@ecopages/react 0.2.1-beta.0 → 0.3.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.
- package/README.md +164 -28
- package/package.json +67 -30
- package/src/app/client-only.js +10 -0
- package/src/app/dynamic.js +9 -0
- package/src/app/dynamic.test.browser.js +38 -0
- package/src/bundling/bootstrap-package-paths.d.ts +5 -0
- package/src/bundling/bootstrap-package-paths.js +5 -0
- package/src/{services/react-bundle.service.d.ts → bundling/bundle.d.ts} +29 -11
- package/src/bundling/bundle.js +130 -0
- package/src/bundling/runtime-alias-map.d.ts +12 -0
- package/src/bundling/runtime-alias-map.js +110 -0
- package/src/bundling/runtime-bundle.d.ts +70 -0
- package/src/bundling/runtime-bundle.js +233 -0
- package/src/{utils/react-dom-runtime-interop-plugin.d.ts → bundling/runtime-interop-plugin.d.ts} +1 -1
- package/src/bundling/runtime-interop-plugin.js +32 -0
- package/src/bundling/runtime-mode.d.ts +1 -0
- package/src/bundling/runtime-mode.js +10 -0
- package/src/bundling/runtime-modules.d.ts +21 -0
- package/src/bundling/runtime-modules.js +28 -0
- package/src/client-graph/ast-transform-eco-page.d.ts +10 -0
- package/src/client-graph/ast-transform-eco-page.js +71 -0
- package/src/client-graph/ast-transform-import-edits.d.ts +13 -0
- package/src/client-graph/ast-transform-import-edits.js +75 -0
- package/src/client-graph/ast-transform-walk-imports.d.ts +20 -0
- package/src/client-graph/ast-transform-walk-imports.js +105 -0
- package/src/client-graph/ast-transform.d.ts +12 -0
- package/src/client-graph/ast-transform.js +91 -0
- package/src/client-graph/ast-walk.d.ts +10 -0
- package/src/client-graph/ast-walk.js +26 -0
- package/src/client-graph/boundary-plugin-read-file-inline.d.ts +7 -0
- package/src/client-graph/boundary-plugin-read-file-inline.js +43 -0
- package/src/client-graph/boundary-plugin-transform.d.ts +16 -0
- package/src/client-graph/boundary-plugin-transform.js +31 -0
- package/src/client-graph/boundary-plugin.d.ts +23 -0
- package/src/client-graph/boundary-plugin.js +177 -0
- package/src/client-graph/component-config-traversal.js +77 -0
- package/src/client-graph/declared-modules.js +69 -0
- package/src/client-graph/module-classification.d.ts +3 -0
- package/src/client-graph/module-classification.js +43 -0
- package/src/client-graph/reachability-analyzer.d.ts +26 -0
- package/src/client-graph/reachability-analyzer.js +55 -0
- package/src/client-graph/reachability-client-roots.d.ts +8 -0
- package/src/client-graph/reachability-client-roots.js +59 -0
- package/src/client-graph/reachability-export-names.d.ts +5 -0
- package/src/client-graph/reachability-export-names.js +34 -0
- package/src/client-graph/reachability-fallback-roots.d.ts +3 -0
- package/src/client-graph/reachability-fallback-roots.js +71 -0
- package/src/client-graph/reachability-preload.d.ts +10 -0
- package/src/client-graph/reachability-preload.js +30 -0
- package/src/client-graph/reachability-top-level-index.d.ts +14 -0
- package/src/client-graph/reachability-top-level-index.js +93 -0
- package/src/client-graph/reachability-traverse.d.ts +7 -0
- package/src/client-graph/reachability-traverse.js +201 -0
- package/src/client-graph/specifier-classification.d.ts +74 -0
- package/src/client-graph/specifier-classification.js +191 -0
- package/src/content/collection-component-cache.d.ts +25 -0
- package/src/content/collection-component-cache.js +62 -0
- package/src/contracts/router-adapter.js +6 -0
- package/src/dev-transform/react-dev-transform-contributor.d.ts +17 -0
- package/src/dev-transform/react-dev-transform-contributor.js +22 -0
- package/src/hmr/hmr-strategy-process.d.ts +34 -0
- package/src/hmr/hmr-strategy-process.js +83 -0
- package/src/hmr/hmr-strategy.d.ts +67 -0
- package/src/hmr/hmr-strategy.js +306 -0
- package/src/{services/react-hmr-page-metadata-cache.d.ts → hmr/page-metadata-cache.d.ts} +5 -1
- package/src/hmr/page-metadata-cache.js +44 -0
- package/src/hmr/react-hmr-dev-transform-plugins.d.ts +22 -0
- package/src/hmr/react-hmr-dev-transform-plugins.js +19 -0
- package/src/hydration/assert-no-bare-ecopages-imports.d.ts +4 -0
- package/src/hydration/assert-no-bare-ecopages-imports.js +7 -0
- package/src/hydration/bootstrap-imports.d.ts +25 -0
- package/src/hydration/bootstrap-imports.js +33 -0
- package/src/hydration/browser/island-hydration.d.ts +82 -0
- package/src/hydration/browser/island-hydration.js +251 -0
- package/src/hydration/browser/page-hydration-hmr.d.ts +11 -0
- package/src/hydration/browser/page-hydration-hmr.js +56 -0
- package/src/hydration/browser/page-hydration-module.d.ts +8 -0
- package/src/hydration/browser/page-hydration-module.js +17 -0
- package/src/hydration/browser/page-hydration.d.ts +54 -0
- package/src/hydration/browser/page-hydration.js +177 -0
- package/src/hydration/compiled-page-hydration-options.d.ts +20 -0
- package/src/hydration/hydration-asset.d.ts +127 -0
- package/src/hydration/hydration-asset.js +379 -0
- package/src/hydration/hydration-lifecycle.test.browser.d.ts +1 -0
- package/src/hydration/hydration-lifecycle.test.browser.js +461 -0
- package/src/hydration/hydration-page-entry-source.d.ts +5 -0
- package/src/hydration/hydration-page-entry-source.js +87 -0
- package/src/hydration/hydration-script-compiler.d.ts +48 -0
- package/src/hydration/hydration-script-compiler.js +213 -0
- package/src/hydration/page-data-manifest.d.ts +58 -0
- package/src/hydration/page-data-manifest.js +97 -0
- package/src/hydration/page-data-reader.d.ts +17 -0
- package/src/hydration/page-data-reader.js +31 -0
- package/src/hydration/page-payload.d.ts +68 -0
- package/src/hydration/page-payload.js +106 -0
- package/src/hydration/serialize-page-data-script.d.ts +27 -0
- package/src/hydration/serialize-page-data-script.js +30 -0
- package/src/{services/react-mdx-config-dependency.service.d.ts → mdx/mdx-config-dependency.d.ts} +9 -8
- package/src/mdx/mdx-config-dependency.js +107 -0
- package/src/mdx/mdx-loader-plugin.d.ts +8 -0
- package/src/mdx/mdx-loader-plugin.js +11 -0
- package/src/page/page-module.d.ts +46 -0
- package/src/page/page-module.js +74 -0
- package/src/plugin/react.constants.js +1 -0
- package/src/{react.plugin.d.ts → plugin/react.plugin.d.ts} +21 -27
- package/src/plugin/react.plugin.js +210 -0
- package/src/plugin/react.types.d.ts +106 -0
- package/src/plugin/react.types.js +1 -0
- package/src/render/component-ownership.d.ts +49 -0
- package/src/render/component-ownership.js +47 -0
- package/src/render/component-ssr.d.ts +59 -0
- package/src/render/component-ssr.js +76 -0
- package/src/render/eco-embed.js +9 -0
- package/src/render/errors.d.ts +16 -0
- package/src/render/errors.js +23 -0
- package/src/render/html-boundary.js +59 -0
- package/src/render/layout-compose.d.ts +66 -0
- package/src/render/layout-compose.js +134 -0
- package/src/render/react-renderer.d.ts +114 -0
- package/src/render/react-renderer.js +490 -0
- package/src/render/react-runtime.d.ts +13 -0
- package/src/render/react-runtime.js +26 -0
- package/src/render/unified-layout-composition.d.ts +22 -0
- package/src/render/unified-layout-composition.js +31 -0
- package/src/runtime/use-sync-external-store-with-selector.js +52 -54
- package/src/eco-embed.js +0 -11
- package/src/react-hmr-strategy.d.ts +0 -230
- package/src/react-hmr-strategy.js +0 -657
- package/src/react-renderer.d.ts +0 -233
- package/src/react-renderer.js +0 -622
- package/src/react.constants.js +0 -4
- package/src/react.plugin.js +0 -205
- package/src/react.types.d.ts +0 -88
- package/src/react.types.js +0 -0
- package/src/router-adapter.js +0 -0
- package/src/services/pages-index.d.ts +0 -64
- package/src/services/pages-index.js +0 -73
- package/src/services/react-bundle.service.js +0 -86
- package/src/services/react-hmr-page-metadata-cache.js +0 -35
- package/src/services/react-hydration-asset.service.d.ts +0 -84
- package/src/services/react-hydration-asset.service.js +0 -217
- package/src/services/react-mdx-config-dependency.service.js +0 -122
- package/src/services/react-page-module.service.d.ts +0 -88
- package/src/services/react-page-module.service.js +0 -166
- package/src/services/react-page-payload.service.d.ts +0 -46
- package/src/services/react-page-payload.service.js +0 -67
- package/src/services/react-runtime-bundle.service.d.ts +0 -45
- package/src/services/react-runtime-bundle.service.js +0 -186
- package/src/utils/client-graph-boundary-cache.d.ts +0 -108
- package/src/utils/client-graph-boundary-cache.js +0 -116
- package/src/utils/client-graph-boundary-plugin.d.ts +0 -51
- package/src/utils/client-graph-boundary-plugin.js +0 -552
- package/src/utils/client-only.js +0 -19
- package/src/utils/component-config-traversal.js +0 -54
- package/src/utils/declared-modules.js +0 -47
- package/src/utils/dynamic.js +0 -12
- package/src/utils/dynamic.test.browser.js +0 -33
- package/src/utils/hmr-scripts.d.ts +0 -18
- package/src/utils/hmr-scripts.js +0 -31
- package/src/utils/html-boundary.js +0 -55
- package/src/utils/hydration-scripts.d.ts +0 -92
- package/src/utils/hydration-scripts.js +0 -358
- package/src/utils/hydration-scripts.test.browser.js +0 -198
- package/src/utils/reachability-analyzer.d.ts +0 -66
- package/src/utils/reachability-analyzer.js +0 -339
- package/src/utils/react-dom-runtime-interop-plugin.js +0 -38
- package/src/utils/react-mdx-loader-plugin.d.ts +0 -3
- package/src/utils/react-mdx-loader-plugin.js +0 -45
- package/src/utils/react-runtime-alias-map.d.ts +0 -8
- package/src/utils/react-runtime-alias-map.js +0 -90
- /package/src/{utils → app}/client-only.d.ts +0 -0
- /package/src/{utils → app}/dynamic.d.ts +0 -0
- /package/src/{utils → app}/dynamic.test.browser.d.ts +0 -0
- /package/src/{utils → client-graph}/component-config-traversal.d.ts +0 -0
- /package/src/{utils → client-graph}/declared-modules.d.ts +0 -0
- /package/src/{declarations.d.ts → contracts/declarations.d.ts} +0 -0
- /package/src/{router-adapter.d.ts → contracts/router-adapter.d.ts} +0 -0
- /package/src/{utils/hydration-scripts.test.browser.d.ts → hydration/compiled-page-hydration-options.js} +0 -0
- /package/src/{react.constants.d.ts → plugin/react.constants.d.ts} +0 -0
- /package/src/{eco-embed.d.ts → render/eco-embed.d.ts} +0 -0
- /package/src/{utils → render}/html-boundary.d.ts +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified React layout + page composition for SSR document shells.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* When every shell layout is React-managed, compose one element tree via
|
|
6
|
+
* {@link composeLayoutPageTree} / {@link composeLayoutPageTreeFromShell} instead of
|
|
7
|
+
* rendering each tier separately. This keeps SSR DOM shape aligned with client
|
|
8
|
+
* hydration through `@ecopages/react/layout-compose`.
|
|
9
|
+
*/
|
|
10
|
+
import { isReactManagedComponent } from './component-ownership.js';
|
|
11
|
+
import { assertComposablePage, composeLayoutPageTree, composeLayoutPageTreeFromShell, } from './layout-compose.js';
|
|
12
|
+
export function composeReactLayoutPageTree(Page, pageProps, shellEntries, options) {
|
|
13
|
+
const hasNormalizedLayouts = Boolean(Page.config?.layoutEntries?.length) || Boolean(Page.config?.layouts?.length);
|
|
14
|
+
if (hasNormalizedLayouts) {
|
|
15
|
+
return composeLayoutPageTree(Page, pageProps, options);
|
|
16
|
+
}
|
|
17
|
+
return composeLayoutPageTreeFromShell(Page, pageProps, shellEntries, options);
|
|
18
|
+
}
|
|
19
|
+
export function shouldUseUnifiedReactLayoutComposition(options) {
|
|
20
|
+
const { page, shellLayouts, reactIntegrationName } = options;
|
|
21
|
+
if (!isReactManagedComponent(page, reactIntegrationName)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const composablePage = assertComposablePage(page);
|
|
25
|
+
const configLayouts = composablePage.config?.layouts ?? composablePage.config?.layoutEntries?.map((entry) => entry.component) ?? [];
|
|
26
|
+
const layoutComponents = shellLayouts.length > 0 ? shellLayouts.map((layout) => layout.component) : configLayouts;
|
|
27
|
+
if (layoutComponents.length === 0) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return layoutComponents.every((component) => isReactManagedComponent(component, reactIntegrationName));
|
|
31
|
+
}
|
|
@@ -1,56 +1,54 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps -- shim mirrors upstream ref-based hook semantics */
|
|
2
|
+
import { useDebugValue, useEffect, useMemo, useRef, useSyncExternalStore } from 'react';
|
|
2
3
|
const objectIs = Object.is;
|
|
3
|
-
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
4
|
+
export function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
5
|
+
const instRef = useRef({ hasValue: false, value: undefined });
|
|
6
|
+
const memoizedSelectionRef = useMemo(() => {
|
|
7
|
+
let hasMemo = false;
|
|
8
|
+
let memoizedSnapshot;
|
|
9
|
+
let memoizedSelection;
|
|
10
|
+
const maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
|
|
11
|
+
const memoizedSelector = (nextSnapshot) => {
|
|
12
|
+
if (!hasMemo) {
|
|
13
|
+
hasMemo = true;
|
|
14
|
+
memoizedSnapshot = nextSnapshot;
|
|
15
|
+
const nextSelection = selector(nextSnapshot);
|
|
16
|
+
const inst = instRef.current;
|
|
17
|
+
if (isEqual !== undefined && inst.hasValue) {
|
|
18
|
+
const currentSelection = inst.value;
|
|
19
|
+
if (isEqual(currentSelection, nextSelection)) {
|
|
20
|
+
memoizedSelection = currentSelection;
|
|
21
|
+
return currentSelection;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
memoizedSelection = nextSelection;
|
|
25
|
+
return nextSelection;
|
|
26
|
+
}
|
|
27
|
+
const currentSelection = memoizedSelection;
|
|
28
|
+
if (objectIs(memoizedSnapshot, nextSnapshot)) {
|
|
29
|
+
return currentSelection;
|
|
30
|
+
}
|
|
31
|
+
const nextSelection = selector(nextSnapshot);
|
|
32
|
+
if (isEqual !== undefined && isEqual(currentSelection, nextSelection)) {
|
|
33
|
+
memoizedSnapshot = nextSnapshot;
|
|
34
|
+
return currentSelection;
|
|
35
|
+
}
|
|
36
|
+
memoizedSnapshot = nextSnapshot;
|
|
37
|
+
memoizedSelection = nextSelection;
|
|
38
|
+
return nextSelection;
|
|
39
|
+
};
|
|
40
|
+
return [
|
|
41
|
+
() => memoizedSelector(getSnapshot()),
|
|
42
|
+
maybeGetServerSnapshot === null ? undefined : () => memoizedSelector(maybeGetServerSnapshot()),
|
|
43
|
+
];
|
|
44
|
+
}, [getSnapshot, getServerSnapshot, selector, isEqual]);
|
|
45
|
+
const value = useSyncExternalStore(subscribe, memoizedSelectionRef[0], memoizedSelectionRef[1]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
instRef.current = {
|
|
48
|
+
hasValue: true,
|
|
49
|
+
value,
|
|
50
|
+
};
|
|
51
|
+
}, [value]);
|
|
52
|
+
useDebugValue(value);
|
|
53
|
+
return value;
|
|
53
54
|
}
|
|
54
|
-
export {
|
|
55
|
-
useSyncExternalStoreWithSelector
|
|
56
|
-
};
|
package/src/eco-embed.js
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React HMR Strategy
|
|
3
|
-
*
|
|
4
|
-
* Handles hot module replacement for React components.
|
|
5
|
-
* Triggers module invalidation on changes to ensure fresh component re-renders.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import { HmrStrategy, type HmrAction } from '@ecopages/core/hmr/hmr-strategy';
|
|
10
|
-
import type { BrowserRuntimeManifest } from '@ecopages/core/build/browser-runtime-manifest';
|
|
11
|
-
import type { DefaultHmrContext } from '@ecopages/core';
|
|
12
|
-
import type { CompileOptions } from '@mdx-js/mdx';
|
|
13
|
-
import { ClientGraphBoundaryCache } from './utils/client-graph-boundary-cache.js';
|
|
14
|
-
import type { ReactHmrPageMetadataCache } from './services/react-hmr-page-metadata-cache.js';
|
|
15
|
-
export interface ReactHmrStrategyOptions {
|
|
16
|
-
context: DefaultHmrContext;
|
|
17
|
-
pageMetadataCache: ReactHmrPageMetadataCache;
|
|
18
|
-
runtimeManifest: BrowserRuntimeManifest;
|
|
19
|
-
mdxCompilerOptions?: CompileOptions;
|
|
20
|
-
ownedTemplateExtensions?: string[];
|
|
21
|
-
allTemplateExtensions?: string[];
|
|
22
|
-
explicitGraphEnabled?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Per-app cache for client-graph-boundary transform results. Owned by
|
|
25
|
-
* the React plugin for the app's lifetime. When omitted, the strategy
|
|
26
|
-
* uses a fresh in-memory cache that does not persist across HMR
|
|
27
|
-
* rebuilds.
|
|
28
|
-
*/
|
|
29
|
-
clientGraphBoundaryCache?: ClientGraphBoundaryCache;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Strategy for handling React component HMR updates.
|
|
33
|
-
*
|
|
34
|
-
* This strategy provides React-specific HMR handling by rebuilding entrypoints
|
|
35
|
-
* and injecting HMR acceptance handlers that trigger module invalidation.
|
|
36
|
-
*
|
|
37
|
-
* The processing steps are:
|
|
38
|
-
* 1. Check if any React entrypoints are registered
|
|
39
|
-
* 2. Rebuild all React entrypoints (the changed file could be a dependency)
|
|
40
|
-
* 3. Rebuild browser output through the shared browser bundle service while
|
|
41
|
-
* preserving React-specific runtime aliases and graph policy
|
|
42
|
-
* 4. Read page config metadata through the shared server-module loading path
|
|
43
|
-
* 5. Inject HMR acceptance handler
|
|
44
|
-
* 6. Broadcast update events for each rebuilt entrypoint
|
|
45
|
-
*
|
|
46
|
-
* @remarks
|
|
47
|
-
* This strategy has higher priority than generic JsHmrStrategy, allowing it
|
|
48
|
-
* to handle React files specially while falling back to generic handling for
|
|
49
|
-
* non-React files.
|
|
50
|
-
*
|
|
51
|
-
* Future enhancement: Track dependencies using Bun's transpiler API to only
|
|
52
|
-
* rebuild affected entrypoints instead of all of them.
|
|
53
|
-
*
|
|
54
|
-
* @see https://bun.sh/docs/runtime/transpiler
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* const context = {
|
|
59
|
-
* getWatchedFiles: () => watchedFilesMap,
|
|
60
|
-
* getDistDir: () => '/path/to/dist/_hmr',
|
|
61
|
-
* getPlugins: () => [],
|
|
62
|
-
* getSrcDir: () => '/path/to/src',
|
|
63
|
-
* getLayoutsDir: () => '/path/to/src/layouts'
|
|
64
|
-
* };
|
|
65
|
-
* const strategy = new ReactHmrStrategy({
|
|
66
|
-
* context,
|
|
67
|
-
* pageMetadataCache,
|
|
68
|
-
* runtimeManifest
|
|
69
|
-
* });
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
export declare class ReactHmrStrategy extends HmrStrategy {
|
|
73
|
-
readonly type: 100;
|
|
74
|
-
private mdxCompilerOptions?;
|
|
75
|
-
private readonly ownedTemplateExtensions;
|
|
76
|
-
private readonly allTemplateExtensions;
|
|
77
|
-
private importNodePageModule;
|
|
78
|
-
/**
|
|
79
|
-
* Creates a new React HMR strategy instance.
|
|
80
|
-
*
|
|
81
|
-
* @param options - React HMR runtime services and behavior flags.
|
|
82
|
-
*/
|
|
83
|
-
private context;
|
|
84
|
-
private pageMetadataCache;
|
|
85
|
-
private explicitGraphEnabled;
|
|
86
|
-
private readonly runtimeManifest;
|
|
87
|
-
private readonly clientGraphBoundaryCache;
|
|
88
|
-
private readonly pagesIndex;
|
|
89
|
-
constructor(options: ReactHmrStrategyOptions);
|
|
90
|
-
/**
|
|
91
|
-
* Returns build plugins for React HMR bundling.
|
|
92
|
-
*
|
|
93
|
-
* Includes the client graph boundary plugin to prevent undeclared imports
|
|
94
|
-
* (including `node:*`) from breaking the browser bundle.
|
|
95
|
-
*
|
|
96
|
-
* @remarks
|
|
97
|
-
* HMR builds receive the React runtime manifest and rewrite manifest-owned
|
|
98
|
-
* runtime imports to concrete asset URLs before module resolution.
|
|
99
|
-
*/
|
|
100
|
-
private getBuildPlugins;
|
|
101
|
-
private isReactEntrypoint;
|
|
102
|
-
/**
|
|
103
|
-
* Returns true when a route file uses a compound extension like `page.foo.tsx`.
|
|
104
|
-
*
|
|
105
|
-
* @remarks
|
|
106
|
-
* React integration owns plain `.tsx` route templates. Compound extensions in
|
|
107
|
-
* pages/layouts are integration-specific route templates and should not be
|
|
108
|
-
* claimed by React HMR strategy.
|
|
109
|
-
*/
|
|
110
|
-
private isRouteTemplate;
|
|
111
|
-
private resolveTemplateExtension;
|
|
112
|
-
private ownsWatchedEntrypoint;
|
|
113
|
-
private configContainsFile;
|
|
114
|
-
private pageModuleRequiresLayoutRefresh;
|
|
115
|
-
private hasLayoutOwnedDependencyTarget;
|
|
116
|
-
/**
|
|
117
|
-
* Determines if the file is a React/MDX entrypoint that's registered for HMR.
|
|
118
|
-
*
|
|
119
|
-
* Uses a three-way decision strategy for selective invalidation:
|
|
120
|
-
* 1. If the file is a watched entrypoint, check if React owns it
|
|
121
|
-
* 2. If the file is a dependency of watched entrypoints (via dependency graph),
|
|
122
|
-
* check if any affected entrypoints are React-owned. Returns false if hits
|
|
123
|
-
* exist but none are owned (prevents unnecessary rebuilds).
|
|
124
|
-
* 3. Otherwise, check if the file itself is a React entrypoint template
|
|
125
|
-
*
|
|
126
|
-
* @param filePath - Absolute path to the changed file
|
|
127
|
-
* @returns True if this file should trigger React HMR rebuilds
|
|
128
|
-
*/
|
|
129
|
-
matches(filePath: string): boolean;
|
|
130
|
-
/**
|
|
131
|
-
* Checks if a file is a layout file.
|
|
132
|
-
*
|
|
133
|
-
* Layout files require special HMR handling because they wrap multiple pages and affect
|
|
134
|
-
* the entire page structure. When a layout changes, we trigger a 'layout-update' event
|
|
135
|
-
* instead of a regular 'update' event, which instructs the browser to perform a full
|
|
136
|
-
* page reload (or clear cache and re-render) rather than attempting module-level HMR.
|
|
137
|
-
*
|
|
138
|
-
* @param filePath - Absolute path to the file
|
|
139
|
-
* @returns True if the file is in the layouts directory
|
|
140
|
-
*/
|
|
141
|
-
private isLayoutFile;
|
|
142
|
-
private isPageEntrypoint;
|
|
143
|
-
private getEntrypointOutput;
|
|
144
|
-
private getRolldownEntryKey;
|
|
145
|
-
private getTempFileBasename;
|
|
146
|
-
private collectReactPageBuildTargets;
|
|
147
|
-
/**
|
|
148
|
-
* Expands one HMR request into the full React page build cohort when needed.
|
|
149
|
-
*
|
|
150
|
-
* @remarks
|
|
151
|
-
* Page and layout changes need one shared rebuild pass so sibling routes keep
|
|
152
|
-
* a consistent client module graph. Non-page changes that do not touch a page
|
|
153
|
-
* cohort can stay scoped to the originally requested targets.
|
|
154
|
-
*/
|
|
155
|
-
private resolveBuildTargets;
|
|
156
|
-
private partitionBuildTargets;
|
|
157
|
-
/**
|
|
158
|
-
* Processes a React file change by rebuilding affected React entrypoints.
|
|
159
|
-
*
|
|
160
|
-
* Uses a three-way decision strategy for selective invalidation:
|
|
161
|
-
* 1. Changed file is a watched entrypoint: rebuild only that entrypoint
|
|
162
|
-
* 2. Dependency graph has hits: rebuild only affected React-owned entrypoints.
|
|
163
|
-
* If hits exist but none map to React-owned entrypoints, return 'none' to
|
|
164
|
-
* prevent unnecessary rebuilds.
|
|
165
|
-
* 3. Dependency graph miss: fall back to rebuilding all watched entrypoints
|
|
166
|
-
*
|
|
167
|
-
* For layout files, broadcasts a 'layout-update' event to trigger full page reload.
|
|
168
|
-
* For regular components/pages, broadcasts 'update' events for module-level HMR.
|
|
169
|
-
*
|
|
170
|
-
* @param _filePath - Absolute path to the changed file
|
|
171
|
-
* @returns Action to broadcast update events (layout-update for layouts, update for components)
|
|
172
|
-
*/
|
|
173
|
-
process(_filePath: string): Promise<HmrAction>;
|
|
174
|
-
/**
|
|
175
|
-
* Bundles a single React/MDX entrypoint with HMR support.
|
|
176
|
-
*
|
|
177
|
-
* After successful bundling, populates the entrypoint dependency graph with
|
|
178
|
-
* the build's dependency metadata. This enables selective invalidation on
|
|
179
|
-
* subsequent file changes, so only entrypoints affected by a changed
|
|
180
|
-
* dependency are rebuilt.
|
|
181
|
-
*
|
|
182
|
-
* @param entrypointPath - Absolute path to the source file
|
|
183
|
-
* @param outputUrl - URL path for the bundled file
|
|
184
|
-
* @returns True if bundling was successful
|
|
185
|
-
*/
|
|
186
|
-
private bundleReactEntrypoint;
|
|
187
|
-
/**
|
|
188
|
-
* Bundles multiple React/MDX entrypoints in a single build pass.
|
|
189
|
-
*
|
|
190
|
-
* Uses code splitting to share common dependencies across entrypoints.
|
|
191
|
-
* After successful bundling, populates the entrypoint dependency graph with
|
|
192
|
-
* the build's dependency metadata for selective invalidation.
|
|
193
|
-
*
|
|
194
|
-
* @param entrypoints - Array of entrypoint paths and their output URLs
|
|
195
|
-
* @returns Array of output URLs that were successfully built
|
|
196
|
-
*/
|
|
197
|
-
private bundleReactEntrypoints;
|
|
198
|
-
private resolveTempOutputPath;
|
|
199
|
-
/**
|
|
200
|
-
* Clears stale HMR output from a directory before a rebuild.
|
|
201
|
-
*
|
|
202
|
-
* Only removes:
|
|
203
|
-
* - `*.tmp.js` files (the per-build bundler output the strategy owns)
|
|
204
|
-
* - the `chunks/` subdirectory (the bundler's splitting target)
|
|
205
|
-
*
|
|
206
|
-
* The HMR runtime script (`_hmr_runtime.js`) and any user-authored
|
|
207
|
-
* assets in the outdir are preserved. This is the minimal set of
|
|
208
|
-
* files that, if left from a previous build, can cause the bundler
|
|
209
|
-
* to emit `ENOENT` for chunk references that point to entrypoints
|
|
210
|
-
* whose hash has since changed.
|
|
211
|
-
*/
|
|
212
|
-
private clearHmrOutdir;
|
|
213
|
-
/**
|
|
214
|
-
* Encodes dynamic route segments (brackets) in file paths.
|
|
215
|
-
* Converts `[slug]` to `_slug_` to avoid filesystem issues.
|
|
216
|
-
*/
|
|
217
|
-
private encodeDynamicSegments;
|
|
218
|
-
private rewriteChunkImportUrls;
|
|
219
|
-
private isMissingTempOutputError;
|
|
220
|
-
/**
|
|
221
|
-
* Processes bundled output and injects the React HMR handler.
|
|
222
|
-
* Writes to temp file first, then renames atomically to avoid conflicts.
|
|
223
|
-
*
|
|
224
|
-
* @param tempPath - Path to the temporary bundled file
|
|
225
|
-
* @param finalPath - Final destination path
|
|
226
|
-
* @param url - URL path for logging
|
|
227
|
-
* @returns True if processing was successful
|
|
228
|
-
*/
|
|
229
|
-
private processOutput;
|
|
230
|
-
}
|