@bleedingdev/modern-js-runtime 3.2.0-ultramodern.24 → 3.2.0-ultramodern.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,12 +50,15 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
50
50
  if (!routeManifest) return template;
51
51
  const { routeAssets } = routeManifest;
52
52
  if (!routeAssets) return template;
53
- const asyncEntry = routeAssets[`async-${entryName}`];
54
- if (asyncEntry) {
55
- const { assets } = asyncEntry;
56
- const jsChunkStr = assets?.filter((asset)=>asset.endsWith('.js'))?.map((asset)=>`<script src=${asset} nonce="${nonce}"></script>`).join(' ');
57
- if (jsChunkStr) return (0, external_utils_js_namespaceObject.safeReplace)(template, '<!--<?- chunksMap.js ?>-->', jsChunkStr);
58
- }
53
+ const matchedRouteIds = (0, lifecycle_js_namespaceObject.getRouterMatchedRouteIds)(runtimeContext) ?? [];
54
+ const assetEntries = [
55
+ ...matchedRouteIds.map((routeId)=>routeAssets[routeId]),
56
+ routeAssets[`async-${entryName}`]
57
+ ].filter(Boolean);
58
+ const jsAssets = Array.from(new Set(assetEntries.flatMap((entry)=>(entry.assets ?? []).filter((asset)=>asset.endsWith('.js')))));
59
+ const nonceAttr = nonce ? ` nonce="${nonce}"` : '';
60
+ const jsChunkStr = jsAssets.filter((asset)=>!template.includes(asset)).map((asset)=>`<script src=${asset}${nonceAttr}></script>`).join(' ');
61
+ if (jsChunkStr) return (0, external_utils_js_namespaceObject.safeReplace)(template, '<!--<?- chunksMap.js ?>-->', jsChunkStr);
59
62
  return template;
60
63
  }
61
64
  return (0, external_shared_js_namespaceObject.buildHtml)(afterAppTemplate, callbacks);
@@ -70,28 +70,27 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
70
70
  const { routeManifest, routerContext, routes } = runtimeContext;
71
71
  if (!routeManifest) return '';
72
72
  const { routeAssets } = routeManifest;
73
- let matchedRouteManifests;
73
+ let matchedRouteManifests = [];
74
74
  const matchedRouteIds = (0, lifecycle_js_namespaceObject.getRouterMatchedRouteIds)(runtimeContext);
75
75
  if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
76
- else {
77
- if (!routerContext || !routes) return '';
76
+ else if (routerContext && routes) {
78
77
  const matches = (0, router_namespaceObject.matchRoutes)(routes, routerContext.location, routerContext.basename);
79
78
  matchedRouteManifests = matches?.map((match, index)=>{
80
79
  if (!index) return;
81
80
  const routeId = match.route.id;
82
81
  if (routeId) return routeAssets[routeId];
83
- }).filter(Boolean);
82
+ }).filter(Boolean) ?? [];
84
83
  }
85
84
  const asyncEntry = routeAssets[`async-${entryName}`];
86
- if (asyncEntry) matchedRouteManifests?.push(asyncEntry);
87
- const cssChunks = matchedRouteManifests ? matchedRouteManifests.reduce((chunks, routeManifest)=>{
85
+ if (asyncEntry) matchedRouteManifests.push(asyncEntry);
86
+ const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
88
87
  const { referenceCssAssets = [] } = routeManifest;
89
88
  const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
90
89
  return [
91
90
  ...chunks,
92
91
  ..._cssChunks
93
92
  ];
94
- }, []) : [];
93
+ }, []);
95
94
  const { inlineStyles } = config;
96
95
  const styles = await Promise.all(cssChunks.map(async (chunk)=>{
97
96
  const link = `<link href="${chunk}" rel="stylesheet" />`;
@@ -64,28 +64,27 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
64
64
  const { routeManifest, routerContext, routes } = runtimeContext;
65
65
  if (!routeManifest) return '';
66
66
  const { routeAssets } = routeManifest;
67
- let matchedRouteManifests;
67
+ let matchedRouteManifests = [];
68
68
  const matchedRouteIds = (0, lifecycle_js_namespaceObject.getRouterMatchedRouteIds)(runtimeContext);
69
69
  if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
70
- else {
71
- if (!routerContext || !routes) return '';
70
+ else if (routerContext && routes) {
72
71
  const matches = (0, router_namespaceObject.matchRoutes)(routes, routerContext.location, routerContext.basename);
73
72
  matchedRouteManifests = matches?.map((match, index)=>{
74
73
  if (!index) return;
75
74
  const routeId = match.route.id;
76
75
  if (routeId) return routeAssets[routeId];
77
- }).filter(Boolean);
76
+ }).filter(Boolean) ?? [];
78
77
  }
79
78
  const asyncEntry = routeAssets[`async-${entryName}`];
80
- if (asyncEntry) matchedRouteManifests?.push(asyncEntry);
81
- const cssChunks = matchedRouteManifests ? matchedRouteManifests.reduce((chunks, routeManifest)=>{
79
+ if (asyncEntry) matchedRouteManifests.push(asyncEntry);
80
+ const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
82
81
  const { referenceCssAssets = [] } = routeManifest;
83
82
  const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
84
83
  return [
85
84
  ...chunks,
86
85
  ..._cssChunks
87
86
  ];
88
- }, []) : [];
87
+ }, []);
89
88
  const { inlineStyles } = config;
90
89
  const styles = cssChunks.map((chunk)=>{
91
90
  const link = `<link href="${chunk}" rel="stylesheet" />`;
@@ -71,6 +71,7 @@ const renderString = async (request, serverRoot, options)=>{
71
71
  stats: loadableStats,
72
72
  nonce: config.nonce,
73
73
  routeManifest,
74
+ runtimeContext,
74
75
  template: htmlTemplate,
75
76
  entryName,
76
77
  chunkSet,
@@ -27,6 +27,7 @@ __webpack_require__.d(__webpack_exports__, {
27
27
  LoadableCollector: ()=>LoadableCollector
28
28
  });
29
29
  const server_namespaceObject = require("@loadable/server");
30
+ const lifecycle_js_namespaceObject = require("../../../router/runtime/lifecycle.js");
30
31
  const external_utils_js_namespaceObject = require("../utils.js");
31
32
  const extname = (uri)=>{
32
33
  if ('string' != typeof uri || !uri.includes('.')) return '';
@@ -49,6 +50,20 @@ class LoadableCollector {
49
50
  const { routeManifest, entryName } = this.options;
50
51
  return routeManifest?.routeAssets?.[entryName]?.assets;
51
52
  }
53
+ getMatchedRouteChunks() {
54
+ const { routeManifest, runtimeContext } = this.options;
55
+ const routeAssets = routeManifest?.routeAssets;
56
+ if (!routeAssets) return [];
57
+ const matchedRouteIds = (0, lifecycle_js_namespaceObject.getRouterMatchedRouteIds)(runtimeContext) ?? [];
58
+ return matchedRouteIds.flatMap((routeId)=>{
59
+ const routeAsset = routeAssets[routeId];
60
+ return (routeAsset?.assets ?? []).map((asset)=>({
61
+ filename: asset.replace(/^\//, ''),
62
+ path: asset,
63
+ url: asset
64
+ }));
65
+ });
66
+ }
52
67
  collect(comopnent) {
53
68
  const { stats, entryName } = this.options;
54
69
  if (!stats) return comopnent;
@@ -70,7 +85,7 @@ class LoadableCollector {
70
85
  `async-${entryName}`
71
86
  ]));
72
87
  } catch (e) {}
73
- const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks));
88
+ const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks)).concat(this.getMatchedRouteChunks());
74
89
  const scriptChunks = generateChunks(chunks, 'js');
75
90
  const styleChunks = generateChunks(chunks, 'css');
76
91
  this.emitLoadableScripts(extractor);
@@ -1,5 +1,5 @@
1
1
  import { serializeJson } from "@modern-js/runtime-utils/node";
2
- import { getRouterHydrationScripts } from "../../../router/runtime/lifecycle.mjs";
2
+ import { getRouterHydrationScripts, getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
3
3
  import { SSR_DATA_JSON_ID } from "../../constants.mjs";
4
4
  import { SSR_DATA_PLACEHOLDER } from "../constants.mjs";
5
5
  import { buildHtml } from "../shared.mjs";
@@ -22,12 +22,15 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
22
22
  if (!routeManifest) return template;
23
23
  const { routeAssets } = routeManifest;
24
24
  if (!routeAssets) return template;
25
- const asyncEntry = routeAssets[`async-${entryName}`];
26
- if (asyncEntry) {
27
- const { assets } = asyncEntry;
28
- const jsChunkStr = assets?.filter((asset)=>asset.endsWith('.js'))?.map((asset)=>`<script src=${asset} nonce="${nonce}"></script>`).join(' ');
29
- if (jsChunkStr) return safeReplace(template, '<!--<?- chunksMap.js ?>-->', jsChunkStr);
30
- }
25
+ const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
26
+ const assetEntries = [
27
+ ...matchedRouteIds.map((routeId)=>routeAssets[routeId]),
28
+ routeAssets[`async-${entryName}`]
29
+ ].filter(Boolean);
30
+ const jsAssets = Array.from(new Set(assetEntries.flatMap((entry)=>(entry.assets ?? []).filter((asset)=>asset.endsWith('.js')))));
31
+ const nonceAttr = nonce ? ` nonce="${nonce}"` : '';
32
+ const jsChunkStr = jsAssets.filter((asset)=>!template.includes(asset)).map((asset)=>`<script src=${asset}${nonceAttr}></script>`).join(' ');
33
+ if (jsChunkStr) return safeReplace(template, '<!--<?- chunksMap.js ?>-->', jsChunkStr);
31
34
  return template;
32
35
  }
33
36
  return buildHtml(afterAppTemplate, callbacks);
@@ -32,28 +32,27 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
32
32
  const { routeManifest, routerContext, routes } = runtimeContext;
33
33
  if (!routeManifest) return '';
34
34
  const { routeAssets } = routeManifest;
35
- let matchedRouteManifests;
35
+ let matchedRouteManifests = [];
36
36
  const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
37
37
  if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
38
- else {
39
- if (!routerContext || !routes) return '';
38
+ else if (routerContext && routes) {
40
39
  const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
41
40
  matchedRouteManifests = matches?.map((match, index)=>{
42
41
  if (!index) return;
43
42
  const routeId = match.route.id;
44
43
  if (routeId) return routeAssets[routeId];
45
- }).filter(Boolean);
44
+ }).filter(Boolean) ?? [];
46
45
  }
47
46
  const asyncEntry = routeAssets[`async-${entryName}`];
48
- if (asyncEntry) matchedRouteManifests?.push(asyncEntry);
49
- const cssChunks = matchedRouteManifests ? matchedRouteManifests.reduce((chunks, routeManifest)=>{
47
+ if (asyncEntry) matchedRouteManifests.push(asyncEntry);
48
+ const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
50
49
  const { referenceCssAssets = [] } = routeManifest;
51
50
  const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
52
51
  return [
53
52
  ...chunks,
54
53
  ..._cssChunks
55
54
  ];
56
- }, []) : [];
55
+ }, []);
57
56
  const { inlineStyles } = config;
58
57
  const styles = await Promise.all(cssChunks.map(async (chunk)=>{
59
58
  const link = `<link href="${chunk}" rel="stylesheet" />`;
@@ -26,28 +26,27 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
26
26
  const { routeManifest, routerContext, routes } = runtimeContext;
27
27
  if (!routeManifest) return '';
28
28
  const { routeAssets } = routeManifest;
29
- let matchedRouteManifests;
29
+ let matchedRouteManifests = [];
30
30
  const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
31
31
  if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
32
- else {
33
- if (!routerContext || !routes) return '';
32
+ else if (routerContext && routes) {
34
33
  const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
35
34
  matchedRouteManifests = matches?.map((match, index)=>{
36
35
  if (!index) return;
37
36
  const routeId = match.route.id;
38
37
  if (routeId) return routeAssets[routeId];
39
- }).filter(Boolean);
38
+ }).filter(Boolean) ?? [];
40
39
  }
41
40
  const asyncEntry = routeAssets[`async-${entryName}`];
42
- if (asyncEntry) matchedRouteManifests?.push(asyncEntry);
43
- const cssChunks = matchedRouteManifests ? matchedRouteManifests.reduce((chunks, routeManifest)=>{
41
+ if (asyncEntry) matchedRouteManifests.push(asyncEntry);
42
+ const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
44
43
  const { referenceCssAssets = [] } = routeManifest;
45
44
  const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
46
45
  return [
47
46
  ...chunks,
48
47
  ..._cssChunks
49
48
  ];
50
- }, []) : [];
49
+ }, []);
51
50
  const { inlineStyles } = config;
52
51
  const styles = cssChunks.map((chunk)=>{
53
52
  const link = `<link href="${chunk}" rel="stylesheet" />`;
@@ -32,6 +32,7 @@ const renderString = async (request, serverRoot, options)=>{
32
32
  stats: loadableStats,
33
33
  nonce: config.nonce,
34
34
  routeManifest,
35
+ runtimeContext,
35
36
  template: htmlTemplate,
36
37
  entryName,
37
38
  chunkSet,
@@ -1,4 +1,5 @@
1
1
  import { ChunkExtractor } from "@loadable/server";
2
+ import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
2
3
  import { attributesToString, checkIsNode } from "../utils.mjs";
3
4
  const extname = (uri)=>{
4
5
  if ('string' != typeof uri || !uri.includes('.')) return '';
@@ -21,6 +22,20 @@ class LoadableCollector {
21
22
  const { routeManifest, entryName } = this.options;
22
23
  return routeManifest?.routeAssets?.[entryName]?.assets;
23
24
  }
25
+ getMatchedRouteChunks() {
26
+ const { routeManifest, runtimeContext } = this.options;
27
+ const routeAssets = routeManifest?.routeAssets;
28
+ if (!routeAssets) return [];
29
+ const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
30
+ return matchedRouteIds.flatMap((routeId)=>{
31
+ const routeAsset = routeAssets[routeId];
32
+ return (routeAsset?.assets ?? []).map((asset)=>({
33
+ filename: asset.replace(/^\//, ''),
34
+ path: asset,
35
+ url: asset
36
+ }));
37
+ });
38
+ }
24
39
  collect(comopnent) {
25
40
  const { stats, entryName } = this.options;
26
41
  if (!stats) return comopnent;
@@ -42,7 +57,7 @@ class LoadableCollector {
42
57
  `async-${entryName}`
43
58
  ]));
44
59
  } catch (e) {}
45
- const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks));
60
+ const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks)).concat(this.getMatchedRouteChunks());
46
61
  const scriptChunks = generateChunks(chunks, 'js');
47
62
  const styleChunks = generateChunks(chunks, 'css');
48
63
  this.emitLoadableScripts(extractor);
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
2
  import { serializeJson } from "@modern-js/runtime-utils/node";
3
- import { getRouterHydrationScripts } from "../../../router/runtime/lifecycle.mjs";
3
+ import { getRouterHydrationScripts, getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
4
4
  import { SSR_DATA_JSON_ID } from "../../constants.mjs";
5
5
  import { SSR_DATA_PLACEHOLDER } from "../constants.mjs";
6
6
  import { buildHtml } from "../shared.mjs";
@@ -23,12 +23,15 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
23
23
  if (!routeManifest) return template;
24
24
  const { routeAssets } = routeManifest;
25
25
  if (!routeAssets) return template;
26
- const asyncEntry = routeAssets[`async-${entryName}`];
27
- if (asyncEntry) {
28
- const { assets } = asyncEntry;
29
- const jsChunkStr = assets?.filter((asset)=>asset.endsWith('.js'))?.map((asset)=>`<script src=${asset} nonce="${nonce}"></script>`).join(' ');
30
- if (jsChunkStr) return safeReplace(template, '<!--<?- chunksMap.js ?>-->', jsChunkStr);
31
- }
26
+ const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
27
+ const assetEntries = [
28
+ ...matchedRouteIds.map((routeId)=>routeAssets[routeId]),
29
+ routeAssets[`async-${entryName}`]
30
+ ].filter(Boolean);
31
+ const jsAssets = Array.from(new Set(assetEntries.flatMap((entry)=>(entry.assets ?? []).filter((asset)=>asset.endsWith('.js')))));
32
+ const nonceAttr = nonce ? ` nonce="${nonce}"` : '';
33
+ const jsChunkStr = jsAssets.filter((asset)=>!template.includes(asset)).map((asset)=>`<script src=${asset}${nonceAttr}></script>`).join(' ');
34
+ if (jsChunkStr) return safeReplace(template, '<!--<?- chunksMap.js ?>-->', jsChunkStr);
32
35
  return template;
33
36
  }
34
37
  return buildHtml(afterAppTemplate, callbacks);
@@ -36,28 +36,27 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
36
36
  const { routeManifest, routerContext, routes } = runtimeContext;
37
37
  if (!routeManifest) return '';
38
38
  const { routeAssets } = routeManifest;
39
- let matchedRouteManifests;
39
+ let matchedRouteManifests = [];
40
40
  const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
41
41
  if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
42
- else {
43
- if (!routerContext || !routes) return '';
42
+ else if (routerContext && routes) {
44
43
  const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
45
44
  matchedRouteManifests = matches?.map((match, index)=>{
46
45
  if (!index) return;
47
46
  const routeId = match.route.id;
48
47
  if (routeId) return routeAssets[routeId];
49
- }).filter(Boolean);
48
+ }).filter(Boolean) ?? [];
50
49
  }
51
50
  const asyncEntry = routeAssets[`async-${entryName}`];
52
- if (asyncEntry) matchedRouteManifests?.push(asyncEntry);
53
- const cssChunks = matchedRouteManifests ? matchedRouteManifests.reduce((chunks, routeManifest)=>{
51
+ if (asyncEntry) matchedRouteManifests.push(asyncEntry);
52
+ const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
54
53
  const { referenceCssAssets = [] } = routeManifest;
55
54
  const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
56
55
  return [
57
56
  ...chunks,
58
57
  ..._cssChunks
59
58
  ];
60
- }, []) : [];
59
+ }, []);
61
60
  const { inlineStyles } = config;
62
61
  const styles = await Promise.all(cssChunks.map(async (chunk)=>{
63
62
  const link = `<link href="${chunk}" rel="stylesheet" />`;
@@ -27,28 +27,27 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
27
27
  const { routeManifest, routerContext, routes } = runtimeContext;
28
28
  if (!routeManifest) return '';
29
29
  const { routeAssets } = routeManifest;
30
- let matchedRouteManifests;
30
+ let matchedRouteManifests = [];
31
31
  const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
32
32
  if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
33
- else {
34
- if (!routerContext || !routes) return '';
33
+ else if (routerContext && routes) {
35
34
  const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
36
35
  matchedRouteManifests = matches?.map((match, index)=>{
37
36
  if (!index) return;
38
37
  const routeId = match.route.id;
39
38
  if (routeId) return routeAssets[routeId];
40
- }).filter(Boolean);
39
+ }).filter(Boolean) ?? [];
41
40
  }
42
41
  const asyncEntry = routeAssets[`async-${entryName}`];
43
- if (asyncEntry) matchedRouteManifests?.push(asyncEntry);
44
- const cssChunks = matchedRouteManifests ? matchedRouteManifests.reduce((chunks, routeManifest)=>{
42
+ if (asyncEntry) matchedRouteManifests.push(asyncEntry);
43
+ const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
45
44
  const { referenceCssAssets = [] } = routeManifest;
46
45
  const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
47
46
  return [
48
47
  ...chunks,
49
48
  ..._cssChunks
50
49
  ];
51
- }, []) : [];
50
+ }, []);
52
51
  const { inlineStyles } = config;
53
52
  const styles = cssChunks.map((chunk)=>{
54
53
  const link = `<link href="${chunk}" rel="stylesheet" />`;
@@ -33,6 +33,7 @@ const renderString = async (request, serverRoot, options)=>{
33
33
  stats: loadableStats,
34
34
  nonce: config.nonce,
35
35
  routeManifest,
36
+ runtimeContext,
36
37
  template: htmlTemplate,
37
38
  entryName,
38
39
  chunkSet,
@@ -1,5 +1,6 @@
1
1
  import "node:module";
2
2
  import { ChunkExtractor } from "@loadable/server";
3
+ import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
3
4
  import { attributesToString, checkIsNode } from "../utils.mjs";
4
5
  import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
5
6
  import { dirname as __rspack_dirname } from "node:path";
@@ -25,6 +26,20 @@ class LoadableCollector {
25
26
  const { routeManifest, entryName } = this.options;
26
27
  return routeManifest?.routeAssets?.[entryName]?.assets;
27
28
  }
29
+ getMatchedRouteChunks() {
30
+ const { routeManifest, runtimeContext } = this.options;
31
+ const routeAssets = routeManifest?.routeAssets;
32
+ if (!routeAssets) return [];
33
+ const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
34
+ return matchedRouteIds.flatMap((routeId)=>{
35
+ const routeAsset = routeAssets[routeId];
36
+ return (routeAsset?.assets ?? []).map((asset)=>({
37
+ filename: asset.replace(/^\//, ''),
38
+ path: asset,
39
+ url: asset
40
+ }));
41
+ });
42
+ }
28
43
  collect(comopnent) {
29
44
  const { stats, entryName } = this.options;
30
45
  if (!stats) return comopnent;
@@ -46,7 +61,7 @@ class LoadableCollector {
46
61
  `async-${entryName}`
47
62
  ]));
48
63
  } catch (e) {}
49
- const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks));
64
+ const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks)).concat(this.getMatchedRouteChunks());
50
65
  const scriptChunks = generateChunks(chunks, 'js');
51
66
  const styleChunks = generateChunks(chunks, 'css');
52
67
  this.emitLoadableScripts(extractor);
@@ -1,4 +1,5 @@
1
1
  import type { ReactElement } from 'react';
2
+ import type { TInternalRuntimeContext } from '../../context';
2
3
  import type { ChunkSet, Collector } from './types';
3
4
  declare module '@loadable/server' {
4
5
  interface ChunkExtractor {
@@ -10,6 +11,7 @@ export interface LoadableCollectorOptions {
10
11
  nonce?: string;
11
12
  stats?: Record<string, any>;
12
13
  routeManifest?: Record<string, any>;
14
+ runtimeContext: TInternalRuntimeContext;
13
15
  template: string;
14
16
  entryName: string;
15
17
  chunkSet: ChunkSet;
@@ -27,6 +29,7 @@ export declare class LoadableCollector implements Collector {
27
29
  private extractor?;
28
30
  constructor(options: LoadableCollectorOptions);
29
31
  private get existsAssets();
32
+ private getMatchedRouteChunks;
30
33
  collect(comopnent: ReactElement): ReactElement;
31
34
  effect(): Promise<void>;
32
35
  private emitLoadableScripts;
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.2.0-ultramodern.24",
20
+ "version": "3.2.0-ultramodern.25",
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
@@ -227,12 +227,12 @@
227
227
  "isbot": "5.1.40",
228
228
  "react-helmet": "^6.1.0",
229
229
  "react-is": "^19.2.6",
230
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.24",
231
- "@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.2.0-ultramodern.24",
232
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.24",
233
- "@modern-js/render": "npm:@bleedingdev/modern-js-render@3.2.0-ultramodern.24",
234
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.24",
235
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.24"
230
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.25",
231
+ "@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.2.0-ultramodern.25",
232
+ "@modern-js/render": "npm:@bleedingdev/modern-js-render@3.2.0-ultramodern.25",
233
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.25",
234
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.25",
235
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.25"
236
236
  },
237
237
  "peerDependencies": {
238
238
  "react": "^19.2.6",
@@ -251,7 +251,7 @@
251
251
  "@typescript/native-preview": "7.0.0-dev.20260526.1",
252
252
  "react": "^19.2.6",
253
253
  "react-dom": "^19.2.6",
254
- "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.24",
254
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.25",
255
255
  "@scripts/rstest-config": "2.66.0"
256
256
  },
257
257
  "sideEffects": false,