From 93a4cbf4c91d61be7334a70ad8fe6e2ff511ed49 Mon Sep 17 00:00:00 2001 From: xuegan Date: Thu, 21 May 2026 14:33:22 +0800 Subject: [PATCH] fix: sort componentsMap and pagesMap keys to ensure stable build output Async file resolution causes non-deterministic insertion order in localPagesMap/localComponentsMap, leading to inconsistent build output between runs. Sort keys before iterating to guarantee stable output. Co-Authored-By: Claude Opus 4.7 --- packages/webpack-plugin/lib/react/script-helper.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/webpack-plugin/lib/react/script-helper.js b/packages/webpack-plugin/lib/react/script-helper.js index a86e3ad72d..8bf617a1d5 100644 --- a/packages/webpack-plugin/lib/react/script-helper.js +++ b/packages/webpack-plugin/lib/react/script-helper.js @@ -51,7 +51,7 @@ function buildPagesMap ({ localPagesMap, loaderContext, jsonConfig, rnConfig }) let firstPage = '' const pagesMap = {} const mpx = loaderContext.getMpx() - Object.keys(localPagesMap).forEach((pagePath) => { + Object.keys(localPagesMap).sort().forEach((pagePath) => { const pageCfg = localPagesMap[pagePath] const pageRequest = stringifyRequest(loaderContext, pageCfg.resource) if (pageCfg.async && rnConfig.supportSubpackage) { @@ -80,7 +80,7 @@ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderC const componentsMap = {} const mpx = loaderContext.getMpx() if (localComponentsMap) { - Object.keys(localComponentsMap).forEach((componentName) => { + Object.keys(localComponentsMap).sort().forEach((componentName) => { const componentCfg = localComponentsMap[componentName] const componentRequest = stringifyRequest(loaderContext, componentCfg.resource) if (componentCfg.async && rnConfig.supportSubpackage) { @@ -114,7 +114,7 @@ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderC }) } if (builtInComponentsMap) { - Object.keys(builtInComponentsMap).forEach((componentName) => { + Object.keys(builtInComponentsMap).sort().forEach((componentName) => { const componentCfg = builtInComponentsMap[componentName] const componentRequest = stringifyRequest(loaderContext, componentCfg.resource) componentsMap[componentName] = getComponentGetter(getBuiltInComponent(componentRequest))