@modern-js/runtime 3.9.2 → 3.10.0

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.
Files changed (39) hide show
  1. package/dist/cjs/cli/ssr/index.js +5 -0
  2. package/dist/cjs/cli/ssr/loadable-bundler-plugin.js +13 -4
  3. package/dist/cjs/core/browser/hydrate.js +2 -0
  4. package/dist/cjs/core/server/requestHandler.js +2 -0
  5. package/dist/cjs/core/server/stream/createReadableStream.js +51 -8
  6. package/dist/cjs/core/server/stream/createReadableStream.worker.js +37 -15
  7. package/dist/cjs/core/server/stream/deferredScript.js +12 -6
  8. package/dist/cjs/core/server/stream/deferredScriptOutputCoordinator.js +370 -0
  9. package/dist/cjs/router/cli/code/templates.js +2 -2
  10. package/dist/cjs/router/runtime/DeferredDataScripts.node.js +3 -1
  11. package/dist/esm/cli/ssr/index.mjs +5 -0
  12. package/dist/esm/cli/ssr/loadable-bundler-plugin.mjs +13 -4
  13. package/dist/esm/core/browser/hydrate.mjs +2 -0
  14. package/dist/esm/core/server/requestHandler.mjs +2 -0
  15. package/dist/esm/core/server/stream/createReadableStream.mjs +51 -8
  16. package/dist/esm/core/server/stream/createReadableStream.worker.mjs +37 -15
  17. package/dist/esm/core/server/stream/deferredScript.mjs +12 -6
  18. package/dist/esm/core/server/stream/deferredScriptOutputCoordinator.mjs +332 -0
  19. package/dist/esm/router/cli/code/templates.mjs +2 -2
  20. package/dist/esm/router/runtime/DeferredDataScripts.node.mjs +3 -1
  21. package/dist/esm-node/cli/ssr/index.mjs +5 -0
  22. package/dist/esm-node/cli/ssr/loadable-bundler-plugin.mjs +13 -4
  23. package/dist/esm-node/core/browser/hydrate.mjs +2 -0
  24. package/dist/esm-node/core/server/requestHandler.mjs +2 -0
  25. package/dist/esm-node/core/server/stream/createReadableStream.mjs +51 -8
  26. package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +37 -15
  27. package/dist/esm-node/core/server/stream/deferredScript.mjs +12 -6
  28. package/dist/esm-node/core/server/stream/deferredScriptOutputCoordinator.mjs +333 -0
  29. package/dist/esm-node/router/cli/code/templates.mjs +2 -2
  30. package/dist/esm-node/router/runtime/DeferredDataScripts.node.mjs +3 -1
  31. package/dist/types/core/context/index.d.ts +1 -1
  32. package/dist/types/core/index.d.ts +1 -1
  33. package/dist/types/core/server/stream/deferredScript.d.ts +1 -1
  34. package/dist/types/core/server/stream/deferredScriptOutputCoordinator.d.ts +72 -0
  35. package/dist/types/index.d.ts +1 -1
  36. package/dist/types/router/runtime/routerHelper.d.ts +5 -0
  37. package/package.json +16 -17
  38. package/{rslib.config.mts → rstack.config.mts} +2 -2
  39. package/rstest.config.mts +4 -1
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Serializes the router's deferred-data resolver scripts with React's Fizz
3
+ * output without rewriting either producer's bytes.
4
+ *
5
+ * Why this exists:
6
+ * - A resolver script settles the client-side Promise created for a
7
+ * `defer()` key. It must be sent when that individual server Promise
8
+ * settles; waiting for the whole React stream would unnecessarily delay
9
+ * hydration and interactivity behind unrelated Suspense boundaries.
10
+ * - React and the resolver callbacks are independent stream producers. A
11
+ * direct `write()` can therefore land in a partial HTML tag, a hidden Fizz
12
+ * segment container, or between that container and its continuation
13
+ * instruction.
14
+ * - React's public streaming callbacks expose shell/all-ready lifecycle
15
+ * events, not a safe byte-level insertion point. React chunk sizes and
16
+ * `progressiveChunkSize` are buffering heuristics, not HTML or Fizz
17
+ * boundaries.
18
+ *
19
+ * The coordinator deliberately recognizes the Fizz continuation containers
20
+ * and instructions used by the supported React stream format. This is a
21
+ * compatibility boundary: when the supported React/Fizz output protocol is
22
+ * changed, update this recognizer and its Node, Edge, HTML, SVG, MathML, and
23
+ * table continuation tests together. It is not intended to be a general HTML
24
+ * rewriter.
25
+ *
26
+ * Shell completion only makes a resolver eligible to send. The resolver is
27
+ * emitted after a root-level HTML boundary and, for a continuation segment,
28
+ * after React's matching continuation instruction.
29
+ */
30
+ export declare class DeferredScriptOutputCoordinator {
31
+ private readonly emit;
32
+ private readonly pendingResolvers;
33
+ private readonly openElements;
34
+ private shellFinished;
35
+ private closed;
36
+ private state;
37
+ private currentTagName;
38
+ private currentAttributes;
39
+ private currentAttributeName;
40
+ private currentAttributeValue;
41
+ private currentAttributeHasValue;
42
+ private declarationPrefix;
43
+ private commentTail;
44
+ private rawTextElement;
45
+ private rawTextSearch;
46
+ private continuationProtocolScript;
47
+ private continuationProtocolTail;
48
+ private hasContinuationProtocolCall;
49
+ private awaitingContinuationProtocol;
50
+ constructor(emit: (chunk: string) => void);
51
+ enqueueResolver(script: string): void;
52
+ /**
53
+ * Keep this separate from the ShellChunkStatus assignment. The caller sets
54
+ * FINISH at the existing marker position, then calls this after the marker
55
+ * chunk's afterMark bytes have been observed.
56
+ */
57
+ markShellFinished(): void;
58
+ writeReact(chunk: string): void;
59
+ finish(): void;
60
+ abort(): void;
61
+ private isSafeBoundary;
62
+ private flushResolvers;
63
+ private consume;
64
+ private startTag;
65
+ private startAttribute;
66
+ private completeAttribute;
67
+ private completeStartTag;
68
+ private completeEndTag;
69
+ private consumeRawText;
70
+ private completeRawTextEndTag;
71
+ private closeOpenElement;
72
+ }
@@ -6,5 +6,5 @@ export type { TRuntimeContext } from './core/context/runtime.js';
6
6
  export { getMonitors } from './core/context/monitors/index.js';
7
7
  export { getRequest } from './core/context/request/index.js';
8
8
  export { setHeaders, setStatus, redirect } from './core/context/response/index.js';
9
- export { RuntimeContext, defineRuntimeConfig, useRuntimeContext, } from './core/index.js';
9
+ export { RuntimeContext, defineRuntimeConfig, useRuntimeContext } from './core/index.js';
10
10
  export type { RouterConfig };
@@ -2,4 +2,9 @@ import type Module from 'module';
2
2
  import type { ShouldRevalidateFunction } from '@modern-js/runtime-utils/router';
3
3
  export declare const createShouldRevalidate: (routeId: string) => ShouldRevalidateFunction;
4
4
  export declare const handleRouteModule: (routeModule: Module, routeId: string) => Module;
5
+ /**
6
+ * @deprecated Generated routes no longer use this. Swallowing the import error
7
+ * here replaced a `ChunkLoadError` with an unrelated `TypeError` by the time it
8
+ * reached the route error boundary. Kept only for code that imports it directly.
9
+ */
5
10
  export declare const handleRouteModuleError: (error: Error) => null;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.9.2",
18
+ "version": "3.10.0",
19
19
  "engines": {
20
20
  "node": ">=20"
21
21
  },
@@ -203,7 +203,7 @@
203
203
  "dependencies": {
204
204
  "@loadable/component": "5.16.7",
205
205
  "@loadable/server": "5.16.7",
206
- "@swc/core": "1.15.41",
206
+ "@swc/core": "1.16.18",
207
207
  "@swc/helpers": "^0.5.17",
208
208
  "@swc/plugin-loadable-components": "^12.0.0",
209
209
  "@types/loadable__component": "^5.13.10",
@@ -215,12 +215,12 @@
215
215
  "isbot": "3.8.0",
216
216
  "react-helmet": "^6.1.0",
217
217
  "react-is": "^18.3.1",
218
- "@modern-js/plugin": "3.9.2",
219
- "@modern-js/plugin-data-loader": "3.9.2",
220
- "@modern-js/render": "3.9.2",
221
- "@modern-js/runtime-utils": "3.9.2",
222
- "@modern-js/utils": "3.9.2",
223
- "@modern-js/types": "3.9.2"
218
+ "@modern-js/plugin": "3.10.0",
219
+ "@modern-js/plugin-data-loader": "3.10.0",
220
+ "@modern-js/render": "3.10.0",
221
+ "@modern-js/runtime-utils": "3.10.0",
222
+ "@modern-js/types": "3.10.0",
223
+ "@modern-js/utils": "3.10.0"
224
224
  },
225
225
  "peerDependencies": {
226
226
  "react": ">=18.3.1",
@@ -228,19 +228,18 @@
228
228
  },
229
229
  "devDependencies": {
230
230
  "@remix-run/web-fetch": "^4.1.3",
231
- "@rsbuild/core": "2.2.7",
232
- "@rslib/core": "1.0.0",
233
- "@testing-library/dom": "^10.4.1",
234
- "@testing-library/react": "^16.3.2",
231
+ "@rsbuild/core": "2.2.13",
232
+ "@testing-library/dom": "^10.4.2",
233
+ "@testing-library/react": "^16.3.3",
235
234
  "@types/cookie": "0.6.0",
236
235
  "@types/invariant": "^2.2.37",
237
236
  "@types/loadable__server": "5.12.11",
238
237
  "@types/node": "^20",
239
- "react": "^19.2.8",
240
- "react-dom": "^19.2.8",
238
+ "react": "^19.3.0",
239
+ "react-dom": "^19.3.0",
241
240
  "ts-node": "^10.9.2",
242
241
  "typescript": "^5",
243
- "@modern-js/app-tools": "3.9.2",
242
+ "@modern-js/app-tools": "3.10.0",
244
243
  "@modern-js/rslib": "2.68.10",
245
244
  "@scripts/rstest-config": "2.66.0"
246
245
  },
@@ -250,8 +249,8 @@
250
249
  "access": "public"
251
250
  },
252
251
  "scripts": {
253
- "dev": "rslib build --watch",
254
- "build": "rslib build && pnpm run gen-static",
252
+ "dev": "rs lib --watch",
253
+ "build": "rs lib && pnpm run gen-static",
255
254
  "gen-static": "ts-node ./scripts/gen-static.ts",
256
255
  "test": "rstest"
257
256
  }
@@ -1,7 +1,7 @@
1
1
  import { rslibConfig } from '@modern-js/rslib';
2
- import { defineConfig } from '@rslib/core';
2
+ import { define } from 'rstack';
3
3
 
4
- export default defineConfig({
4
+ define.lib({
5
5
  ...rslibConfig,
6
6
  source: {
7
7
  define: {
package/rstest.config.mts CHANGED
@@ -57,7 +57,10 @@ export default {
57
57
  ({
58
58
  code,
59
59
  resourcePath,
60
- }: { code: string; resourcePath: string }) => {
60
+ }: {
61
+ code: string;
62
+ resourcePath: string;
63
+ }) => {
61
64
  return code.replace(
62
65
  '__webpack_chunk_load__',
63
66
  '__webpack_chunk_load_test__',