@ecopages/react 0.2.0-alpha.2 → 0.2.0-alpha.20

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 (66) hide show
  1. package/CHANGELOG.md +19 -39
  2. package/README.md +160 -18
  3. package/package.json +6 -6
  4. package/src/react-hmr-strategy.d.ts +26 -21
  5. package/src/react-hmr-strategy.js +91 -110
  6. package/src/react-renderer.d.ts +165 -41
  7. package/src/react-renderer.js +451 -158
  8. package/src/react.constants.d.ts +1 -0
  9. package/src/react.constants.js +4 -0
  10. package/src/react.plugin.d.ts +37 -108
  11. package/src/react.plugin.js +125 -54
  12. package/src/react.types.d.ts +88 -0
  13. package/src/react.types.js +0 -0
  14. package/src/router-adapter.d.ts +2 -2
  15. package/src/services/react-bundle.service.d.ts +4 -25
  16. package/src/services/react-bundle.service.js +39 -91
  17. package/src/services/react-hmr-page-metadata-cache.d.ts +9 -0
  18. package/src/services/react-hmr-page-metadata-cache.js +18 -2
  19. package/src/services/react-hydration-asset.service.d.ts +7 -6
  20. package/src/services/react-hydration-asset.service.js +29 -17
  21. package/src/services/react-mdx-config-dependency.service.d.ts +36 -0
  22. package/src/services/react-mdx-config-dependency.service.js +122 -0
  23. package/src/services/react-page-module.service.d.ts +8 -2
  24. package/src/services/react-page-module.service.js +44 -37
  25. package/src/services/react-page-payload.service.d.ts +46 -0
  26. package/src/services/react-page-payload.service.js +67 -0
  27. package/src/services/react-runtime-bundle.service.d.ts +14 -12
  28. package/src/services/react-runtime-bundle.service.js +103 -180
  29. package/src/utils/client-graph-boundary-plugin.js +149 -11
  30. package/src/utils/component-config-traversal.d.ts +36 -0
  31. package/src/utils/component-config-traversal.js +54 -0
  32. package/src/utils/declared-modules.d.ts +1 -1
  33. package/src/utils/declared-modules.js +7 -16
  34. package/src/utils/dynamic.test.browser.d.ts +1 -0
  35. package/src/utils/dynamic.test.browser.js +33 -0
  36. package/src/utils/hydration-scripts.d.ts +19 -4
  37. package/src/utils/hydration-scripts.js +102 -39
  38. package/src/utils/hydration-scripts.test.browser.d.ts +1 -0
  39. package/src/utils/hydration-scripts.test.browser.js +126 -0
  40. package/src/utils/reachability-analyzer.d.ts +12 -1
  41. package/src/utils/reachability-analyzer.js +101 -5
  42. package/src/utils/react-dom-runtime-interop-plugin.d.ts +5 -0
  43. package/src/utils/react-dom-runtime-interop-plugin.js +29 -0
  44. package/src/utils/react-mdx-loader-plugin.js +13 -5
  45. package/src/utils/react-runtime-specifier-map.d.ts +6 -0
  46. package/src/utils/react-runtime-specifier-map.js +37 -0
  47. package/src/utils/use-sync-external-store-shim-plugin.d.ts +5 -0
  48. package/src/utils/use-sync-external-store-shim-plugin.js +41 -0
  49. package/src/react-hmr-strategy.ts +0 -444
  50. package/src/react-renderer.ts +0 -403
  51. package/src/react.plugin.ts +0 -241
  52. package/src/router-adapter.ts +0 -95
  53. package/src/services/react-bundle.service.ts +0 -212
  54. package/src/services/react-hmr-page-metadata-cache.ts +0 -24
  55. package/src/services/react-hydration-asset.service.ts +0 -260
  56. package/src/services/react-page-module.service.ts +0 -214
  57. package/src/services/react-runtime-bundle.service.ts +0 -271
  58. package/src/utils/client-graph-boundary-plugin.ts +0 -590
  59. package/src/utils/client-only.ts +0 -27
  60. package/src/utils/declared-modules.ts +0 -99
  61. package/src/utils/dynamic.ts +0 -27
  62. package/src/utils/hmr-scripts.ts +0 -47
  63. package/src/utils/html-boundary.ts +0 -66
  64. package/src/utils/hydration-scripts.ts +0 -338
  65. package/src/utils/reachability-analyzer.ts +0 -440
  66. package/src/utils/react-mdx-loader-plugin.ts +0 -40
@@ -1,8 +1,16 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { dirname, extname, resolve } from "node:path";
3
3
  import { parseSync } from "oxc-parser";
4
- import { analyzeReachability } from "./reachability-analyzer";
4
+ import { analyzeReachability } from "./reachability-analyzer.js";
5
5
  const SOURCE_FILE_FILTER = /\.(tsx?|jsx?)$/;
6
+ const SERVER_ONLY_ECO_PAGE_OPTION_KEYS = /* @__PURE__ */ new Set([
7
+ "cache",
8
+ "middleware",
9
+ "requires",
10
+ "metadata",
11
+ "staticProps",
12
+ "staticPaths"
13
+ ]);
6
14
  function isBareSpecifier(specifier) {
7
15
  if (specifier.startsWith(".")) return false;
8
16
  if (specifier.startsWith("/")) return false;
@@ -12,6 +20,10 @@ function isBareSpecifier(specifier) {
12
20
  function isProjectAliasSpecifier(specifier) {
13
21
  return specifier.startsWith("@/") || specifier.startsWith("~/") || specifier.startsWith("ecopages:");
14
22
  }
23
+ function isServerOnlySpecifier(specifier) {
24
+ if (specifier.startsWith("node:")) return true;
25
+ return /(?:^|[/])[^/]+\.server(?:$|\.)/.test(specifier);
26
+ }
15
27
  function toModuleBaseSpecifier(specifier) {
16
28
  if (!isBareSpecifier(specifier) || specifier.startsWith("node:")) {
17
29
  return specifier;
@@ -82,7 +94,93 @@ function parserLanguageForFile(filename) {
82
94
  if (extension === ".jsx") return "jsx";
83
95
  return "js";
84
96
  }
85
- function transformModuleImports(source, filename, globallyAllowed) {
97
+ function getObjectPropertyKeyName(node) {
98
+ if (!node) return void 0;
99
+ if (node.type === "Identifier") return node.name;
100
+ if (node.type === "StringLiteral" || node.type === "Literal") {
101
+ return typeof node.value === "string" ? node.value : void 0;
102
+ }
103
+ return void 0;
104
+ }
105
+ function stripServerOnlyEcoPageOptions(source, program) {
106
+ const edits = [];
107
+ function walk(node) {
108
+ if (!node || typeof node !== "object") return;
109
+ if (Array.isArray(node)) {
110
+ for (const child of node) walk(child);
111
+ return;
112
+ }
113
+ if (node.type === "CallExpression" && node.callee?.type === "MemberExpression" && node.callee.object?.type === "Identifier" && node.callee.object.name === "eco" && node.callee.property?.type === "Identifier" && node.callee.property.name === "page" && node.arguments?.[0]?.type === "ObjectExpression") {
114
+ const objectExpression = node.arguments[0];
115
+ const keptProperties = [];
116
+ let removedProperty = false;
117
+ for (const property of objectExpression.properties ?? []) {
118
+ if (property?.type === "Property") {
119
+ const keyName = getObjectPropertyKeyName(property.key);
120
+ if (keyName && SERVER_ONLY_ECO_PAGE_OPTION_KEYS.has(keyName)) {
121
+ removedProperty = true;
122
+ continue;
123
+ }
124
+ }
125
+ keptProperties.push(source.slice(property.start, property.end));
126
+ }
127
+ if (removedProperty) {
128
+ const replacement = keptProperties.length > 0 ? `{ ${keptProperties.join(", ")} }` : "{}";
129
+ edits.push({
130
+ start: objectExpression.start,
131
+ end: objectExpression.end,
132
+ replacement
133
+ });
134
+ }
135
+ }
136
+ for (const key in node) {
137
+ if (key !== "type" && key !== "start" && key !== "end") {
138
+ walk(node[key]);
139
+ }
140
+ }
141
+ }
142
+ walk(program);
143
+ if (edits.length === 0) {
144
+ return { transformed: source, modified: false };
145
+ }
146
+ edits.sort((a, b) => b.start - a.start);
147
+ let transformed = source;
148
+ for (const edit of edits) {
149
+ transformed = transformed.slice(0, edit.start) + edit.replacement + transformed.slice(edit.end);
150
+ }
151
+ return { transformed, modified: true };
152
+ }
153
+ function normalizeRequestedExportsKey(pathname) {
154
+ let normalized = pathname.replace(/\\/g, "/");
155
+ normalized = normalized.replace(/\.(tsx?|jsx?)$/i, "");
156
+ if (normalized.endsWith("/index")) {
157
+ normalized = normalized.slice(0, -"/index".length);
158
+ }
159
+ return normalized;
160
+ }
161
+ function resolveRequestedExportsKey(importer, specifier) {
162
+ if (isBareSpecifier(specifier) || isProjectAliasSpecifier(specifier)) {
163
+ return void 0;
164
+ }
165
+ const resolved = specifier.startsWith("/") ? specifier : resolve(dirname(importer), specifier);
166
+ return normalizeRequestedExportsKey(resolved);
167
+ }
168
+ function mergeRequestedExportRules(registry, moduleKey, rules) {
169
+ const existing = registry.get(moduleKey);
170
+ if (existing === "*") return;
171
+ if (rules === "*") {
172
+ registry.set(moduleKey, "*");
173
+ return;
174
+ }
175
+ if (!existing) {
176
+ registry.set(moduleKey, new Set(rules));
177
+ return;
178
+ }
179
+ for (const rule of rules) {
180
+ existing.add(rule);
181
+ }
182
+ }
183
+ function transformModuleImports(source, filename, globallyAllowed, requestedExports) {
86
184
  let result;
87
185
  try {
88
186
  result = parseSync(filename, source, {
@@ -116,12 +214,35 @@ function transformModuleImports(source, filename, globallyAllowed) {
116
214
  walk(program);
117
215
  const locallyAllowed = parseDeclaredModules(localDeclared);
118
216
  const allowedMap = mergeDeclaredModulesMap(globallyAllowed, locallyAllowed);
119
- const reachability = analyzeReachability(source, filename, program);
217
+ const explicitRequestedExports = requestedExports.get(normalizeRequestedExportsKey(filename));
218
+ const reachability = analyzeReachability(source, filename, program, explicitRequestedExports);
219
+ for (const statement of program.body) {
220
+ if (statement.type === "ImportDeclaration") {
221
+ const reachableRules = reachability.reachableImports.get(statement.source.value);
222
+ const requestedModuleKey = resolveRequestedExportsKey(filename, statement.source.value);
223
+ if (!requestedModuleKey || !reachableRules) continue;
224
+ mergeRequestedExportRules(requestedExports, requestedModuleKey, reachableRules);
225
+ continue;
226
+ }
227
+ if (statement.type === "ExportNamedDeclaration" && statement.source) {
228
+ const reachableRules = reachability.reachableImports.get(statement.source.value);
229
+ const requestedModuleKey = resolveRequestedExportsKey(filename, statement.source.value);
230
+ if (!requestedModuleKey || !reachableRules) continue;
231
+ mergeRequestedExportRules(requestedExports, requestedModuleKey, reachableRules);
232
+ continue;
233
+ }
234
+ if (statement.type === "ExportAllDeclaration" && statement.source) {
235
+ const reachableRules = reachability.reachableImports.get(statement.source.value);
236
+ const requestedModuleKey = resolveRequestedExportsKey(filename, statement.source.value);
237
+ if (!requestedModuleKey || !reachableRules) continue;
238
+ mergeRequestedExportRules(requestedExports, requestedModuleKey, reachableRules);
239
+ }
240
+ }
120
241
  const edits = [];
121
242
  function processSpecifier(specifier) {
122
243
  const moduleBase = toModuleBaseSpecifier(specifier);
123
244
  const explicitRules = allowedMap.get(moduleBase);
124
- if (specifier.startsWith("node:") || specifier.includes(".server.")) {
245
+ if (isServerOnlySpecifier(specifier)) {
125
246
  if (explicitRules) {
126
247
  return { allowed: true, rules: explicitRules };
127
248
  }
@@ -208,9 +329,10 @@ function transformModuleImports(source, filename, globallyAllowed) {
208
329
  const specifier = node.source.value;
209
330
  const { allowed } = processSpecifier(specifier);
210
331
  if (!allowed) {
211
- if (!reachability.isFallbackRoots) {
332
+ const reachableRules = reachability.reachableImports.get(specifier);
333
+ if (reachableRules && !reachability.isFallbackRoots) {
212
334
  throw new Error(
213
- `[Ecopages Client Reachability] Forbidden client export from '${specifier}' at ${filename}:${node.start}.`
335
+ `[Ecopages Client Reachability] Forbidden client export from '${specifier}' at ${filename}:${node.start}. This export is explicitly reachable from the React render function.`
214
336
  );
215
337
  } else {
216
338
  edits.push({ start: node.start, end: node.end, replacement: "" });
@@ -222,9 +344,10 @@ function transformModuleImports(source, filename, globallyAllowed) {
222
344
  const specifier = node.source.value;
223
345
  const { allowed } = processSpecifier(specifier);
224
346
  if (!allowed) {
225
- if (!reachability.isFallbackRoots) {
347
+ const reachableRules = reachability.reachableImports.get(specifier);
348
+ if (reachableRules && !reachability.isFallbackRoots) {
226
349
  throw new Error(
227
- `[Ecopages Client Reachability] Forbidden client export * from '${specifier}' at ${filename}:${node.start}.`
350
+ `[Ecopages Client Reachability] Forbidden client export * from '${specifier}' at ${filename}:${node.start}. This export is explicitly reachable from the React render function.`
228
351
  );
229
352
  } else {
230
353
  edits.push({ start: node.start, end: node.end, replacement: "" });
@@ -282,13 +405,26 @@ function transformModuleImports(source, filename, globallyAllowed) {
282
405
  }
283
406
  walkImports(program);
284
407
  if (edits.length === 0) {
285
- return { transformed: source, modified: false };
408
+ return stripServerOnlyEcoPageOptions(source, program);
286
409
  }
287
410
  edits.sort((a, b) => b.start - a.start);
288
411
  let transformed = source;
289
412
  for (const edit of edits) {
290
413
  transformed = transformed.slice(0, edit.start) + edit.replacement + transformed.slice(edit.end);
291
414
  }
415
+ let reparsedResult;
416
+ try {
417
+ reparsedResult = parseSync(filename, transformed, {
418
+ sourceType: "module",
419
+ lang: parserLanguageForFile(filename)
420
+ });
421
+ } catch {
422
+ return { transformed, modified: true };
423
+ }
424
+ const strippedPageOptions = stripServerOnlyEcoPageOptions(transformed, reparsedResult.program);
425
+ if (strippedPageOptions.modified) {
426
+ return strippedPageOptions;
427
+ }
292
428
  return { transformed, modified: true };
293
429
  }
294
430
  function createClientGraphBoundaryPlugin(options) {
@@ -297,6 +433,7 @@ function createClientGraphBoundaryPlugin(options) {
297
433
  setup(build) {
298
434
  const absWorkingDir = options?.absWorkingDir ?? process.cwd();
299
435
  const globallyDeclaredSources = parseDeclaredModules(options?.declaredModules);
436
+ const requestedExports = /* @__PURE__ */ new Map();
300
437
  for (const alwaysAllow of options?.alwaysAllowSpecifiers ?? []) {
301
438
  globallyDeclaredSources.set(toModuleBaseSpecifier(alwaysAllow), "*");
302
439
  }
@@ -338,7 +475,8 @@ function createClientGraphBoundaryPlugin(options) {
338
475
  const { transformed: oxcTransformed, modified: importsModified } = transformModuleImports(
339
476
  transformed,
340
477
  args.path,
341
- globallyDeclaredSources
478
+ globallyDeclaredSources,
479
+ requestedExports
342
480
  );
343
481
  if (importsModified) {
344
482
  modified = true;
@@ -346,7 +484,7 @@ function createClientGraphBoundaryPlugin(options) {
346
484
  }
347
485
  if (!modified) return void 0;
348
486
  const ext = extname(args.path).slice(1);
349
- return { contents: transformed, loader: ext };
487
+ return { contents: transformed, loader: ext, resolveDir: dirname(args.path) };
350
488
  });
351
489
  }
352
490
  };
@@ -0,0 +1,36 @@
1
+ import type { EcoComponent, EcoComponentConfig } from '@ecopages/core';
2
+ /**
3
+ * Walks a component config tree once, including nested layout configs and
4
+ * dependency component configs.
5
+ *
6
+ * The shared React integration code performs several different analyses over the
7
+ * same config graph. Centralizing the traversal keeps cycle handling and graph
8
+ * shape assumptions in one place instead of repeating them in the renderer and
9
+ * services.
10
+ */
11
+ export declare function walkConfigTree(config: EcoComponentConfig | undefined, visitor: (config: EcoComponentConfig) => void, visited?: Set<EcoComponentConfig>): void;
12
+ /**
13
+ * Walks a forest of root component configs using one shared visited set.
14
+ *
15
+ * This is useful when a page contributes multiple config roots, such as a page
16
+ * config plus a resolved layout config, and duplicate nested nodes should still
17
+ * be processed only once.
18
+ */
19
+ export declare function walkConfigForest(configs: Iterable<EcoComponentConfig | undefined>, visitor: (config: EcoComponentConfig) => void): void;
20
+ /**
21
+ * Collects values from a config tree while preserving the shared traversal and
22
+ * cycle protection behavior used across the React integration.
23
+ */
24
+ export declare function collectFromConfigTree<T>(config: EcoComponentConfig | undefined, collector: (config: EcoComponentConfig) => T[]): T[];
25
+ /**
26
+ * Collects values from multiple config roots with one shared visited set.
27
+ */
28
+ export declare function collectFromConfigForest<T>(configs: Iterable<EcoComponentConfig | undefined>, collector: (config: EcoComponentConfig) => T[]): T[];
29
+ /**
30
+ * Returns true when any node in the config tree matches the predicate.
31
+ */
32
+ export declare function someInConfigTree(config: EcoComponentConfig | undefined, predicate: (config: EcoComponentConfig) => boolean): boolean;
33
+ /**
34
+ * Reads config roots from partial components while tolerating undefined config.
35
+ */
36
+ export declare function getComponentConfigs(components: Partial<EcoComponent>[]): Array<EcoComponentConfig | undefined>;
@@ -0,0 +1,54 @@
1
+ function walkConfigTree(config, visitor, visited = /* @__PURE__ */ new Set()) {
2
+ if (!config || visited.has(config)) {
3
+ return;
4
+ }
5
+ visited.add(config);
6
+ visitor(config);
7
+ if (config.layout?.config) {
8
+ walkConfigTree(config.layout.config, visitor, visited);
9
+ }
10
+ for (const component of config.dependencies?.components ?? []) {
11
+ walkConfigTree(component.config, visitor, visited);
12
+ }
13
+ }
14
+ function walkConfigForest(configs, visitor) {
15
+ const visited = /* @__PURE__ */ new Set();
16
+ for (const config of configs) {
17
+ walkConfigTree(config, visitor, visited);
18
+ }
19
+ }
20
+ function collectFromConfigTree(config, collector) {
21
+ const values = [];
22
+ walkConfigTree(config, (node) => {
23
+ values.push(...collector(node));
24
+ });
25
+ return values;
26
+ }
27
+ function collectFromConfigForest(configs, collector) {
28
+ const values = [];
29
+ walkConfigForest(configs, (node) => {
30
+ values.push(...collector(node));
31
+ });
32
+ return values;
33
+ }
34
+ function someInConfigTree(config, predicate) {
35
+ let matched = false;
36
+ walkConfigTree(config, (node) => {
37
+ if (matched) {
38
+ return;
39
+ }
40
+ matched = predicate(node);
41
+ });
42
+ return matched;
43
+ }
44
+ function getComponentConfigs(components) {
45
+ return components.map((component) => component.config);
46
+ }
47
+ export {
48
+ collectFromConfigForest,
49
+ collectFromConfigTree,
50
+ getComponentConfigs,
51
+ someInConfigTree,
52
+ walkConfigForest,
53
+ walkConfigTree
54
+ };
@@ -29,7 +29,7 @@ export declare function normalizeDeclaredModuleSources(modules?: string[]): stri
29
29
  * Recursively walks a component config tree (including layouts and nested
30
30
  * `dependencies.components`) to collect all declared module sources.
31
31
  */
32
- export declare function collectDeclaredModulesInConfig(config: EcoComponentConfig | undefined, visited?: Set<EcoComponentConfig>): string[];
32
+ export declare function collectDeclaredModulesInConfig(config: EcoComponentConfig | undefined): string[];
33
33
  /**
34
34
  * Collects declared module sources from an already imported page module.
35
35
  */
@@ -1,3 +1,4 @@
1
+ import { collectFromConfigTree } from "./component-config-traversal.js";
1
2
  function parseDeclaredModuleSource(value) {
2
3
  const source = value.trim();
3
4
  if (source.length === 0) return void 0;
@@ -16,21 +17,8 @@ function normalizeDeclaredModuleSources(modules) {
16
17
  }
17
18
  return Array.from(seen);
18
19
  }
19
- function collectDeclaredModulesInConfig(config, visited = /* @__PURE__ */ new Set()) {
20
- if (!config || visited.has(config)) {
21
- return [];
22
- }
23
- visited.add(config);
24
- const declarations = normalizeDeclaredModuleSources(config.dependencies?.modules);
25
- if (config.layout?.config) {
26
- declarations.push(...collectDeclaredModulesInConfig(config.layout.config, visited));
27
- }
28
- for (const component of config.dependencies?.components ?? []) {
29
- if (component.config) {
30
- declarations.push(...collectDeclaredModulesInConfig(component.config, visited));
31
- }
32
- }
33
- return declarations;
20
+ function collectDeclaredModulesInConfig(config) {
21
+ return collectFromConfigTree(config, (node) => normalizeDeclaredModuleSources(node.dependencies?.modules));
34
22
  }
35
23
  function collectPageDeclaredModulesFromModule(pageModule) {
36
24
  const declarations = [
@@ -41,7 +29,10 @@ function collectPageDeclaredModulesFromModule(pageModule) {
41
29
  }
42
30
  async function collectPageDeclaredModules(pagePath) {
43
31
  try {
44
- const pageModule = await import(pagePath);
32
+ const pageModule = await import(
33
+ /* @vite-ignore */
34
+ pagePath
35
+ );
45
36
  return collectPageDeclaredModulesFromModule(pageModule);
46
37
  } catch {
47
38
  return [];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Suspense } from "react";
3
+ import { afterEach, describe, expect, it } from "vitest";
4
+ import { cleanup, render, screen } from "@testing-library/react";
5
+ import { dynamic } from "./dynamic.js";
6
+ function createDeferredImport() {
7
+ let resolve;
8
+ const promise = new Promise((innerResolve) => {
9
+ resolve = innerResolve;
10
+ });
11
+ return {
12
+ promise,
13
+ resolve
14
+ };
15
+ }
16
+ describe("dynamic", () => {
17
+ afterEach(() => {
18
+ cleanup();
19
+ });
20
+ it("returns a browser lazy component that resolves through Suspense", async () => {
21
+ const deferredImport = createDeferredImport();
22
+ const DynamicComponent = dynamic(() => deferredImport.promise);
23
+ render(
24
+ /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("span", { children: "Loading dynamic component" }), children: /* @__PURE__ */ jsx(DynamicComponent, {}) })
25
+ );
26
+ expect(screen.getByText("Loading dynamic component")).toBeTruthy();
27
+ deferredImport.resolve({
28
+ default: () => /* @__PURE__ */ jsx("span", { children: "Dynamic content" })
29
+ });
30
+ expect(await screen.findByText("Dynamic content")).toBeTruthy();
31
+ expect(screen.queryByText("Loading dynamic component")).toBeNull();
32
+ });
33
+ });
@@ -30,10 +30,8 @@ export type IslandHydrationScriptOptions = {
30
30
  reactImportPath: string;
31
31
  /** Browser import path for react-dom/client runtime. */
32
32
  reactDomClientImportPath: string;
33
- /** Selector that resolves to the SSR root element for this island instance. */
33
+ /** Selector that resolves to all SSR root elements for this island component. */
34
34
  targetSelector: string;
35
- /** Serialized component props emitted at render time. */
36
- props: Record<string, unknown>;
37
35
  /** Optional stable component id used to resolve named exports reliably. */
38
36
  componentRef?: string;
39
37
  /** Optional source file hint used as fallback for component resolution. */
@@ -43,7 +41,18 @@ export type IslandHydrationScriptOptions = {
43
41
  };
44
42
  /**
45
43
  * Creates a hydration script for client-side React hydration.
46
- * Generates appropriate script based on environment and router configuration.
44
+ *
45
+ * Why this dispatcher exists:
46
+ * the runtime matrix is small but behaviorally different across development vs
47
+ * production and router vs non-router pages. Keeping that branch here preserves
48
+ * a compact public API while allowing each emitted script to stay focused.
49
+ *
50
+ * Selection rules:
51
+ * - development uses readable scripts with HMR hooks
52
+ * - production uses minified equivalents
53
+ * - router presence decides whether page updates flow through the router runtime
54
+ * or rebuild directly from the page module
55
+ *
47
56
  * @param options - Configuration options for script generation
48
57
  * @returns The generated hydration script as a string
49
58
  */
@@ -63,8 +72,14 @@ export declare function createHydrationScript(options: HydrationScriptOptions):
63
72
  * - resolves the component export by metadata (`componentRef`, `componentFile`)
64
73
  * before falling back to default/first function export
65
74
  * - selects island root using `targetSelector`
75
+ * - replaces the SSR host with a dedicated client-owned container
66
76
  * - creates a fresh React root and renders with serialized `props`
67
77
  *
78
+ * Why it remounts instead of hydrating:
79
+ * island SSR intentionally avoids synthetic wrapper elements. The runtime swaps
80
+ * the authored SSR node for a dedicated client-owned container before mounting
81
+ * so the server markup stays clean while the client still gets a stable root.
82
+ *
68
83
  * @param options Island script generation options.
69
84
  * @returns Browser-executable JavaScript module source.
70
85
  */