@rangojs/router 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/dist/bin/rango.js +26 -14
  2. package/dist/types/browser/event-controller.d.ts +32 -0
  3. package/dist/types/browser/history-state.d.ts +16 -4
  4. package/dist/types/browser/navigation-transaction.d.ts +7 -0
  5. package/dist/types/browser/rango-state.d.ts +3 -1
  6. package/dist/types/browser/react/context.d.ts +11 -0
  7. package/dist/types/browser/react/location-state-shared.d.ts +84 -10
  8. package/dist/types/browser/react/location-state.d.ts +7 -2
  9. package/dist/types/browser/react/subscribe-to-nothing.d.ts +7 -0
  10. package/dist/types/cache/cache-scope.d.ts +4 -5
  11. package/dist/types/cache/cf/cf-cache-store.d.ts +27 -6
  12. package/dist/types/cache/cf/cf-cache-types.d.ts +12 -4
  13. package/dist/types/cache/handle-snapshot.d.ts +36 -50
  14. package/dist/types/cache/index.d.ts +2 -0
  15. package/dist/types/cache/shell-snapshot.d.ts +19 -3
  16. package/dist/types/cache/types.d.ts +21 -10
  17. package/dist/types/cache/vercel/vercel-cache-store.d.ts +28 -16
  18. package/dist/types/client-urls/navigation.d.ts +7 -1
  19. package/dist/types/client-urls/optimistic-location.d.ts +10 -4
  20. package/dist/types/handles/deferred-resolution.d.ts +11 -1
  21. package/dist/types/prerender/build-shell-capture.d.ts +8 -6
  22. package/dist/types/router/match-middleware/cache-lookup.d.ts +1 -1
  23. package/dist/types/router/navigation-snapshot.d.ts +8 -1
  24. package/dist/types/router/router-interfaces.d.ts +2 -1
  25. package/dist/types/router/router-options.d.ts +17 -7
  26. package/dist/types/router/segment-resolution/loader-cache.d.ts +21 -9
  27. package/dist/types/router-versions.d.ts +39 -0
  28. package/dist/types/rsc/handler-context.d.ts +5 -0
  29. package/dist/types/rsc/shell-build-manifest.d.ts +3 -2
  30. package/dist/types/rsc/types.d.ts +4 -6
  31. package/dist/types/server/build-version-table.d.ts +44 -0
  32. package/dist/types/server/handle-store.d.ts +87 -46
  33. package/dist/types/server/request-context.d.ts +22 -8
  34. package/dist/types/testing/build-versions.d.ts +32 -0
  35. package/dist/types/testing/dom.entry.d.ts +1 -1
  36. package/dist/types/testing/flight.entry.d.ts +1 -1
  37. package/dist/types/testing/index.d.ts +2 -0
  38. package/dist/types/testing/internal/seed-vars.d.ts +7 -2
  39. package/dist/types/testing/location-state-key.d.ts +5 -1
  40. package/dist/types/testing/render-route.d.ts +77 -6
  41. package/dist/types/testing/serve-shell-request.d.ts +21 -0
  42. package/dist/types/testing/vitest-stubs/version.d.ts +1 -0
  43. package/dist/types/types/handler-context.d.ts +8 -5
  44. package/dist/types/vite/discovery/build-versions.d.ts +393 -0
  45. package/dist/types/vite/discovery/installed-packages.d.ts +26 -0
  46. package/dist/types/vite/discovery/router-versions-phase.d.ts +52 -0
  47. package/dist/types/vite/discovery/shell-prerender-phase.d.ts +7 -17
  48. package/dist/types/vite/discovery/state.d.ts +14 -0
  49. package/dist/types/vite/encryption-key.d.ts +18 -0
  50. package/dist/types/vite/plugin-types.d.ts +27 -0
  51. package/dist/types/vite/plugins/{version-injector.d.ts → entry-bootstrap-injector.d.ts} +4 -6
  52. package/dist/types/vite/plugins/expose-ids/export-analysis.d.ts +1 -0
  53. package/dist/types/vite/plugins/expose-ids/router-transform.d.ts +14 -0
  54. package/dist/types/vite/plugins/stable-rsc-output.d.ts +51 -0
  55. package/dist/types/vite/plugins/version-plugin.d.ts +9 -11
  56. package/dist/types/vite/plugins/virtual-entries.d.ts +18 -1
  57. package/dist/types/vite/router-discovery.d.ts +6 -0
  58. package/dist/types/vite/utils/client-chunks.d.ts +2 -0
  59. package/dist/types/vite/utils/compare-strings.d.ts +7 -0
  60. package/dist/types/vite/utils/package-resolution.d.ts +8 -0
  61. package/dist/types/vite/utils/prerender-utils.d.ts +2 -0
  62. package/dist/vite/index.js +1537 -444
  63. package/package.json +1 -2
  64. package/skills/cache-guide/SKILL.md +84 -20
  65. package/skills/caching/SKILL.md +16 -5
  66. package/skills/client-urls/SKILL.md +16 -0
  67. package/skills/cloudflare/SKILL.md +2 -1
  68. package/skills/comparison/references/framework-comparison.md +16 -12
  69. package/skills/hooks/SKILL.md +3 -0
  70. package/skills/hooks/handle-and-actions.md +6 -0
  71. package/skills/hooks/navigation.md +28 -0
  72. package/skills/hooks/state.md +209 -8
  73. package/skills/hooks/urls.md +40 -1
  74. package/skills/host-router/SKILL.md +13 -0
  75. package/skills/intercept/SKILL.md +6 -0
  76. package/skills/loader/SKILL.md +19 -1
  77. package/skills/middleware/SKILL.md +2 -0
  78. package/skills/ppr/SKILL.md +119 -40
  79. package/skills/prerender/SKILL.md +7 -3
  80. package/skills/rango/SKILL.md +8 -7
  81. package/skills/router-setup/SKILL.md +15 -1
  82. package/skills/testing/SKILL.md +30 -26
  83. package/skills/testing/client-components.md +193 -8
  84. package/skills/testing/handles.md +2 -0
  85. package/skills/testing/loader.md +1 -1
  86. package/skills/testing/middleware.md +1 -1
  87. package/skills/testing/render-handler.md +18 -18
  88. package/skills/testing/serve-shell-request.md +63 -14
  89. package/skills/testing/server-actions.md +17 -17
  90. package/skills/testing/server-tree.md +1 -1
  91. package/skills/typesafety/generated-files-and-cli.md +1 -1
  92. package/skills/use-cache/SKILL.md +16 -5
  93. package/skills/vercel/SKILL.md +3 -3
  94. package/src/bin/rango.ts +1 -1
  95. package/src/browser/event-controller.ts +75 -2
  96. package/src/browser/history-state.ts +39 -17
  97. package/src/browser/navigation-bridge.ts +41 -18
  98. package/src/browser/navigation-transaction.ts +15 -10
  99. package/src/browser/partial-update.ts +10 -2
  100. package/src/browser/rango-state.ts +3 -1
  101. package/src/browser/react/Link.tsx +2 -3
  102. package/src/browser/react/NavigationProvider.tsx +25 -1
  103. package/src/browser/react/context.ts +13 -0
  104. package/src/browser/react/location-state-shared.ts +200 -34
  105. package/src/browser/react/location-state.ts +40 -75
  106. package/src/browser/react/subscribe-to-nothing.ts +7 -0
  107. package/src/browser/react/use-handle.ts +20 -1
  108. package/src/browser/rsc-router.tsx +33 -11
  109. package/src/browser/server-action-bridge.ts +17 -1
  110. package/src/cache/cache-scope.ts +18 -8
  111. package/src/cache/cf/cf-cache-store.ts +75 -55
  112. package/src/cache/cf/cf-cache-types.ts +12 -4
  113. package/src/cache/handle-snapshot.ts +69 -87
  114. package/src/cache/index.ts +4 -0
  115. package/src/cache/shell-snapshot.ts +35 -5
  116. package/src/cache/types.ts +21 -10
  117. package/src/cache/vercel/vercel-cache-store.ts +48 -20
  118. package/src/client-urls/client-root.tsx +1 -0
  119. package/src/client-urls/navigation.ts +10 -0
  120. package/src/client-urls/optimistic-location.ts +10 -4
  121. package/src/handles/deferred-resolution.ts +31 -0
  122. package/src/prerender/build-shell-capture.ts +11 -9
  123. package/src/router/manifest.ts +2 -0
  124. package/src/router/match-middleware/cache-lookup.ts +11 -18
  125. package/src/router/navigation-snapshot.ts +25 -6
  126. package/src/router/request-classification.ts +15 -12
  127. package/src/router/router-interfaces.ts +2 -1
  128. package/src/router/router-options.ts +17 -7
  129. package/src/router/segment-resolution/loader-cache.ts +95 -60
  130. package/src/router-versions.ts +60 -0
  131. package/src/rsc/full-payload.ts +6 -2
  132. package/src/rsc/handler-context.ts +5 -0
  133. package/src/rsc/handler.ts +14 -4
  134. package/src/rsc/rsc-rendering.ts +12 -1
  135. package/src/rsc/shell-build-manifest.ts +10 -7
  136. package/src/rsc/shell-capture.ts +36 -26
  137. package/src/rsc/types.ts +4 -6
  138. package/src/server/build-version-table.ts +115 -0
  139. package/src/server/handle-store.ts +344 -127
  140. package/src/server/request-context.ts +62 -11
  141. package/src/ssr/ssr-root.tsx +16 -4
  142. package/src/testing/build-versions.ts +64 -0
  143. package/src/testing/dispatch.ts +6 -0
  144. package/src/testing/dom.entry.ts +1 -0
  145. package/src/testing/flight.entry.ts +1 -0
  146. package/src/testing/index.ts +3 -0
  147. package/src/testing/internal/context.ts +2 -1
  148. package/src/testing/internal/seed-vars.ts +14 -2
  149. package/src/testing/location-state-key.ts +18 -8
  150. package/src/testing/render-handler.ts +2 -1
  151. package/src/testing/render-route.tsx +277 -43
  152. package/src/testing/serve-shell-request.ts +80 -11
  153. package/src/testing/vitest-stubs/version.ts +4 -1
  154. package/src/types/handler-context.ts +8 -5
  155. package/src/vite/discovery/build-versions.ts +1281 -0
  156. package/src/vite/discovery/installed-packages.ts +159 -0
  157. package/src/vite/discovery/prerender-collection.ts +38 -1
  158. package/src/vite/discovery/router-versions-phase.ts +336 -0
  159. package/src/vite/discovery/shell-prerender-phase.ts +28 -38
  160. package/src/vite/discovery/state.ts +19 -0
  161. package/src/vite/discovery/virtual-module-codegen.ts +7 -2
  162. package/src/vite/encryption-key.ts +101 -9
  163. package/src/vite/plugin-types.ts +28 -0
  164. package/src/vite/plugins/{version-injector.ts → entry-bootstrap-injector.ts} +7 -22
  165. package/src/vite/plugins/expose-ids/export-analysis.ts +1 -1
  166. package/src/vite/plugins/expose-ids/router-transform.ts +36 -15
  167. package/src/vite/plugins/expose-internal-ids.ts +12 -3
  168. package/src/vite/plugins/stable-rsc-output.ts +147 -0
  169. package/src/vite/plugins/version-plugin.ts +19 -24
  170. package/src/vite/plugins/version.d.ts +17 -2
  171. package/src/vite/plugins/virtual-entries.ts +31 -5
  172. package/src/vite/rango.ts +28 -3
  173. package/src/vite/router-discovery.ts +82 -13
  174. package/src/vite/utils/client-chunks.ts +5 -1
  175. package/src/vite/utils/compare-strings.ts +9 -0
  176. package/src/vite/utils/package-resolution.ts +9 -0
  177. package/src/vite/utils/prerender-utils.ts +4 -1
  178. package/src/vite/utils/shared-utils.ts +1 -1
@@ -0,0 +1,51 @@
1
+ import { type Plugin } from "vite";
2
+ /** One property of an object literal, by its position in the source. */
3
+ export interface LiteralProperty {
4
+ readonly key: string;
5
+ /** Range of the whole property, key included. */
6
+ readonly start: number;
7
+ readonly end: number;
8
+ /** The value's AST node. */
9
+ readonly value: any;
10
+ }
11
+ /**
12
+ * The properties of an object-literal AST node, or undefined when it is not an
13
+ * object literal of plain keys (a spread, a computed key).
14
+ */
15
+ export declare function literalProperties(object: any): LiteralProperty[] | undefined;
16
+ /**
17
+ * The properties of a module's `export default { ... }`, or undefined when
18
+ * the module does not parse or is not that shape. plugin-rsc generates its
19
+ * registries (the server-reference map, the assets manifest) in this form.
20
+ */
21
+ export declare function defaultExportProperties(code: string): LiteralProperty[] | undefined;
22
+ /**
23
+ * Return `code` with the properties of its default-exported object literal
24
+ * sorted by key, or undefined when there is nothing to reorder (or the module
25
+ * is not that shape).
26
+ */
27
+ export declare function sortDefaultExportProperties(code: string): string | undefined;
28
+ /**
29
+ * Return `code` with its default import of plugin-rsc's assets manifest
30
+ * renamed to {@link ASSETS_MANIFEST_BINDING}, or undefined when there is
31
+ * nothing to rename (no such import under a generated name, or the module
32
+ * uses the canonical name for something else).
33
+ */
34
+ export declare function canonicalAssetsManifestBinding(code: string): string | undefined;
35
+ /**
36
+ * Removes two run-to-run differences from plugin-rsc 0.5.35's build output.
37
+ * The cache versions hash these bytes (discovery/build-versions.ts).
38
+ *
39
+ * 1. Property order of the server-reference map. plugin-rsc writes it in the
40
+ * order its transforms first saw each `"use server"` module
41
+ * (`ServerReferencesManager.claimMap`), which varies with the concurrent
42
+ * scan builds (e2e/test-app: 2 of 2 consecutive builds differed). Sorted
43
+ * here so a minified server build, where stripServerReferenceMap finds no
44
+ * region comments, still hashes the same bytes.
45
+ * 2. Local name of the assets-manifest import. plugin-rsc imports the manifest
46
+ * under three names; the bundler merges them into one import per chunk and
47
+ * keeps a different one from build to build (the cache-versions fixture:
48
+ * 1 of 10 concurrent builds). One name in, one name out.
49
+ * @internal
50
+ */
51
+ export declare function stableRscOutput(): Plugin;
@@ -1,18 +1,16 @@
1
1
  import { type Plugin } from "vite";
2
2
  /**
3
- * Plugin providing rsc-router:version virtual module.
4
- * Exports VERSION that changes when RSC modules change (dev) or at build time (production).
3
+ * Plugin providing the `@rangojs/router:version` virtual module.
5
4
  *
6
- * The version is used for:
7
- * 1. Cache invalidation - CFCacheStore uses VERSION to invalidate stale cache
8
- * 2. Version mismatch detection - client sends version, server reloads on mismatch
5
+ * Dev: exports a VERSION stamp used for both versions of every router. It
6
+ * updates when the server starts and when an RSC module changes via HMR (the
7
+ * version module is invalidated). Client-only HMR changes do not update it:
8
+ * they do not affect server-rendered content or cached RSC payloads.
9
9
  *
10
- * In dev mode, the version updates when:
11
- * - Server starts (initial version)
12
- * - RSC modules change via HMR (triggers version module invalidation)
13
- *
14
- * Client-only HMR changes don't update the version since they don't affect
15
- * server-rendered content or cached RSC payloads.
10
+ * Build: exports a placeholder for the per-router versions table. The module
11
+ * holds nothing that varies between builds; the table is written into the
12
+ * built chunk after the server output is hashed (the buildApp post hook in
13
+ * router-discovery.ts). See docs/design/per-app-cache-version.md.
16
14
  * @internal
17
15
  */
18
16
  export declare function createVersionPlugin(): Plugin;
@@ -22,7 +22,7 @@ export declare function getVirtualEntrySSR(headScripts?: HeadScriptsOption, prog
22
22
  * registered for the _rsc_loader endpoint and fail in production.
23
23
  *
24
24
  * Single source of truth: both the generated virtual RSC entry below and the
25
- * custom-entry injector (version-injector) consume this list, so a new
25
+ * custom-entry injector (entry-bootstrap-injector) consume this list, so a new
26
26
  * bootstrap manifest cannot be added to one path and forgotten on the other.
27
27
  * That exact drift (loader-manifest present here but missing from the injector)
28
28
  * is what left fetchable loaders unresolved on custom worker entries.
@@ -36,4 +36,21 @@ export declare const VIRTUAL_IDS: {
36
36
  readonly rsc: "virtual:rsc-router/entry.rsc.js";
37
37
  readonly version: "@rangojs/router:version";
38
38
  };
39
+ /** Dev: one stamp for both versions of every router, bumped on RSC edits. */
39
40
  export declare function getVirtualVersionContent(version: string): string;
41
+ /**
42
+ * Free identifier the production version module ships in place of the table.
43
+ * The versions are hashes of the built server code, so they cannot be part of
44
+ * it: the buildApp post hook (router-discovery.ts) replaces this token in the
45
+ * written chunk once the hashes are final (runRouterVersionsPhase,
46
+ * discovery/router-versions-phase.ts). An unreplaced token throws a ReferenceError
47
+ * when the module evaluates, so a build that skipped the step cannot serve
48
+ * with a constant version.
49
+ */
50
+ export declare const ROUTER_VERSIONS_PLACEHOLDER = "__RANGO_ROUTER_VERSIONS__";
51
+ /**
52
+ * Production: byte-identical in every build, so it never moves the hashes it
53
+ * is later filled with. VERSION is the whole-build document version (the
54
+ * table's "*" entry).
55
+ */
56
+ export declare function getVirtualBuildVersionContent(): string;
@@ -35,6 +35,12 @@ export declare function createTempRscServer(state: DiscoveryState, options?: {
35
35
  */
36
36
  realSsrEntry?: boolean;
37
37
  }): Promise<ViteDevServer>;
38
+ import type { BuildEnvOption, BuildEnvFactoryContext, BuildEnvResult } from "./plugin-types.js";
39
+ /**
40
+ * Resolve the buildEnv option into a concrete { env, dispose? } result.
41
+ * Handles all four input shapes: false, "auto", factory, plain object.
42
+ */
43
+ export declare function resolveBuildEnv(option: BuildEnvOption | undefined, factoryCtx: BuildEnvFactoryContext): Promise<BuildEnvResult | null>;
38
44
  /**
39
45
  * Plugin that discovers router instances at dev/build time via the RSC environment.
40
46
  *
@@ -58,6 +58,8 @@ export declare function directoryClientChunks(meta: ClientChunkMeta, ctx?: Clien
58
58
  * fallback refinement does not apply — the consumer owns the grouping).
59
59
  */
60
60
  export declare function resolveClientChunks(option: ClientChunks | undefined, ctx?: ClientChunkContext): RscClientChunksFn | undefined;
61
+ /** @vitejs/plugin-rsc's client-reference map; its group modules sit under it. */
62
+ export declare const CLIENT_REFERENCES_MODULE_ID = "\0virtual:vite-rsc/client-references";
61
63
  /**
62
64
  * Build-end group report under `DEBUG=rango:chunks`: one line per client
63
65
  * reference group with its client-reference count and the size of the group's
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Code-unit order, the same on every machine. Generated modules and the cache
3
+ * version inputs are sorted with it: `localeCompare` depends on the build
4
+ * machine's ICU data, and build output has to be byte-identical across machines
5
+ * (discovery/build-versions.ts hashes it).
6
+ */
7
+ export declare function compareStrings(a: string, b: string): number;
@@ -3,4 +3,12 @@ export declare function isInstalledFromNpm(): boolean;
3
3
  export declare function isWorkspaceDevelopment(): boolean;
4
4
  export declare function getExcludeDeps(): string[];
5
5
  export declare function getPackageAliases(): Record<string, string>;
6
+ /**
7
+ * @vitejs/plugin-rsc puts these vendor specifiers in `optimizeDeps.include`,
8
+ * and Vite resolves them from the app root, where pnpm's strict layout does
9
+ * not link the plugin unless the app lists it (#1050). Aliased to the copy
10
+ * the router resolves, which therefore also wins over an app's own
11
+ * @vitejs/plugin-rsc. Must hold every vendor entry the plugin includes:
12
+ * optimize-deps-vendor-resolution.test.ts checks the resolved config.
13
+ */
6
14
  export declare function getVendorAliases(): Record<string, string>;
@@ -18,6 +18,8 @@ export declare function notifyOnError(registry: Map<string, any>, error: unknown
18
18
  * URL / handler name for the log line; `elapsed` is the per-entry duration string.
19
19
  */
20
20
  export declare function resolvePrerenderError(registry: Map<string, any>, error: any, onError: "fail" | "warn", label: string, elapsed: string, phase: "prerender" | "static", routeKey?: string, pathname?: string): void;
21
+ /** Build scratch space, relative to the project root. Never shipped. */
22
+ export declare const RANGO_BUILD_DIR = "node_modules/.rangojs-router-build";
21
23
  export declare function resetStagedBuildAssets(projectRoot: string): void;
22
24
  /**
23
25
  * Write one content-hashed `export default <value>;` asset module into `dir`