@timber-js/app 0.2.0-alpha.220 → 0.2.0-alpha.222
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/dist/_chunks/{actions-BwkmAYXq.js → actions-vBHr2vqd.js} +3 -3
- package/dist/_chunks/{actions-BwkmAYXq.js.map → actions-vBHr2vqd.js.map} +1 -1
- package/dist/_chunks/{cache-api-LA3sBpUS.js → cache-api-DdcDLpBj.js} +72 -145
- package/dist/_chunks/cache-api-DdcDLpBj.js.map +1 -0
- package/dist/_chunks/chains-B8TCLved.js +1 -0
- package/dist/_chunks/{chains-e_Buf9vg.js → chains-BchW_AtW.js} +2 -2
- package/dist/_chunks/{chains-e_Buf9vg.js.map → chains-BchW_AtW.js.map} +1 -1
- package/dist/_chunks/{classify-2Yp3xJY1.js → classify-IqzMpxMs.js} +2 -2
- package/dist/_chunks/{classify-2Yp3xJY1.js.map → classify-IqzMpxMs.js.map} +1 -1
- package/dist/_chunks/{cli-check-DDwCkeDY.js → cli-check-DQne_YhU.js} +3 -3
- package/dist/_chunks/{cli-check-DDwCkeDY.js.map → cli-check-DQne_YhU.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-BdIebmk3.js → cli-schema-sync-BS-RFGE2.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-BdIebmk3.js.map → cli-schema-sync-BS-RFGE2.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-CLNfXQDK.js → cli-schema-sync-v872sHms.js} +1 -1
- package/dist/_chunks/{client-dep-entries-BOkpKjj1.js → client-dep-entries-BJyP9SIu.js} +2 -2
- package/dist/_chunks/{client-dep-entries-BOkpKjj1.js.map → client-dep-entries-BJyP9SIu.js.map} +1 -1
- package/dist/_chunks/{convention-lint-ByKJ6aqD.js → convention-lint-VwzrtjIt.js} +3 -3
- package/dist/_chunks/{convention-lint-ByKJ6aqD.js.map → convention-lint-VwzrtjIt.js.map} +1 -1
- package/dist/_chunks/{dev-server-DnODXuNM.js → dev-server-BNr5drEO.js} +57 -8
- package/dist/_chunks/dev-server-BNr5drEO.js.map +1 -0
- package/dist/_chunks/dev-server-CUg7Mqh_.js +1 -0
- package/dist/_chunks/dev-store-BOa304m_.js +283 -0
- package/dist/_chunks/dev-store-BOa304m_.js.map +1 -0
- package/dist/_chunks/{error-boundary-xxxLtXt6.js → error-boundary-Bc8QPZuq.js} +71 -21
- package/dist/_chunks/error-boundary-Bc8QPZuq.js.map +1 -0
- package/dist/_chunks/{flight-source-node-0dE-t3kq.js → flight-source-node-BdHUOUqg.js} +6 -7
- package/dist/_chunks/flight-source-node-BdHUOUqg.js.map +1 -0
- package/dist/_chunks/global-context-B9PFncvb.js +48 -0
- package/dist/_chunks/global-context-B9PFncvb.js.map +1 -0
- package/dist/_chunks/{json-lossy-check-C8zBY2uZ.js → json-lossy-check-C3Sht92C.js} +2 -2
- package/dist/_chunks/{json-lossy-check-C8zBY2uZ.js.map → json-lossy-check-C3Sht92C.js.map} +1 -1
- package/dist/_chunks/{live-graph-tSWrv8eH.js → live-graph-DEu_GWbc.js} +4 -4
- package/dist/_chunks/{live-graph-tSWrv8eH.js.map → live-graph-DEu_GWbc.js.map} +1 -1
- package/dist/_chunks/{logger-CbLdcy-W.js → logger-CI_hThfy.js} +10 -2
- package/dist/_chunks/{logger-CbLdcy-W.js.map → logger-CI_hThfy.js.map} +1 -1
- package/dist/_chunks/{node-response-Dibufw_b.js → node-response-bF0bKoig.js} +49 -3
- package/dist/_chunks/node-response-bF0bKoig.js.map +1 -0
- package/dist/_chunks/{poison-scan-C4FgMxFl.js → poison-scan-DTWIfNgD.js} +2 -2
- package/dist/_chunks/{poison-scan-C4FgMxFl.js.map → poison-scan-DTWIfNgD.js.map} +1 -1
- package/dist/_chunks/{purge-store-Byr8XOjU.js → purge-store-WZaxu-3m.js} +2 -2
- package/dist/_chunks/purge-store-WZaxu-3m.js.map +1 -0
- package/dist/_chunks/{render-timeout-DOf_BBcO.js → render-timeout-Ln_u7fX-.js} +19 -11
- package/dist/_chunks/render-timeout-Ln_u7fX-.js.map +1 -0
- package/dist/_chunks/{resolve-schema-CBR6Lm4i.js → resolve-schema-CkAInout.js} +2 -2
- package/dist/_chunks/{resolve-schema-CBR6Lm4i.js.map → resolve-schema-CkAInout.js.map} +1 -1
- package/dist/_chunks/{scanner-Cb3fSjAC.js → scanner-C8fdKvKG.js} +2 -2
- package/dist/_chunks/{scanner-Cb3fSjAC.js.map → scanner-C8fdKvKG.js.map} +1 -1
- package/dist/_chunks/{schema-bridge-C83xa9lT.js → schema-bridge-DpOmvZlI.js} +60 -23
- package/dist/_chunks/schema-bridge-DpOmvZlI.js.map +1 -0
- package/dist/_chunks/{segment-context-xtPUGfdq.js → segment-context-D3DNxKFq.js} +4 -8
- package/dist/_chunks/segment-context-D3DNxKFq.js.map +1 -0
- package/dist/_chunks/{sizeof-QPE5nd3u.js → sizeof-CO3dk0V1.js} +2 -2
- package/dist/_chunks/{sizeof-QPE5nd3u.js.map → sizeof-CO3dk0V1.js.map} +1 -1
- package/dist/_chunks/{walkers-qu8TpiLh.js → walkers-BqzxnwGC.js} +3 -3
- package/dist/_chunks/{walkers-qu8TpiLh.js.map → walkers-BqzxnwGC.js.map} +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/analyze/crawl-entry.js +3 -3
- package/dist/analyze/graph-command.js +2 -2
- package/dist/cache/cache-api.d.ts.map +1 -1
- package/dist/cache/guarded-read.d.ts +29 -0
- package/dist/cache/guarded-read.d.ts.map +1 -0
- package/dist/cache/handler-store.d.ts +13 -1
- package/dist/cache/handler-store.d.ts.map +1 -1
- package/dist/cache/index.js +3 -2
- package/dist/cache/invalidation-epoch.d.ts +7 -0
- package/dist/cache/invalidation-epoch.d.ts.map +1 -1
- package/dist/cache/stores/memory.js +1 -1
- package/dist/cache/timber-cache.d.ts.map +1 -1
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/purge-store.d.ts +10 -1
- package/dist/cdn/purge-store.d.ts.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/client/browser-entry/router-init.d.ts.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/global-context.d.ts +21 -1
- package/dist/client/global-context.d.ts.map +1 -1
- package/dist/client/index.js +9 -27
- package/dist/client/index.js.map +1 -1
- package/dist/client/internal.js +38 -65
- package/dist/client/internal.js.map +1 -1
- package/dist/client/link.d.ts.map +1 -1
- package/dist/client/navigation-context.d.ts.map +1 -1
- package/dist/client/navigation-transition.d.ts +68 -14
- package/dist/client/navigation-transition.d.ts.map +1 -1
- package/dist/client/params-context.d.ts.map +1 -1
- package/dist/client/router-effects.d.ts +35 -31
- package/dist/client/router-effects.d.ts.map +1 -1
- package/dist/client/router-pipeline.d.ts +2 -6
- package/dist/client/router-pipeline.d.ts.map +1 -1
- package/dist/client/router-types.d.ts +10 -30
- package/dist/client/router-types.d.ts.map +1 -1
- package/dist/client/router.d.ts.map +1 -1
- package/dist/client/slot-context.d.ts +2 -2
- package/dist/client/slot-context.d.ts.map +1 -1
- package/dist/codec.js +1 -1
- package/dist/cookies/index.js +1 -1
- package/dist/dev-tools/logs.d.ts +2 -2
- package/dist/dev-tools/logs.d.ts.map +1 -1
- package/dist/index.js +149 -56
- package/dist/index.js.map +1 -1
- package/dist/params/index.js +1 -1
- package/dist/plugins/dev-server.d.ts +1 -1
- package/dist/plugins/dev-server.d.ts.map +1 -1
- package/dist/plugins/dev-store-clear.d.ts +28 -0
- package/dist/plugins/dev-store-clear.d.ts.map +1 -0
- package/dist/plugins/entries.d.ts +5 -0
- package/dist/plugins/entries.d.ts.map +1 -1
- package/dist/plugins/orphaned-modules.d.ts +57 -0
- package/dist/plugins/orphaned-modules.d.ts.map +1 -0
- package/dist/plugins/prebuilt.d.ts +6 -6
- package/dist/plugins/prerender-sugar.d.ts.map +1 -1
- package/dist/plugins/routing.d.ts +1 -1
- package/dist/plugins/routing.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/rsc-runtime/dev-reference-cache.d.ts +47 -0
- package/dist/rsc-runtime/dev-reference-cache.d.ts.map +1 -0
- package/dist/rsc-runtime/rsc.d.ts +0 -15
- package/dist/rsc-runtime/rsc.d.ts.map +1 -1
- package/dist/rsc-runtime/ssr.d.ts +0 -11
- package/dist/rsc-runtime/ssr.d.ts.map +1 -1
- package/dist/schema-bridge.d.ts +28 -19
- package/dist/schema-bridge.d.ts.map +1 -1
- package/dist/search-params/define.d.ts +1 -1
- package/dist/search-params/define.d.ts.map +1 -1
- package/dist/search-params/index.js +7 -8
- package/dist/search-params/index.js.map +1 -1
- package/dist/search-params/wrappers.d.ts +3 -3
- package/dist/server/abort-scope.d.ts +27 -0
- package/dist/server/abort-scope.d.ts.map +1 -0
- package/dist/server/flight-source-node.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/instrumentation.d.ts +2 -1
- package/dist/server/instrumentation.d.ts.map +1 -1
- package/dist/server/internal.d.ts +1 -1
- package/dist/server/internal.d.ts.map +1 -1
- package/dist/server/internal.js +350 -151
- package/dist/server/internal.js.map +1 -1
- package/dist/server/logger.d.ts +9 -0
- package/dist/server/logger.d.ts.map +1 -1
- package/dist/server/pipeline-helpers.d.ts.map +1 -1
- package/dist/server/pipeline.d.ts +10 -7
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/prebuilt/cache-key.d.ts +26 -0
- package/dist/server/prebuilt/cache-key.d.ts.map +1 -1
- package/dist/server/prebuilt/capture-render.d.ts +9 -4
- package/dist/server/prebuilt/capture-render.d.ts.map +1 -1
- package/dist/server/prebuilt/capture-routes.d.ts +1 -1
- package/dist/server/prebuilt/dev-store.d.ts +103 -0
- package/dist/server/prebuilt/dev-store.d.ts.map +1 -0
- package/dist/server/prebuilt/overlay.d.ts +14 -3
- package/dist/server/prebuilt/overlay.d.ts.map +1 -1
- package/dist/server/prebuilt/payload-source.d.ts +8 -0
- package/dist/server/prebuilt/payload-source.d.ts.map +1 -1
- package/dist/server/prebuilt/slots.d.ts +5 -6
- package/dist/server/prebuilt/slots.d.ts.map +1 -1
- package/dist/server/prebuilt-builder.d.ts.map +1 -1
- package/dist/server/prebuilt-runtime.d.ts +5 -10
- package/dist/server/prebuilt-runtime.d.ts.map +1 -1
- package/dist/server/render-timeout.d.ts.map +1 -1
- package/dist/server/rsc-entry/action-dispatcher.d.ts.map +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/ssr-render.d.ts.map +1 -1
- package/docs/api/32-api-cache.mdx +2 -0
- package/docs/api/33-api-search-params.mdx +3 -1
- package/docs/learn/06-typed-params.mdx +2 -2
- package/docs/learn/10-caching.mdx +12 -0
- package/docs/learn/11-middleware.mdx +2 -0
- package/package.json +1 -1
- package/src/cache/cache-api.ts +7 -1
- package/src/cache/guarded-read.ts +44 -0
- package/src/cache/handler-store.ts +38 -1
- package/src/cache/invalidation-epoch.ts +18 -6
- package/src/cache/timber-cache.ts +9 -3
- package/src/cdn/purge-store.ts +29 -1
- package/src/client/browser-entry/action-dispatch.ts +5 -5
- package/src/client/browser-entry/router-init.ts +2 -4
- package/src/client/global-context.ts +42 -14
- package/src/client/link.tsx +14 -18
- package/src/client/navigation-context.ts +4 -11
- package/src/client/navigation-transition.ts +86 -33
- package/src/client/params-context.ts +5 -17
- package/src/client/router-effects.ts +70 -45
- package/src/client/router-lifecycle.ts +1 -1
- package/src/client/router-pipeline.ts +52 -65
- package/src/client/router-types.ts +11 -31
- package/src/client/router.ts +98 -104
- package/src/client/segment-update-context.ts +1 -1
- package/src/client/slot-content-cache-context.ts +1 -1
- package/src/client/slot-context.ts +6 -17
- package/src/dev-tools/logs.ts +76 -50
- package/src/plugins/dev-server.ts +58 -9
- package/src/plugins/dev-store-clear.ts +47 -0
- package/src/plugins/entries.ts +6 -0
- package/src/plugins/orphaned-modules.ts +78 -0
- package/src/plugins/prebuilt.ts +17 -17
- package/src/plugins/prerender-sugar.ts +38 -6
- package/src/plugins/routing.ts +23 -1
- package/src/rsc-runtime/dev-reference-cache.ts +115 -0
- package/src/rsc-runtime/rsc.ts +10 -0
- package/src/rsc-runtime/ssr.ts +10 -0
- package/src/rsc-runtime/vendor-types.d.ts +8 -0
- package/src/schema-bridge.ts +93 -38
- package/src/search-params/define.ts +5 -6
- package/src/search-params/wrappers.ts +3 -3
- package/src/server/abort-scope.ts +49 -0
- package/src/server/action-handler.ts +18 -2
- package/src/server/flight-source-node.ts +5 -4
- package/src/server/instrumentation.ts +32 -8
- package/src/server/internal.ts +1 -6
- package/src/server/logger.ts +9 -0
- package/src/server/pipeline-helpers.ts +5 -3
- package/src/server/pipeline.ts +31 -20
- package/src/server/prebuilt/cache-key.ts +41 -0
- package/src/server/prebuilt/capture-render.ts +10 -6
- package/src/server/prebuilt/capture-routes.ts +1 -1
- package/src/server/prebuilt/dev-store.ts +173 -0
- package/src/server/prebuilt/overlay.ts +21 -5
- package/src/server/prebuilt/payload-source.ts +19 -0
- package/src/server/prebuilt/slots.ts +5 -6
- package/src/server/prebuilt-builder.ts +3 -2
- package/src/server/prebuilt-runtime.ts +194 -177
- package/src/server/render-timeout.ts +12 -17
- package/src/server/rsc-entry/action-dispatcher.ts +3 -1
- package/src/server/rsc-entry/index.ts +47 -13
- package/src/server/ssr-render.ts +9 -11
- package/dist/_chunks/cache-api-LA3sBpUS.js.map +0 -1
- package/dist/_chunks/chains-CDK1AWZQ.js +0 -1
- package/dist/_chunks/dev-server-DkytOEG2.js +0 -1
- package/dist/_chunks/dev-server-DnODXuNM.js.map +0 -1
- package/dist/_chunks/error-boundary-xxxLtXt6.js.map +0 -1
- package/dist/_chunks/flight-source-node-0dE-t3kq.js.map +0 -1
- package/dist/_chunks/node-response-Dibufw_b.js.map +0 -1
- package/dist/_chunks/purge-store-Byr8XOjU.js.map +0 -1
- package/dist/_chunks/render-timeout-DOf_BBcO.js.map +0 -1
- package/dist/_chunks/schema-bridge-C83xa9lT.js.map +0 -1
- package/dist/_chunks/segment-context-xtPUGfdq.js.map +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clear the cache.component dev store on every dev-server watcher event
|
|
3
|
+
* (TIM-1588, server/prebuilt/dev-store.ts) — and once more shortly after.
|
|
4
|
+
*
|
|
5
|
+
* Vite's watcher (chokidar) throttles `change`: once it emits one for a
|
|
6
|
+
* path, it DROPS every further `change` for that path for 50ms, and never
|
|
7
|
+
* emits a trailing event for them. So a save is invisible when it lands
|
|
8
|
+
* inside that window, which is easy to hit: save a file, the next request
|
|
9
|
+
* renders and stores it in a few milliseconds, save again (an editor that
|
|
10
|
+
* writes twice, a script that rewrites a file the page reads with fs).
|
|
11
|
+
* The store keeps the first save's render until some later, unrelated
|
|
12
|
+
* save. Before the store, a dropped event cost nothing: a file read with
|
|
13
|
+
* fs was read again on every request.
|
|
14
|
+
*
|
|
15
|
+
* The trailing clear lands after that window closes, so it follows any
|
|
16
|
+
* write whose event was dropped. A render that started before it cannot
|
|
17
|
+
* store (the clear records an invalidation of everything), and a render
|
|
18
|
+
* after it reads the file as written. Debounced, so a burst of saves gets
|
|
19
|
+
* one trailing clear, after the last of them. The cost is at most one
|
|
20
|
+
* extra re-render per save, in dev only.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** chokidar's per-path `change` throttle (`_throttle(EV_CHANGE, path, 50)`). */
|
|
24
|
+
const WATCHER_CHANGE_THROTTLE_MS = 50;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Comfortably past the throttle window. Both are timers started in the same
|
|
28
|
+
* synchronous emit, so this one always fires after the throttle has expired,
|
|
29
|
+
* however late the event loop runs them.
|
|
30
|
+
*/
|
|
31
|
+
const TRAILING_CLEAR_DELAY_MS = WATCHER_CHANGE_THROTTLE_MS * 2;
|
|
32
|
+
|
|
33
|
+
/** The part of Vite's `FSWatcher` this needs. */
|
|
34
|
+
interface WatcherEvents {
|
|
35
|
+
on(event: 'all', listener: () => void): unknown;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function clearDevStoreOnWatcherEvents(watcher: WatcherEvents, clear: () => void): void {
|
|
39
|
+
let trailing: ReturnType<typeof setTimeout> | undefined;
|
|
40
|
+
watcher.on('all', () => {
|
|
41
|
+
clear();
|
|
42
|
+
clearTimeout(trailing);
|
|
43
|
+
trailing = setTimeout(clear, TRAILING_CLEAR_DELAY_MS);
|
|
44
|
+
// Never the reason the dev process stays alive.
|
|
45
|
+
trailing.unref?.();
|
|
46
|
+
});
|
|
47
|
+
}
|
package/src/plugins/entries.ts
CHANGED
|
@@ -60,6 +60,12 @@ const ENTRY_FILE_MAP: Record<string, string> = {
|
|
|
60
60
|
*/
|
|
61
61
|
export const BROWSER_ENTRY_FILE = ENTRY_FILE_MAP[VIRTUAL_IDS.browserEntry];
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The real file behind virtual:timber-rsc-entry, the RSC environment's HMR
|
|
65
|
+
* boundary (see plugins/orphaned-modules.ts).
|
|
66
|
+
*/
|
|
67
|
+
export const RSC_ENTRY_FILE = ENTRY_FILE_MAP[VIRTUAL_IDS.rscEntry];
|
|
68
|
+
|
|
63
69
|
/** The \0-prefixed resolved ID for virtual:timber-config */
|
|
64
70
|
const RESOLVED_CONFIG_ID = `\0${VIRTUAL_IDS.config}`;
|
|
65
71
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep an update to an orphaned RSC module from reloading the RSC module runner.
|
|
3
|
+
*
|
|
4
|
+
* Vite propagates a server-module update up its importers to an HMR
|
|
5
|
+
* boundary (the RSC entry self-accepts). A module with no importers is a dead
|
|
6
|
+
* end, and Vite answers a dead end by full-reloading the environment's
|
|
7
|
+
* runner, which in the RSC environment leaks the whole module generation:
|
|
8
|
+
* React's dev Flight server leaves its async hook and console patches
|
|
9
|
+
* installed, and they keep every discarded copy reachable (TIM-1588,
|
|
10
|
+
* TIM-1589). Two kinds of module have no importers:
|
|
11
|
+
*
|
|
12
|
+
* - A deleted route file's module. The regenerated route manifest no longer
|
|
13
|
+
* imports it, but its node stays in the graph, so a file that appears at
|
|
14
|
+
* that path again (re-added, renamed back, a branch switch) updates it.
|
|
15
|
+
* - A server-reference module (`'use server'`) that only client components
|
|
16
|
+
* import. plugin-rsc loads server references with a runtime
|
|
17
|
+
* `import(/* @vite-ignore *\/ id)`, which records no importer edge.
|
|
18
|
+
*
|
|
19
|
+
* Neither can simply be dropped from the update. The module runner keeps the
|
|
20
|
+
* module's evaluated instance until something invalidates it, and the update
|
|
21
|
+
* is what advances the source generation that keys plugin-rsc's reference
|
|
22
|
+
* caches (rsc-runtime/dev-reference-cache.ts): without it, a no-JS form
|
|
23
|
+
* submit would keep running the edited action's old code. So the orphan is
|
|
24
|
+
* invalidated in the server graph and in the runner, and the update goes to
|
|
25
|
+
* the RSC entry instead, re-running its boot as any other server edit does.
|
|
26
|
+
*
|
|
27
|
+
* See design/21-dev-server.md §HMR Wiring.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** What this reads of a server module node (Vite's `EnvironmentModuleNode`). */
|
|
31
|
+
export interface OrphanCandidate {
|
|
32
|
+
id: string | null;
|
|
33
|
+
importers: { readonly size: number };
|
|
34
|
+
isSelfAccepting?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The slice of the RSC dev environment this needs: its server module graph
|
|
39
|
+
* and, when the runner runs in this process, the runner's evaluated modules.
|
|
40
|
+
*/
|
|
41
|
+
export interface OrphanEnvironment<M extends OrphanCandidate, E> {
|
|
42
|
+
moduleGraph: {
|
|
43
|
+
invalidateModule(mod: M): void;
|
|
44
|
+
getModulesByFile(file: string): Set<M> | undefined;
|
|
45
|
+
};
|
|
46
|
+
evaluatedModules?: {
|
|
47
|
+
getModuleById(id: string): E | undefined;
|
|
48
|
+
invalidateModule(node: E): void;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The update's modules with each orphan replaced by the RSC entry (whose
|
|
54
|
+
* file is `entryFile`). `undefined` when there are no orphans, so Vite keeps
|
|
55
|
+
* the update as it is.
|
|
56
|
+
*/
|
|
57
|
+
export function redirectOrphanedModules<M extends OrphanCandidate, E>(
|
|
58
|
+
environment: OrphanEnvironment<M, E>,
|
|
59
|
+
modules: M[],
|
|
60
|
+
entryFile: string
|
|
61
|
+
): M[] | undefined {
|
|
62
|
+
const entry = environment.moduleGraph.getModulesByFile(entryFile)?.values().next().value;
|
|
63
|
+
const orphans = modules.filter(
|
|
64
|
+
(mod) => mod !== entry && mod.importers.size === 0 && !mod.isSelfAccepting
|
|
65
|
+
);
|
|
66
|
+
if (orphans.length === 0) return undefined;
|
|
67
|
+
|
|
68
|
+
const { moduleGraph, evaluatedModules } = environment;
|
|
69
|
+
for (const mod of orphans) {
|
|
70
|
+
moduleGraph.invalidateModule(mod);
|
|
71
|
+
const evaluated = mod.id ? evaluatedModules?.getModuleById(mod.id) : undefined;
|
|
72
|
+
if (evaluated) evaluatedModules?.invalidateModule(evaluated);
|
|
73
|
+
}
|
|
74
|
+
const rest = modules.filter((mod) => !orphans.includes(mod));
|
|
75
|
+
// Not loaded yet: nothing has run, so there is nothing to update.
|
|
76
|
+
if (entry && !rest.includes(entry)) rest.push(entry);
|
|
77
|
+
return rest;
|
|
78
|
+
}
|
package/src/plugins/prebuilt.ts
CHANGED
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
* cannot see a shadow of an import binding (redeclaration error). Calls in
|
|
33
33
|
* other positions fall back to the runtime path like other untraceable forms.
|
|
34
34
|
*
|
|
35
|
-
* The rewrite
|
|
36
|
-
*
|
|
37
|
-
* dev: cache.component(fn, opts) → __prebuiltDev("<name>", fn, opts)
|
|
35
|
+
* The rewrite, in dev and production alike:
|
|
36
|
+
* cache.component(fn, opts) → __prebuilt("<id>", fn, opts)
|
|
38
37
|
*
|
|
39
|
-
* with `import { __prebuilt } from '#server-internal'` prepended.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
38
|
+
* with `import { __prebuilt } from '#server-internal'` prepended. Dev uses the
|
|
39
|
+
* same IDs: they key the dev store too, and because the hash covers the
|
|
40
|
+
* call-site text, editing the call site re-keys its entries (design/44
|
|
41
|
+
* §Dev Mode). Build attribution is recorded in production only.
|
|
42
42
|
*
|
|
43
43
|
* Component identity: `<name>_<hash16>`, e.g. `blogbody_a1b2c3d4e5f6a7b8`.
|
|
44
44
|
* The name prefix is the declaring variable's name (lowercased, for legible
|
|
@@ -447,7 +447,6 @@ export function timberPrebuilt(ctx: PluginContext): Plugin & { api: PrebuiltBuil
|
|
|
447
447
|
const relPath = relative(root, id);
|
|
448
448
|
const s = new MagicString(code);
|
|
449
449
|
const occurrences = new Map<string, number>();
|
|
450
|
-
const wrapperName = ctx.dev ? '__prebuiltDev' : '__prebuilt';
|
|
451
450
|
const componentIds: string[] = [];
|
|
452
451
|
|
|
453
452
|
for (const { call, stmt, displayName } of callSites) {
|
|
@@ -459,18 +458,19 @@ export function timberPrebuilt(ctx: PluginContext): Plugin & { api: PrebuiltBuil
|
|
|
459
458
|
const occurrence = occurrences.get(dupKey) ?? 0;
|
|
460
459
|
occurrences.set(dupKey, occurrence + 1);
|
|
461
460
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
461
|
+
const componentId = generatePrebuiltId(
|
|
462
|
+
relPath,
|
|
463
|
+
stmtText,
|
|
464
|
+
spanText,
|
|
465
|
+
occurrence,
|
|
466
|
+
displayName
|
|
467
|
+
);
|
|
468
468
|
// Only prerender-capable call sites feed the capture attribution —
|
|
469
469
|
// runtime-tier components (ttl/tags only) must do no build work.
|
|
470
|
-
if (!ctx.dev && mayPrerender(call)) componentIds.push(
|
|
470
|
+
if (!ctx.dev && mayPrerender(call)) componentIds.push(componentId);
|
|
471
471
|
|
|
472
|
-
s.overwrite(call.callee.start, call.callee.end,
|
|
473
|
-
s.appendLeft(call.arguments[0].start, `${JSON.stringify(
|
|
472
|
+
s.overwrite(call.callee.start, call.callee.end, '__prebuilt');
|
|
473
|
+
s.appendLeft(call.arguments[0].start, `${JSON.stringify(componentId)}, `);
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
// Record this module's component IDs for the RSC generateBundle
|
|
@@ -558,7 +558,7 @@ export function timberPrebuilt(ctx: PluginContext): Plugin & { api: PrebuiltBuil
|
|
|
558
558
|
|
|
559
559
|
s.appendLeft(
|
|
560
560
|
importInsertionOffset(program),
|
|
561
|
-
`import {
|
|
561
|
+
`import { __prebuilt } from '#server-internal';\n`
|
|
562
562
|
);
|
|
563
563
|
|
|
564
564
|
return {
|
|
@@ -163,14 +163,13 @@ function findDefaultExport(program: { body: AstNode[] }, source: string): Defaul
|
|
|
163
163
|
|
|
164
164
|
export function timberPrerenderSugar(ctx: PluginContext): Plugin {
|
|
165
165
|
let resolvedPages: Map<string, PrerenderExportValue> | null = null;
|
|
166
|
+
/** The route tree `resolvedPages` was computed from — a rescan replaces it. */
|
|
167
|
+
let resolvedFor: PluginContext['routeTree'] | undefined;
|
|
166
168
|
|
|
167
169
|
function ensureResolved() {
|
|
168
|
-
if (resolvedPages) return;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
resolvedPages = resolvePagePrerender(ctx.routeTree.root);
|
|
170
|
+
if (resolvedPages && resolvedFor === ctx.routeTree) return;
|
|
171
|
+
resolvedFor = ctx.routeTree;
|
|
172
|
+
resolvedPages = ctx.routeTree ? resolvePagePrerender(ctx.routeTree.root) : new Map();
|
|
174
173
|
}
|
|
175
174
|
|
|
176
175
|
return {
|
|
@@ -181,6 +180,39 @@ export function timberPrerenderSugar(ctx: PluginContext): Plugin {
|
|
|
181
180
|
resolvedPages = null;
|
|
182
181
|
},
|
|
183
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Dev: an edit can change the resolved prerender value of pages other
|
|
185
|
+
* than the edited file — a layout's `export const prerender` cascades to
|
|
186
|
+
* every descendant page. Vite re-transforms only the edited file, so
|
|
187
|
+
* the pages whose value changed are added to the update; through the
|
|
188
|
+
* RSC entry's HMR boundary they re-execute with the new wrapping
|
|
189
|
+
* (TIM-1588: dev caches prerendered output, so a stale wrapping is
|
|
190
|
+
* observable — a page switched to `prerender = false` would still be
|
|
191
|
+
* captured under the build rules). Runs after timber-routing's watcher
|
|
192
|
+
* rescan, which happens synchronously when the event fires.
|
|
193
|
+
*/
|
|
194
|
+
hotUpdate({ file, modules }) {
|
|
195
|
+
if (this.environment.name !== 'rsc' || !file.startsWith(ctx.appDir)) return;
|
|
196
|
+
const previous = resolvedPages ?? new Map<string, PrerenderExportValue>();
|
|
197
|
+
// Values are read from disk (mtime-checked), so resolve again even
|
|
198
|
+
// when the tree object is unchanged.
|
|
199
|
+
resolvedPages = null;
|
|
200
|
+
ensureResolved();
|
|
201
|
+
const next = resolvedPages!;
|
|
202
|
+
const changedPages = new Set([...previous.keys(), ...next.keys()]);
|
|
203
|
+
for (const page of changedPages) {
|
|
204
|
+
if (JSON.stringify(previous.get(page)) === JSON.stringify(next.get(page))) {
|
|
205
|
+
changedPages.delete(page);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
changedPages.delete(file);
|
|
209
|
+
const extra = [...changedPages].flatMap((page) => [
|
|
210
|
+
...(this.environment.moduleGraph.getModulesByFile(page) ?? []),
|
|
211
|
+
]);
|
|
212
|
+
if (extra.length === 0) return;
|
|
213
|
+
return [...modules, ...extra];
|
|
214
|
+
},
|
|
215
|
+
|
|
184
216
|
transform(code, id) {
|
|
185
217
|
// Only process in RSC environment (same gate as prebuilt.ts)
|
|
186
218
|
if (this?.environment?.name === 'client') return;
|
package/src/plugins/routing.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Design docs: 18-build-system.md §"Virtual Modules", 07-routing.md
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import type
|
|
11
|
+
import { isRunnableDevEnvironment, type Plugin, type ViteDevServer } from 'vite';
|
|
12
12
|
import { join } from 'node:path';
|
|
13
13
|
import { scanRoutes } from '../routing/scanner.ts';
|
|
14
14
|
import { buildDirToRouteMap, type SegmentInfo } from '../routing/segment-codegen.ts';
|
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
formatConventionWarnings,
|
|
22
22
|
} from '../routing/convention-lint.ts';
|
|
23
23
|
import type { PluginContext } from '../plugin-context.ts';
|
|
24
|
+
import { redirectOrphanedModules } from './orphaned-modules.ts';
|
|
25
|
+
import { RSC_ENTRY_FILE } from './entries.ts';
|
|
24
26
|
|
|
25
27
|
const VIRTUAL_MODULE_ID = 'virtual:timber-route-manifest';
|
|
26
28
|
const RESOLVED_VIRTUAL_ID = `\0${VIRTUAL_MODULE_ID}`;
|
|
@@ -138,6 +140,26 @@ export function timberRouting(ctx: PluginContext): Plugin {
|
|
|
138
140
|
return {
|
|
139
141
|
name: 'timber-routing',
|
|
140
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Keep an update to an orphaned RSC module (a deleted route file created
|
|
145
|
+
* again, a server-reference module) from full-reloading the RSC module
|
|
146
|
+
* runner, which leaks a module generation. See plugins/orphaned-modules.ts.
|
|
147
|
+
*/
|
|
148
|
+
hotUpdate({ modules }) {
|
|
149
|
+
if (this.environment.name !== 'rsc') return;
|
|
150
|
+
const environment = this.environment;
|
|
151
|
+
return redirectOrphanedModules(
|
|
152
|
+
{
|
|
153
|
+
moduleGraph: environment.moduleGraph,
|
|
154
|
+
evaluatedModules: isRunnableDevEnvironment(environment)
|
|
155
|
+
? environment.runner.evaluatedModules
|
|
156
|
+
: undefined,
|
|
157
|
+
},
|
|
158
|
+
modules,
|
|
159
|
+
RSC_ENTRY_FILE
|
|
160
|
+
);
|
|
161
|
+
},
|
|
162
|
+
|
|
141
163
|
/**
|
|
142
164
|
* Resolve the virtual module ID.
|
|
143
165
|
*
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev-only: key plugin-rsc's reference-module caches by source generation
|
|
3
|
+
* instead of by render.
|
|
4
|
+
*
|
|
5
|
+
* In dev, plugin-rsc appends a fresh random tag (`$$cache=<random>`) to every
|
|
6
|
+
* reference id each time it builds a manifest, and it builds one per call: a
|
|
7
|
+
* client manifest per Flight render, a server manifest per `decodeReply` /
|
|
8
|
+
* `decodeAction`. The tag forces a fresh module load after an edit. But the
|
|
9
|
+
* module loaders behind those ids (`globalThis.__vite_rsc_client_require__`
|
|
10
|
+
* in SSR, `__vite_rsc_server_require__` in RSC) are memoized by the full
|
|
11
|
+
* tagged id in a Map that is never pruned, so every request adds one entry
|
|
12
|
+
* per reference it touches, for the life of the dev server.
|
|
13
|
+
*
|
|
14
|
+
* Each entry is a promise created mid-render. React's dev Flight server
|
|
15
|
+
* records every live promise in an async-hook Map, with a debug chain that
|
|
16
|
+
* reaches the render's components, props, and request. A promise that lives
|
|
17
|
+
* forever therefore pins the request that created it: the dev server kept
|
|
18
|
+
* every rendered request, response, and socket (TIM-1589).
|
|
19
|
+
*
|
|
20
|
+
* The wrapper here rewrites the tag to the current source generation, which
|
|
21
|
+
* the environment's HMR updates advance. Within a generation every render
|
|
22
|
+
* shares one load per module (the cache grows per edit, not per request);
|
|
23
|
+
* after an edit the new generation loads fresh modules, as the random tag
|
|
24
|
+
* did. A render keeps the generation it started in: its tag is bound to a
|
|
25
|
+
* generation the first time it is seen, so a render that spans an edit still
|
|
26
|
+
* finds the promises it preloaded (Flight's synchronous `requireModule`
|
|
27
|
+
* reads the settled value of the very promise it preloaded).
|
|
28
|
+
*
|
|
29
|
+
* Production ids carry no tag and pass through untouched; the install calls
|
|
30
|
+
* sit behind `import.meta.hot`, so production never wraps anything.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const CACHE_TAG = '$$cache=';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* How long a tag keeps its generation. A render cannot outlive its render
|
|
37
|
+
* timeout (at most RENDER_TIMEOUT_CEILING_MS, two minutes, unless configured
|
|
38
|
+
* higher), so a tag older than this belongs to a finished render. Expiring by
|
|
39
|
+
* age, not by count, means no number of newer renders can evict a render
|
|
40
|
+
* still in flight (TIM-1589).
|
|
41
|
+
*/
|
|
42
|
+
const TAG_TTL_MS = 10 * 60_000;
|
|
43
|
+
|
|
44
|
+
/** The two module loaders plugin-rsc memoizes by tagged reference id. */
|
|
45
|
+
export type ReferenceRequireGlobal = '__vite_rsc_client_require__' | '__vite_rsc_server_require__';
|
|
46
|
+
|
|
47
|
+
type ReferenceRequire = (id: string) => unknown;
|
|
48
|
+
|
|
49
|
+
/** The slice of `import.meta.hot` this module needs. */
|
|
50
|
+
export interface ReferenceCacheHot {
|
|
51
|
+
on(event: 'vite:beforeUpdate' | 'vite:beforeFullReload', listener: () => void): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface GenerationState {
|
|
55
|
+
generation: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Marks an installed wrapper, carrying its generation, on the function itself. */
|
|
59
|
+
const STATE = Symbol.for('timber.devReferenceCache');
|
|
60
|
+
|
|
61
|
+
function isReferenceRequire(value: unknown): value is ReferenceRequire {
|
|
62
|
+
return typeof value === 'function';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isGenerationState(value: unknown): value is GenerationState {
|
|
66
|
+
return typeof value === 'object' && value !== null && 'generation' in value;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Wrap plugin-rsc's memoized loader `name` so its cache is keyed by source
|
|
71
|
+
* generation. Idempotent: a re-executed caller reuses the installed wrapper
|
|
72
|
+
* and its generation (resetting it would hand later renders the previous
|
|
73
|
+
* generation's modules), and re-registers the HMR listeners, which Vite drops
|
|
74
|
+
* with the re-executed module's hot context. A runner reload evaluates
|
|
75
|
+
* plugin-rsc again, which installs a fresh loader and cache to wrap.
|
|
76
|
+
*/
|
|
77
|
+
export function scopeReferenceCacheToGeneration(
|
|
78
|
+
name: ReferenceRequireGlobal,
|
|
79
|
+
hot: ReferenceCacheHot
|
|
80
|
+
): void {
|
|
81
|
+
const installed: unknown = Reflect.get(globalThis, name);
|
|
82
|
+
if (!isReferenceRequire(installed)) return;
|
|
83
|
+
|
|
84
|
+
const existing: unknown = Reflect.get(installed, STATE);
|
|
85
|
+
const state: GenerationState = isGenerationState(existing) ? existing : { generation: 0 };
|
|
86
|
+
if (state !== existing) {
|
|
87
|
+
const original = installed;
|
|
88
|
+
// In first-seen order (Map insertion order), so expired tags are at the front.
|
|
89
|
+
const tagGeneration = new Map<string, { generation: number; seenAt: number }>();
|
|
90
|
+
const scoped: ReferenceRequire = (id) => {
|
|
91
|
+
const at = id.indexOf(CACHE_TAG);
|
|
92
|
+
if (at < 0) return original(id);
|
|
93
|
+
const tag = id.slice(at + CACHE_TAG.length);
|
|
94
|
+
const now = Date.now();
|
|
95
|
+
let binding = tagGeneration.get(tag);
|
|
96
|
+
if (!binding) {
|
|
97
|
+
for (const [seen, { seenAt }] of tagGeneration) {
|
|
98
|
+
if (now - seenAt < TAG_TTL_MS) break;
|
|
99
|
+
tagGeneration.delete(seen);
|
|
100
|
+
}
|
|
101
|
+
binding = { generation: state.generation, seenAt: now };
|
|
102
|
+
tagGeneration.set(tag, binding);
|
|
103
|
+
}
|
|
104
|
+
return original(`${id.slice(0, at)}${CACHE_TAG}g${binding.generation}`);
|
|
105
|
+
};
|
|
106
|
+
Reflect.set(scoped, STATE, state);
|
|
107
|
+
Reflect.set(globalThis, name, scoped);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const advance = (): void => {
|
|
111
|
+
state.generation++;
|
|
112
|
+
};
|
|
113
|
+
hot.on('vite:beforeUpdate', advance);
|
|
114
|
+
hot.on('vite:beforeFullReload', advance);
|
|
115
|
+
}
|
package/src/rsc-runtime/rsc.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* RSC Runtime Adapter — Re-exports from @vitejs/plugin-rsc/rsc.
|
|
3
5
|
*
|
|
@@ -14,6 +16,8 @@
|
|
|
14
16
|
* `renderFlight` too.
|
|
15
17
|
*/
|
|
16
18
|
|
|
19
|
+
import { scopeReferenceCacheToGeneration } from './dev-reference-cache.ts';
|
|
20
|
+
|
|
17
21
|
// The only way to render Flight; see render-flight.ts.
|
|
18
22
|
export { renderFlight } from './render-flight.ts';
|
|
19
23
|
|
|
@@ -32,3 +36,9 @@ export {
|
|
|
32
36
|
// "use cache" (use-cache-wrapper.ts).
|
|
33
37
|
createFromReadableStream,
|
|
34
38
|
} from '@vitejs/plugin-rsc/rsc';
|
|
39
|
+
|
|
40
|
+
// plugin-rsc caches server-reference modules per decode in dev, which pins
|
|
41
|
+
// every action request; scope the cache to the source generation instead.
|
|
42
|
+
if (import.meta.hot) {
|
|
43
|
+
scopeReferenceCacheToGeneration('__vite_rsc_server_require__', import.meta.hot);
|
|
44
|
+
}
|
package/src/rsc-runtime/ssr.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* SSR Runtime Adapter — Re-exports from @vitejs/plugin-rsc/ssr.
|
|
3
5
|
*
|
|
@@ -12,8 +14,16 @@
|
|
|
12
14
|
|
|
13
15
|
import { nodeStreamsPlatform } from '../server/node-streams-platform.ts';
|
|
14
16
|
|
|
17
|
+
import { scopeReferenceCacheToGeneration } from './dev-reference-cache.ts';
|
|
18
|
+
|
|
15
19
|
export { createFromReadableStream } from '@vitejs/plugin-rsc/ssr';
|
|
16
20
|
|
|
21
|
+
// plugin-rsc caches client-reference modules per render in dev, which pins
|
|
22
|
+
// every request; scope the cache to the source generation instead.
|
|
23
|
+
if (import.meta.hot) {
|
|
24
|
+
scopeReferenceCacheToGeneration('__vite_rsc_client_require__', import.meta.hot);
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
/**
|
|
18
28
|
* Decode a Node Flight source (`server/flight-source.ts`) for SSR — plugin-rsc's
|
|
19
29
|
* `ssr.node` entry, which reads a Node `Readable`, string chunks included.
|
|
@@ -53,6 +53,14 @@ declare module '@vitejs/plugin-rsc/vendor/react-server-dom/server.edge' {
|
|
|
53
53
|
manifest: unknown,
|
|
54
54
|
options?: { temporaryReferences?: unknown; arraySizeLimit?: number }
|
|
55
55
|
): Promise<unknown[]>;
|
|
56
|
+
|
|
57
|
+
// Tests stub `loadServerAction` with functions registered the way the
|
|
58
|
+
// use-server transform registers a module's exports.
|
|
59
|
+
export function registerServerReference<T extends Function>(
|
|
60
|
+
reference: T,
|
|
61
|
+
id: string,
|
|
62
|
+
exportName: string | null
|
|
63
|
+
): T;
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
// src decodes through plugin-rsc's wrappers; tests decode a Flight response
|