@ecopages/react 0.2.0-rc.0 → 0.2.0-rc.10

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 (83) hide show
  1. package/README.md +68 -14
  2. package/package.json +17 -5
  3. package/src/app/client-only.js +3 -8
  4. package/src/bundling/bundle.js +4 -1
  5. package/src/bundling/runtime-alias-map.d.ts +0 -1
  6. package/src/bundling/runtime-alias-map.js +1 -4
  7. package/src/bundling/runtime-bundle.d.ts +9 -2
  8. package/src/bundling/runtime-bundle.js +27 -16
  9. package/src/bundling/runtime-modules.d.ts +21 -0
  10. package/src/bundling/runtime-modules.js +25 -0
  11. package/src/client-graph/ast-transform-eco-page.d.ts +10 -0
  12. package/src/client-graph/ast-transform-eco-page.js +71 -0
  13. package/src/client-graph/ast-transform-import-edits.d.ts +13 -0
  14. package/src/client-graph/ast-transform-import-edits.js +75 -0
  15. package/src/client-graph/ast-transform-walk-imports.d.ts +19 -0
  16. package/src/client-graph/ast-transform-walk-imports.js +103 -0
  17. package/src/client-graph/ast-transform.d.ts +1 -7
  18. package/src/client-graph/ast-transform.js +42 -378
  19. package/src/client-graph/ast-walk.d.ts +10 -0
  20. package/src/client-graph/ast-walk.js +26 -0
  21. package/src/client-graph/boundary-plugin-read-file-inline.d.ts +8 -0
  22. package/src/client-graph/boundary-plugin-read-file-inline.js +45 -0
  23. package/src/client-graph/boundary-plugin-transform.d.ts +18 -0
  24. package/src/client-graph/boundary-plugin-transform.js +61 -0
  25. package/src/client-graph/boundary-plugin.d.ts +0 -20
  26. package/src/client-graph/boundary-plugin.js +16 -98
  27. package/src/client-graph/reachability-analyzer.d.ts +4 -36
  28. package/src/client-graph/reachability-analyzer.js +23 -483
  29. package/src/client-graph/reachability-client-roots.d.ts +8 -0
  30. package/src/client-graph/reachability-client-roots.js +59 -0
  31. package/src/client-graph/reachability-export-names.d.ts +5 -0
  32. package/src/client-graph/reachability-export-names.js +34 -0
  33. package/src/client-graph/reachability-fallback-roots.d.ts +3 -0
  34. package/src/client-graph/reachability-fallback-roots.js +71 -0
  35. package/src/client-graph/reachability-preload.d.ts +10 -0
  36. package/src/client-graph/reachability-preload.js +30 -0
  37. package/src/client-graph/reachability-top-level-index.d.ts +14 -0
  38. package/src/client-graph/reachability-top-level-index.js +93 -0
  39. package/src/client-graph/reachability-traverse.d.ts +7 -0
  40. package/src/client-graph/reachability-traverse.js +201 -0
  41. package/src/client-graph/specifier-classification.d.ts +3 -2
  42. package/src/client-graph/specifier-classification.js +6 -2
  43. package/src/content/collection-component-cache.d.ts +25 -0
  44. package/src/content/collection-component-cache.js +62 -0
  45. package/src/hmr/hmr-strategy-process.d.ts +34 -0
  46. package/src/hmr/hmr-strategy-process.js +83 -0
  47. package/src/hmr/hmr-strategy.d.ts +3 -0
  48. package/src/hmr/hmr-strategy.js +47 -86
  49. package/src/hmr/react-hmr-dev-transform-plugins.d.ts +1 -0
  50. package/src/hmr/react-hmr-dev-transform-plugins.js +4 -1
  51. package/src/hydration/browser/island-hydration.d.ts +82 -0
  52. package/src/hydration/browser/island-hydration.js +247 -0
  53. package/src/hydration/browser/page-hydration-hmr.d.ts +11 -0
  54. package/src/hydration/browser/page-hydration-hmr.js +56 -0
  55. package/src/hydration/browser/page-hydration-module.d.ts +8 -0
  56. package/src/hydration/browser/page-hydration-module.js +17 -0
  57. package/src/hydration/browser/page-hydration.d.ts +54 -0
  58. package/src/hydration/browser/page-hydration.js +177 -0
  59. package/src/hydration/compiled-page-hydration-options.d.ts +20 -0
  60. package/src/hydration/hydration-asset.d.ts +21 -1
  61. package/src/hydration/hydration-asset.js +54 -24
  62. package/src/hydration/hydration-lifecycle.test.browser.d.ts +1 -0
  63. package/src/hydration/hydration-lifecycle.test.browser.js +409 -0
  64. package/src/hydration/hydration-page-entry-source.d.ts +5 -0
  65. package/src/hydration/hydration-page-entry-source.js +87 -0
  66. package/src/hydration/hydration-script-compiler.d.ts +48 -0
  67. package/src/hydration/hydration-script-compiler.js +213 -0
  68. package/src/hydration/page-data-reader.d.ts +0 -14
  69. package/src/hydration/page-data-reader.js +1 -47
  70. package/src/mdx/mdx-loader-plugin.d.ts +5 -1
  71. package/src/mdx/mdx-loader-plugin.js +4 -2
  72. package/src/plugin/react.plugin.js +8 -1
  73. package/src/plugin/react.types.d.ts +11 -2
  74. package/src/render/component-ssr.d.ts +17 -0
  75. package/src/render/component-ssr.js +19 -1
  76. package/src/render/react-renderer.d.ts +4 -2
  77. package/src/render/react-renderer.js +13 -7
  78. package/src/render/unified-layout-composition.d.ts +2 -0
  79. package/src/render/unified-layout-composition.js +5 -1
  80. package/src/hydration/hydration-scripts.d.ts +0 -104
  81. package/src/hydration/hydration-scripts.js +0 -483
  82. package/src/hydration/hydration-scripts.test.browser.js +0 -199
  83. /package/src/hydration/{hydration-scripts.test.browser.d.ts → compiled-page-hydration-options.js} +0 -0
@@ -0,0 +1,71 @@
1
+ import { getExportedName, isExplicitlyRequestedExport, } from './reachability-export-names.js';
2
+ function pushFunctionOrClassExportRoot(exportNode, declaration, potentialClientRoots, explicitlyRequestedExports) {
3
+ if (declaration?.type !== 'FunctionDeclaration' && declaration?.type !== 'ClassDeclaration') {
4
+ return false;
5
+ }
6
+ const declarationName = declaration.id?.name;
7
+ if (declarationName && isExplicitlyRequestedExport(declarationName, explicitlyRequestedExports)) {
8
+ potentialClientRoots.push(exportNode);
9
+ }
10
+ return true;
11
+ }
12
+ function hasRequestedVariableExport(declaration, explicitlyRequestedExports) {
13
+ return declaration.declarations.some((decl) => decl.id?.type === 'Identifier' && isExplicitlyRequestedExport(decl.id.name, explicitlyRequestedExports));
14
+ }
15
+ function hasRequestedExportSpecifier(exportNode, explicitlyRequestedExports) {
16
+ return (exportNode.specifiers?.some((specifier) => {
17
+ const exportedName = getExportedName(specifier);
18
+ return exportedName ? isExplicitlyRequestedExport(exportedName, explicitlyRequestedExports) : false;
19
+ }) ?? false);
20
+ }
21
+ function pushExportNamedFallbackRoots(exportNode, potentialClientRoots, explicitlyRequestedExports) {
22
+ if (exportNode.source && exportNode.specifiers?.length) {
23
+ if (hasRequestedExportSpecifier(exportNode, explicitlyRequestedExports)) {
24
+ potentialClientRoots.push(exportNode);
25
+ }
26
+ return;
27
+ }
28
+ const declaration = exportNode.declaration;
29
+ if (pushFunctionOrClassExportRoot(exportNode, declaration, potentialClientRoots, explicitlyRequestedExports)) {
30
+ return;
31
+ }
32
+ if (declaration?.type === 'VariableDeclaration' &&
33
+ hasRequestedVariableExport(declaration, explicitlyRequestedExports)) {
34
+ potentialClientRoots.push(exportNode);
35
+ return;
36
+ }
37
+ if (hasRequestedExportSpecifier(exportNode, explicitlyRequestedExports)) {
38
+ potentialClientRoots.push(exportNode);
39
+ }
40
+ }
41
+ export function resolveFallbackClientRoots(program, potentialClientRoots, explicitlyRequestedExports) {
42
+ if (potentialClientRoots.length > 0) {
43
+ return false;
44
+ }
45
+ if (explicitlyRequestedExports) {
46
+ for (const node of program.body) {
47
+ if (node.type === 'ExportNamedDeclaration') {
48
+ pushExportNamedFallbackRoots(node, potentialClientRoots, explicitlyRequestedExports);
49
+ }
50
+ else if (node.type === 'ExportDefaultDeclaration') {
51
+ if (isExplicitlyRequestedExport('default', explicitlyRequestedExports)) {
52
+ potentialClientRoots.push(node);
53
+ }
54
+ }
55
+ else if (node.type === 'ExportAllDeclaration') {
56
+ if (explicitlyRequestedExports === '*') {
57
+ potentialClientRoots.push(node);
58
+ }
59
+ }
60
+ }
61
+ return false;
62
+ }
63
+ for (const node of program.body) {
64
+ if (node.type === 'ExportNamedDeclaration' ||
65
+ node.type === 'ExportDefaultDeclaration' ||
66
+ node.type === 'ExportAllDeclaration') {
67
+ potentialClientRoots.push(node);
68
+ }
69
+ }
70
+ return true;
71
+ }
@@ -0,0 +1,10 @@
1
+ import type { ExportNamedDeclaration } from 'oxc-parser';
2
+ export declare function isPreloadExportStatement(statement: ExportNamedDeclaration): boolean;
3
+ /**
4
+ * Returns whether a module exports a named `preload` binding.
5
+ *
6
+ * @remarks
7
+ * Hydration entries only wire `preload` when this is true, so Pages without
8
+ * that export do not produce a missing-named-import warning.
9
+ */
10
+ export declare function hasPagePreloadExport(source: string, filename: string): boolean;
@@ -0,0 +1,30 @@
1
+ import { parseModuleSource } from '@ecopages/core/cache';
2
+ export function isPreloadExportStatement(statement) {
3
+ const declaration = statement.declaration;
4
+ if (declaration?.type === 'FunctionDeclaration' || declaration?.type === 'ClassDeclaration') {
5
+ return declaration.id?.type === 'Identifier' && declaration.id.name === 'preload';
6
+ }
7
+ if (declaration?.type === 'VariableDeclaration') {
8
+ return (declaration.declarations?.some((declarator) => declarator.id.type === 'Identifier' && declarator.id.name === 'preload') ?? false);
9
+ }
10
+ return statement.specifiers.some((specifier) => {
11
+ const exported = specifier.exported;
12
+ return exported.type === 'Identifier' ? exported.name === 'preload' : exported.value === 'preload';
13
+ });
14
+ }
15
+ /**
16
+ * Returns whether a module exports a named `preload` binding.
17
+ *
18
+ * @remarks
19
+ * Hydration entries only wire `preload` when this is true, so Pages without
20
+ * that export do not produce a missing-named-import warning.
21
+ */
22
+ export function hasPagePreloadExport(source, filename) {
23
+ try {
24
+ const { program } = parseModuleSource(filename, source);
25
+ return program.body.some((statement) => statement.type === 'ExportNamedDeclaration' && isPreloadExportStatement(statement));
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ }
@@ -0,0 +1,14 @@
1
+ import type { ParseResult } from 'oxc-parser';
2
+ import { type ClientRootScanState } from './reachability-client-roots.js';
3
+ export type TopLevelImportEntry = {
4
+ node: unknown;
5
+ specifier: string;
6
+ bindings: Map<string, string>;
7
+ isSideEffect: boolean;
8
+ };
9
+ export type TopLevelIndex = {
10
+ topLevelImports: TopLevelImportEntry[];
11
+ topLevelDeclarations: Map<string, unknown>;
12
+ clientRootState: ClientRootScanState;
13
+ };
14
+ export declare function buildTopLevelIndex(program: ParseResult['program']): TopLevelIndex;
@@ -0,0 +1,93 @@
1
+ import { checkPotentialClientRoot, createClientRootScanState, } from './reachability-client-roots.js';
2
+ import { isPreloadExportStatement } from './reachability-preload.js';
3
+ function indexImportDeclaration(statement, topLevelImports) {
4
+ if (statement.importKind === 'type') {
5
+ return;
6
+ }
7
+ const specifier = statement.source.value;
8
+ const bindings = new Map();
9
+ if (!statement.specifiers || statement.specifiers.length === 0) {
10
+ topLevelImports.push({ node: statement, specifier, bindings, isSideEffect: true });
11
+ return;
12
+ }
13
+ for (const spec of statement.specifiers) {
14
+ if (spec.type === 'ImportDefaultSpecifier') {
15
+ bindings.set(spec.local.name, 'default');
16
+ }
17
+ else if (spec.type === 'ImportNamespaceSpecifier') {
18
+ bindings.set(spec.local.name, '*');
19
+ }
20
+ else if (spec.type === 'ImportSpecifier') {
21
+ const importedName = spec.imported.type === 'Identifier' ? spec.imported.name : spec.imported.value;
22
+ bindings.set(spec.local.name, importedName);
23
+ }
24
+ }
25
+ topLevelImports.push({ node: statement, specifier, bindings, isSideEffect: false });
26
+ }
27
+ function indexExportNamedDeclaration(statement, index) {
28
+ const decl = statement.declaration;
29
+ if (isPreloadExportStatement(statement)) {
30
+ index.clientRootState.pagePreloadRoots.push(statement);
31
+ }
32
+ if (!decl) {
33
+ return;
34
+ }
35
+ if (decl.type === 'FunctionDeclaration' || decl.type === 'ClassDeclaration') {
36
+ if (decl.id?.type === 'Identifier') {
37
+ index.topLevelDeclarations.set(decl.id.name, statement);
38
+ }
39
+ return;
40
+ }
41
+ if (decl.type === 'VariableDeclaration') {
42
+ for (const v of decl.declarations) {
43
+ if (v.id.type === 'Identifier') {
44
+ index.topLevelDeclarations.set(v.id.name, statement);
45
+ checkPotentialClientRoot(v.init, index.clientRootState);
46
+ }
47
+ }
48
+ }
49
+ }
50
+ export function buildTopLevelIndex(program) {
51
+ const index = {
52
+ topLevelImports: [],
53
+ topLevelDeclarations: new Map(),
54
+ clientRootState: createClientRootScanState(),
55
+ };
56
+ for (const statement of program.body) {
57
+ if (statement.type === 'ImportDeclaration') {
58
+ indexImportDeclaration(statement, index.topLevelImports);
59
+ continue;
60
+ }
61
+ if (statement.type === 'VariableDeclaration') {
62
+ for (const decl of statement.declarations) {
63
+ if (decl.id.type === 'Identifier') {
64
+ index.topLevelDeclarations.set(decl.id.name, statement);
65
+ checkPotentialClientRoot(decl.init, index.clientRootState);
66
+ }
67
+ }
68
+ continue;
69
+ }
70
+ if (statement.type === 'FunctionDeclaration' || statement.type === 'ClassDeclaration') {
71
+ if (statement.id?.type === 'Identifier') {
72
+ index.topLevelDeclarations.set(statement.id.name, statement);
73
+ }
74
+ continue;
75
+ }
76
+ if (statement.type === 'ExportNamedDeclaration') {
77
+ indexExportNamedDeclaration(statement, index);
78
+ continue;
79
+ }
80
+ if (statement.type === 'ExportDefaultDeclaration') {
81
+ checkPotentialClientRoot(statement.declaration, index.clientRootState);
82
+ continue;
83
+ }
84
+ if (statement.type === 'ExpressionStatement') {
85
+ checkPotentialClientRoot(statement.expression, index.clientRootState);
86
+ continue;
87
+ }
88
+ if (statement.type === 'ExportAllDeclaration' && statement.source) {
89
+ index.clientRootState.potentialClientRoots.push(statement);
90
+ }
91
+ }
92
+ return index;
93
+ }
@@ -0,0 +1,7 @@
1
+ import { type ExplicitlyRequestedExports } from './reachability-export-names.js';
2
+ import type { TopLevelImportEntry } from './reachability-top-level-index.js';
3
+ export type ReachabilityTraversalResult = {
4
+ reachableImports: Map<string, Set<string> | '*'>;
5
+ reachableDeclarations: Set<unknown>;
6
+ };
7
+ export declare function runReachabilityTraversal(roots: unknown[], topLevelImports: TopLevelImportEntry[], topLevelDeclarations: Map<string, unknown>, explicitlyRequestedExports?: ExplicitlyRequestedExports): ReachabilityTraversalResult;
@@ -0,0 +1,201 @@
1
+ import { getExportedName, getLocalExportName, getReexportedImportName, isExplicitlyRequestedExport, } from './reachability-export-names.js';
2
+ function markImportReachable(reachableImports, specifier, importedName) {
3
+ let current = reachableImports.get(specifier);
4
+ if (current === '*')
5
+ return;
6
+ if (importedName === '*') {
7
+ reachableImports.set(specifier, '*');
8
+ return;
9
+ }
10
+ if (!current) {
11
+ current = new Set();
12
+ reachableImports.set(specifier, current);
13
+ }
14
+ current.add(importedName);
15
+ }
16
+ function createTraversalContext(topLevelImports, topLevelDeclarations, explicitlyRequestedExports) {
17
+ const reachableImports = new Map();
18
+ const reachableDeclarations = new Set();
19
+ const queue = [];
20
+ const visitedNodes = new Set();
21
+ function checkIdentifier(name) {
22
+ if (topLevelDeclarations.has(name)) {
23
+ const declNode = topLevelDeclarations.get(name);
24
+ if (!reachableDeclarations.has(declNode)) {
25
+ reachableDeclarations.add(declNode);
26
+ queue.push(declNode);
27
+ }
28
+ }
29
+ for (const imp of topLevelImports) {
30
+ if (imp.bindings.has(name)) {
31
+ markImportReachable(reachableImports, imp.specifier, imp.bindings.get(name));
32
+ }
33
+ }
34
+ }
35
+ return {
36
+ reachableImports,
37
+ reachableDeclarations,
38
+ queue,
39
+ visitedNodes,
40
+ checkIdentifier,
41
+ explicitlyRequestedExports,
42
+ };
43
+ }
44
+ function visitExportAll(node, ctx) {
45
+ if (typeof node.source?.value !== 'string')
46
+ return false;
47
+ markImportReachable(ctx.reachableImports, node.source.value, '*');
48
+ return true;
49
+ }
50
+ function visitExportNamed(node, ctx, localScope) {
51
+ if (typeof node.source?.value === 'string') {
52
+ for (const specifier of node.specifiers ?? []) {
53
+ const importedName = getReexportedImportName(specifier);
54
+ if (importedName) {
55
+ markImportReachable(ctx.reachableImports, node.source.value, importedName);
56
+ }
57
+ }
58
+ return true;
59
+ }
60
+ if (node.source || !ctx.explicitlyRequestedExports || !node.specifiers?.length) {
61
+ return false;
62
+ }
63
+ for (const specifier of node.specifiers) {
64
+ const exportedName = getExportedName(specifier);
65
+ if (!exportedName || !isExplicitlyRequestedExport(exportedName, ctx.explicitlyRequestedExports)) {
66
+ continue;
67
+ }
68
+ const localName = getLocalExportName(specifier);
69
+ if (localName && !localScope.has(localName)) {
70
+ ctx.checkIdentifier(localName);
71
+ }
72
+ }
73
+ return true;
74
+ }
75
+ function visitIdentifier(node, ctx, localScope) {
76
+ if (!localScope.has(node.name)) {
77
+ ctx.checkIdentifier(node.name);
78
+ }
79
+ return false;
80
+ }
81
+ function visitJsxIdentifier(node, ctx, localScope) {
82
+ if (/^[A-Z]/.test(node.name) && !localScope.has(node.name)) {
83
+ ctx.checkIdentifier(node.name);
84
+ }
85
+ return false;
86
+ }
87
+ function visitMemberExpression(node, ctx, localScope) {
88
+ traverseNode(node.object, ctx, localScope);
89
+ if (node.computed) {
90
+ traverseNode(node.property, ctx, localScope);
91
+ }
92
+ return true;
93
+ }
94
+ function visitProperty(node, ctx, localScope) {
95
+ if (node.computed)
96
+ traverseNode(node.key, ctx, localScope);
97
+ traverseNode(node.value, ctx, localScope);
98
+ return true;
99
+ }
100
+ function visitJsxElement(node, ctx, localScope) {
101
+ traverseNode(node.name, ctx, localScope);
102
+ if (node.attributes) {
103
+ for (const attr of node.attributes)
104
+ traverseNode(attr, ctx, localScope);
105
+ }
106
+ return true;
107
+ }
108
+ function visitJsxMemberExpression(node, ctx, localScope) {
109
+ traverseNode(node.object, ctx, localScope);
110
+ return true;
111
+ }
112
+ function visitCallExpression(node, ctx) {
113
+ if (node.callee?.type !== 'Identifier') {
114
+ return false;
115
+ }
116
+ if (node.callee.name === 'dynamic') {
117
+ const arg = node.arguments[0];
118
+ if (arg && (arg.type === 'ArrowFunctionExpression' || arg.type === 'FunctionExpression')) {
119
+ const body = arg.body;
120
+ if (body.type === 'ImportExpression' && body.source.type === 'Literal') {
121
+ markImportReachable(ctx.reachableImports, body.source.value, '*');
122
+ }
123
+ }
124
+ return false;
125
+ }
126
+ if (node.callee.name === 'require') {
127
+ const arg = node.arguments?.[0];
128
+ if (arg && (arg.type === 'StringLiteral' || arg.type === 'Literal') && typeof arg.value === 'string') {
129
+ markImportReachable(ctx.reachableImports, arg.value, '*');
130
+ }
131
+ }
132
+ return false;
133
+ }
134
+ function visitImportExpression(node, ctx) {
135
+ if (node.source.type === 'Literal') {
136
+ markImportReachable(ctx.reachableImports, node.source.value, '*');
137
+ }
138
+ return false;
139
+ }
140
+ function visitFunctionNode(node, ctx, localScope) {
141
+ const newScope = new Set(localScope);
142
+ if (node.id?.type === 'Identifier')
143
+ newScope.add(node.id.name);
144
+ if (node.params?.items) {
145
+ for (const p of node.params.items) {
146
+ if (p.pattern?.type === 'Identifier') {
147
+ newScope.add(p.pattern.name);
148
+ }
149
+ }
150
+ }
151
+ traverseNode(node.body, ctx, newScope);
152
+ return true;
153
+ }
154
+ const NODE_VISITORS = new Map([
155
+ ['ExportAllDeclaration', visitExportAll],
156
+ ['ExportNamedDeclaration', visitExportNamed],
157
+ ['Identifier', visitIdentifier],
158
+ ['JSXIdentifier', visitJsxIdentifier],
159
+ ['MemberExpression', visitMemberExpression],
160
+ ['Property', visitProperty],
161
+ ['JSXOpeningElement', visitJsxElement],
162
+ ['JSXClosingElement', visitJsxElement],
163
+ ['JSXMemberExpression', visitJsxMemberExpression],
164
+ ['CallExpression', visitCallExpression],
165
+ ['ImportExpression', visitImportExpression],
166
+ ['ArrowFunctionExpression', visitFunctionNode],
167
+ ['FunctionExpression', visitFunctionNode],
168
+ ['FunctionDeclaration', visitFunctionNode],
169
+ ]);
170
+ function traverseNode(node, ctx, localScope) {
171
+ if (!node || typeof node !== 'object')
172
+ return;
173
+ if (ctx.visitedNodes.has(node))
174
+ return;
175
+ ctx.visitedNodes.add(node);
176
+ if (Array.isArray(node)) {
177
+ for (const child of node)
178
+ traverseNode(child, ctx, localScope);
179
+ return;
180
+ }
181
+ const visitor = NODE_VISITORS.get(node.type);
182
+ if (visitor?.(node, ctx, localScope))
183
+ return;
184
+ for (const key in node) {
185
+ if (key !== 'type' && key !== 'start' && key !== 'end') {
186
+ traverseNode(node[key], ctx, localScope);
187
+ }
188
+ }
189
+ }
190
+ export function runReachabilityTraversal(roots, topLevelImports, topLevelDeclarations, explicitlyRequestedExports) {
191
+ const ctx = createTraversalContext(topLevelImports, topLevelDeclarations, explicitlyRequestedExports);
192
+ ctx.queue.push(...roots);
193
+ while (ctx.queue.length > 0) {
194
+ const root = ctx.queue.shift();
195
+ traverseNode(root, ctx, new Set());
196
+ }
197
+ return {
198
+ reachableImports: ctx.reachableImports,
199
+ reachableDeclarations: ctx.reachableDeclarations,
200
+ };
201
+ }
@@ -7,8 +7,9 @@ export declare function isProjectAliasSpecifier(specifier: string, projectRoot?:
7
7
  /**
8
8
  * Determines whether a specifier should be treated as server-only.
9
9
  *
10
- * This covers Node built-ins as well as local module conventions such as
11
- * `.server.ts` and extensionless imports that resolve to `.server.*` files.
10
+ * This covers Node built-ins, content collection `/server` virtual modules,
11
+ * and local module conventions such as `.server.ts` and extensionless imports
12
+ * that resolve to `.server.*` files.
12
13
  *
13
14
  * @param specifier - Raw import specifier from the module source.
14
15
  * @returns True when the import must never become client-reachable.
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import { loadTsconfigPathPrefixes, matchesTsconfigPathPrefix } from '@ecopages/core/plugins/tsconfig-import-resolver';
5
5
  import { toPackageRootSpecifier } from '@ecopages/core/plugins/package-specifier';
6
+ import { isContentServerVirtualModule } from '@ecopages/core/build/contracts/content-virtual-modules';
6
7
  import { dirname, resolve } from 'node:path';
7
8
  export function isBareSpecifier(specifier) {
8
9
  if (specifier.startsWith('.'))
@@ -25,8 +26,9 @@ export function isProjectAliasSpecifier(specifier, projectRoot) {
25
26
  /**
26
27
  * Determines whether a specifier should be treated as server-only.
27
28
  *
28
- * This covers Node built-ins as well as local module conventions such as
29
- * `.server.ts` and extensionless imports that resolve to `.server.*` files.
29
+ * This covers Node built-ins, content collection `/server` virtual modules,
30
+ * and local module conventions such as `.server.ts` and extensionless imports
31
+ * that resolve to `.server.*` files.
30
32
  *
31
33
  * @param specifier - Raw import specifier from the module source.
32
34
  * @returns True when the import must never become client-reachable.
@@ -34,6 +36,8 @@ export function isProjectAliasSpecifier(specifier, projectRoot) {
34
36
  export function isServerOnlySpecifier(specifier) {
35
37
  if (specifier.startsWith('node:'))
36
38
  return true;
39
+ if (isContentServerVirtualModule(specifier))
40
+ return true;
37
41
  return /(?:^|[/])[^/]+\.server(?:$|\.)/.test(specifier);
38
42
  }
39
43
  /**
@@ -0,0 +1,25 @@
1
+ import type { EcoComponent } from '@ecopages/core';
2
+ export type CollectionComponentCache = {
3
+ preload(slug: string): Promise<void>;
4
+ prime(slug: string, component: Promise<EcoComponent<Record<string, unknown>>>): Promise<void>;
5
+ get(slug: string): EcoComponent<Record<string, unknown>>;
6
+ };
7
+ /**
8
+ * Creates the synchronous component lookup required by a Page that preloads
9
+ * collection MDX before SSR, hydration, and client navigation.
10
+ *
11
+ * @remarks
12
+ * `preload()` loads the browser-compiled component and must not run in
13
+ * `staticProps`. A hydratable collection Page primes the cache in `staticProps`
14
+ * with its server component, then exposes a named `preload` export for
15
+ * hydration and client navigation to load the browser component.
16
+ *
17
+ * Completed loads are deliberately refreshed by the next preload. Native
18
+ * module caching keeps that inexpensive while allowing HMR to replace a
19
+ * component before the Page re-renders.
20
+ *
21
+ * `prime()` always stores the provided server component, even when a
22
+ * `preload()` is already in flight. Completions from a superseded load are
23
+ * ignored so they cannot replace the primed entry.
24
+ */
25
+ export declare function createCollectionComponentCache(loadComponent: (slug: string) => Promise<EcoComponent<Record<string, unknown>>>): CollectionComponentCache;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Creates the synchronous component lookup required by a Page that preloads
3
+ * collection MDX before SSR, hydration, and client navigation.
4
+ *
5
+ * @remarks
6
+ * `preload()` loads the browser-compiled component and must not run in
7
+ * `staticProps`. A hydratable collection Page primes the cache in `staticProps`
8
+ * with its server component, then exposes a named `preload` export for
9
+ * hydration and client navigation to load the browser component.
10
+ *
11
+ * Completed loads are deliberately refreshed by the next preload. Native
12
+ * module caching keeps that inexpensive while allowing HMR to replace a
13
+ * component before the Page re-renders.
14
+ *
15
+ * `prime()` always stores the provided server component, even when a
16
+ * `preload()` is already in flight. Completions from a superseded load are
17
+ * ignored so they cannot replace the primed entry.
18
+ */
19
+ export function createCollectionComponentCache(loadComponent) {
20
+ const records = new Map();
21
+ const store = async (slug, component) => {
22
+ const pending = {};
23
+ const promise = component.then((resolvedComponent) => {
24
+ if (records.get(slug) === pending.record) {
25
+ records.set(slug, { status: 'success', component: resolvedComponent });
26
+ }
27
+ }, (error) => {
28
+ if (records.get(slug) === pending.record) {
29
+ records.set(slug, { status: 'error', error });
30
+ }
31
+ throw error;
32
+ });
33
+ pending.record = { status: 'pending', promise };
34
+ records.set(slug, pending.record);
35
+ return await promise;
36
+ };
37
+ return {
38
+ async preload(slug) {
39
+ const existing = records.get(slug);
40
+ if (existing?.status === 'pending') {
41
+ return await existing.promise;
42
+ }
43
+ return await store(slug, loadComponent(slug));
44
+ },
45
+ async prime(slug, component) {
46
+ return await store(slug, component);
47
+ },
48
+ get(slug) {
49
+ const record = records.get(slug);
50
+ if (!record) {
51
+ throw new Error(`[ecopages] Collection content '${slug}' was rendered before it was preloaded.`);
52
+ }
53
+ if (record.status === 'success') {
54
+ return record.component;
55
+ }
56
+ if (record.status === 'error') {
57
+ throw record.error;
58
+ }
59
+ throw new Error(`[ecopages] Collection content '${slug}' is still loading during render.`);
60
+ },
61
+ };
62
+ }
@@ -0,0 +1,34 @@
1
+ import type { HmrAction } from '@ecopages/core/hmr/hmr-strategy';
2
+ import type { ReactHmrBuildTarget } from './react-hmr-dev-transform-plugins.js';
3
+ export type HmrProcessContext = {
4
+ resolvedFilePath: string;
5
+ watchedFiles: Map<string, string>;
6
+ isLayoutFile: (filePath: string) => boolean;
7
+ isPageEntrypoint: (filePath: string) => boolean;
8
+ isReactEntrypoint: (filePath: string) => boolean;
9
+ ownsWatchedEntrypoint: (filePath: string) => boolean;
10
+ isDevTransformOutputUrl: (outputUrl: string) => boolean;
11
+ collectReactPageBuildTargets: () => Promise<ReactHmrBuildTarget[]>;
12
+ hasLayoutOwnedDependencyTarget: (changedFilePath: string, requestedTargets: ReactHmrBuildTarget[]) => Promise<boolean>;
13
+ resolveBuildTargets: (requestedTargets: ReactHmrBuildTarget[], changedFilePath: string) => Promise<ReactHmrBuildTarget[]>;
14
+ partitionBuildTargets: (requestedTargets: ReactHmrBuildTarget[], groupedPageTargets: ReactHmrBuildTarget[]) => {
15
+ pageTargets: ReactHmrBuildTarget[];
16
+ nonPageTargets: ReactHmrBuildTarget[];
17
+ };
18
+ queueDevTransformOutputUpdates: (targets: readonly ReactHmrBuildTarget[], requestedOutputUrls: ReadonlySet<string>, updates: string[]) => void;
19
+ markOwnedEntrypoint: (filePath: string) => void;
20
+ getDependencyEntrypoints: (filePath: string) => Set<string>;
21
+ };
22
+ export type DependencyScanResult = {
23
+ affectedEntrypoints: Map<string, string>;
24
+ hasOwnedLayoutDependencyHit: boolean;
25
+ shouldAbort: boolean;
26
+ };
27
+ export declare function scanDependencyHits(ctx: HmrProcessContext, changedEntrypointOutput?: string): DependencyScanResult;
28
+ export declare function resolveRequestedTargets(ctx: HmrProcessContext, changedEntrypointOutput: string | undefined, isLayout: boolean, isChangedPageEntrypoint: boolean, hasOwnedLayoutDependencyHit: boolean, affectedEntrypoints: Map<string, string>, hasDependencyHits: boolean): Promise<{
29
+ requestedTargets: ReactHmrBuildTarget[];
30
+ hasLayoutOwnedRequestedTarget: boolean;
31
+ }>;
32
+ export declare function collectHmrUpdateUrls(ctx: HmrProcessContext, requestedTargets: ReactHmrBuildTarget[], pageTargets: ReactHmrBuildTarget[], nonPageTargets: ReactHmrBuildTarget[]): string[];
33
+ export declare function buildHmrAction(requiresLayoutRefresh: boolean, updates: string[]): HmrAction;
34
+ export declare function ensureWatchedEntrypointOwnership(ctx: HmrProcessContext, changedEntrypointOutput: string | undefined): 'continue' | 'abort';