@rangojs/router 0.0.0-experimental.13 → 0.0.0-experimental.135c6902
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/AGENTS.md +9 -0
- package/README.md +884 -4
- package/dist/__internal.d.ts +83 -0
- package/dist/__internal.d.ts.map +1 -0
- package/dist/__internal.js +19 -0
- package/dist/__internal.js.map +1 -0
- package/dist/__mocks__/version.d.ts +7 -0
- package/dist/__mocks__/version.d.ts.map +1 -0
- package/dist/__mocks__/version.js +7 -0
- package/dist/__mocks__/version.js.map +1 -0
- package/dist/__tests__/client-href.test.d.ts +2 -0
- package/dist/__tests__/client-href.test.d.ts.map +1 -0
- package/dist/__tests__/client-href.test.js +74 -0
- package/dist/__tests__/client-href.test.js.map +1 -0
- package/dist/__tests__/component-utils.test.d.ts +2 -0
- package/dist/__tests__/component-utils.test.d.ts.map +1 -0
- package/dist/__tests__/component-utils.test.js +51 -0
- package/dist/__tests__/component-utils.test.js.map +1 -0
- package/dist/__tests__/event-controller.test.d.ts +2 -0
- package/dist/__tests__/event-controller.test.d.ts.map +1 -0
- package/dist/__tests__/event-controller.test.js +538 -0
- package/dist/__tests__/event-controller.test.js.map +1 -0
- package/dist/__tests__/helpers/route-tree.d.ts +118 -0
- package/dist/__tests__/helpers/route-tree.d.ts.map +1 -0
- package/dist/__tests__/helpers/route-tree.js +374 -0
- package/dist/__tests__/helpers/route-tree.js.map +1 -0
- package/dist/__tests__/match-result.test.d.ts +2 -0
- package/dist/__tests__/match-result.test.d.ts.map +1 -0
- package/dist/__tests__/match-result.test.js +154 -0
- package/dist/__tests__/match-result.test.js.map +1 -0
- package/dist/__tests__/navigation-store.test.d.ts +2 -0
- package/dist/__tests__/navigation-store.test.d.ts.map +1 -0
- package/dist/__tests__/navigation-store.test.js +440 -0
- package/dist/__tests__/navigation-store.test.js.map +1 -0
- package/dist/__tests__/partial-update.test.d.ts +2 -0
- package/dist/__tests__/partial-update.test.d.ts.map +1 -0
- package/dist/__tests__/partial-update.test.js +1009 -0
- package/dist/__tests__/partial-update.test.js.map +1 -0
- package/dist/__tests__/reverse-types.test.d.ts +8 -0
- package/dist/__tests__/reverse-types.test.d.ts.map +1 -0
- package/dist/__tests__/reverse-types.test.js +656 -0
- package/dist/__tests__/reverse-types.test.js.map +1 -0
- package/dist/__tests__/route-definition.test.d.ts +2 -0
- package/dist/__tests__/route-definition.test.d.ts.map +1 -0
- package/dist/__tests__/route-definition.test.js +55 -0
- package/dist/__tests__/route-definition.test.js.map +1 -0
- package/dist/__tests__/router-helpers.test.d.ts +2 -0
- package/dist/__tests__/router-helpers.test.d.ts.map +1 -0
- package/dist/__tests__/router-helpers.test.js +377 -0
- package/dist/__tests__/router-helpers.test.js.map +1 -0
- package/dist/__tests__/router-integration-2.test.d.ts +2 -0
- package/dist/__tests__/router-integration-2.test.d.ts.map +1 -0
- package/dist/__tests__/router-integration-2.test.js +426 -0
- package/dist/__tests__/router-integration-2.test.js.map +1 -0
- package/dist/__tests__/router-integration.test.d.ts +2 -0
- package/dist/__tests__/router-integration.test.d.ts.map +1 -0
- package/dist/__tests__/router-integration.test.js +1051 -0
- package/dist/__tests__/router-integration.test.js.map +1 -0
- package/dist/__tests__/search-params.test.d.ts +5 -0
- package/dist/__tests__/search-params.test.d.ts.map +1 -0
- package/dist/__tests__/search-params.test.js +306 -0
- package/dist/__tests__/search-params.test.js.map +1 -0
- package/dist/__tests__/segment-system.test.d.ts +2 -0
- package/dist/__tests__/segment-system.test.d.ts.map +1 -0
- package/dist/__tests__/segment-system.test.js +627 -0
- package/dist/__tests__/segment-system.test.js.map +1 -0
- package/dist/__tests__/static-handler-types.test.d.ts +8 -0
- package/dist/__tests__/static-handler-types.test.d.ts.map +1 -0
- package/dist/__tests__/static-handler-types.test.js +63 -0
- package/dist/__tests__/static-handler-types.test.js.map +1 -0
- package/dist/__tests__/urls.test.d.ts +2 -0
- package/dist/__tests__/urls.test.d.ts.map +1 -0
- package/dist/__tests__/urls.test.js +421 -0
- package/dist/__tests__/urls.test.js.map +1 -0
- package/dist/__tests__/use-mount.test.d.ts +2 -0
- package/dist/__tests__/use-mount.test.d.ts.map +1 -0
- package/dist/__tests__/use-mount.test.js +35 -0
- package/dist/__tests__/use-mount.test.js.map +1 -0
- package/dist/bin/rango.d.ts +2 -0
- package/dist/bin/rango.d.ts.map +1 -0
- package/dist/bin/rango.js +1531 -212
- package/dist/bin/rango.js.map +1 -0
- package/dist/browser/event-controller.d.ts +191 -0
- package/dist/browser/event-controller.d.ts.map +1 -0
- package/dist/browser/event-controller.js +559 -0
- package/dist/browser/event-controller.js.map +1 -0
- package/dist/browser/index.d.ts +2 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +14 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/link-interceptor.d.ts +38 -0
- package/dist/browser/link-interceptor.d.ts.map +1 -0
- package/dist/browser/link-interceptor.js +99 -0
- package/dist/browser/link-interceptor.js.map +1 -0
- package/dist/browser/logging.d.ts +10 -0
- package/dist/browser/logging.d.ts.map +1 -0
- package/dist/browser/logging.js +29 -0
- package/dist/browser/logging.js.map +1 -0
- package/dist/browser/lru-cache.d.ts +17 -0
- package/dist/browser/lru-cache.d.ts.map +1 -0
- package/dist/browser/lru-cache.js +50 -0
- package/dist/browser/lru-cache.js.map +1 -0
- package/dist/browser/merge-segment-loaders.d.ts +39 -0
- package/dist/browser/merge-segment-loaders.d.ts.map +1 -0
- package/dist/browser/merge-segment-loaders.js +102 -0
- package/dist/browser/merge-segment-loaders.js.map +1 -0
- package/dist/browser/navigation-bridge.d.ts +102 -0
- package/dist/browser/navigation-bridge.d.ts.map +1 -0
- package/dist/browser/navigation-bridge.js +708 -0
- package/dist/browser/navigation-bridge.js.map +1 -0
- package/dist/browser/navigation-client.d.ts +25 -0
- package/dist/browser/navigation-client.d.ts.map +1 -0
- package/dist/browser/navigation-client.js +157 -0
- package/dist/browser/navigation-client.js.map +1 -0
- package/dist/browser/navigation-store.d.ts +101 -0
- package/dist/browser/navigation-store.d.ts.map +1 -0
- package/dist/browser/navigation-store.js +625 -0
- package/dist/browser/navigation-store.js.map +1 -0
- package/dist/browser/partial-update.d.ts +75 -0
- package/dist/browser/partial-update.d.ts.map +1 -0
- package/dist/browser/partial-update.js +426 -0
- package/dist/browser/partial-update.js.map +1 -0
- package/dist/browser/react/Link.d.ts +86 -0
- package/dist/browser/react/Link.d.ts.map +1 -0
- package/dist/browser/react/Link.js +128 -0
- package/dist/browser/react/Link.js.map +1 -0
- package/dist/browser/react/NavigationProvider.d.ts +63 -0
- package/dist/browser/react/NavigationProvider.d.ts.map +1 -0
- package/dist/browser/react/NavigationProvider.js +216 -0
- package/dist/browser/react/NavigationProvider.js.map +1 -0
- package/dist/browser/react/ScrollRestoration.d.ts +75 -0
- package/dist/browser/react/ScrollRestoration.d.ts.map +1 -0
- package/dist/browser/react/ScrollRestoration.js +57 -0
- package/dist/browser/react/ScrollRestoration.js.map +1 -0
- package/dist/browser/react/context.d.ts +46 -0
- package/dist/browser/react/context.d.ts.map +1 -0
- package/dist/browser/react/context.js +10 -0
- package/dist/browser/react/context.js.map +1 -0
- package/dist/browser/react/index.d.ts +11 -0
- package/dist/browser/react/index.d.ts.map +1 -0
- package/dist/browser/react/index.js +22 -0
- package/dist/browser/react/index.js.map +1 -0
- package/dist/browser/react/location-state-shared.d.ts +63 -0
- package/dist/browser/react/location-state-shared.d.ts.map +1 -0
- package/dist/browser/react/location-state-shared.js +81 -0
- package/dist/browser/react/location-state-shared.js.map +1 -0
- package/dist/browser/react/location-state.d.ts +23 -0
- package/dist/browser/react/location-state.d.ts.map +1 -0
- package/dist/browser/react/location-state.js +29 -0
- package/dist/browser/react/location-state.js.map +1 -0
- package/dist/browser/react/mount-context.d.ts +24 -0
- package/dist/browser/react/mount-context.d.ts.map +1 -0
- package/dist/browser/react/mount-context.js +24 -0
- package/dist/browser/react/mount-context.js.map +1 -0
- package/dist/browser/react/use-action.d.ts +64 -0
- package/dist/browser/react/use-action.d.ts.map +1 -0
- package/dist/browser/react/use-action.js +134 -0
- package/dist/browser/react/use-action.js.map +1 -0
- package/dist/browser/react/use-client-cache.d.ts +41 -0
- package/dist/browser/react/use-client-cache.d.ts.map +1 -0
- package/dist/browser/react/use-client-cache.js +39 -0
- package/dist/browser/react/use-client-cache.js.map +1 -0
- package/dist/browser/react/use-handle.d.ts +31 -0
- package/dist/browser/react/use-handle.d.ts.map +1 -0
- package/dist/browser/react/use-handle.js +144 -0
- package/dist/browser/react/use-handle.js.map +1 -0
- package/dist/browser/react/use-href.d.ts +33 -0
- package/dist/browser/react/use-href.d.ts.map +1 -0
- package/dist/browser/react/use-href.js +39 -0
- package/dist/browser/react/use-href.js.map +1 -0
- package/dist/browser/react/use-link-status.d.ts +37 -0
- package/dist/browser/react/use-link-status.d.ts.map +1 -0
- package/dist/browser/react/use-link-status.js +99 -0
- package/dist/browser/react/use-link-status.js.map +1 -0
- package/dist/browser/react/use-mount.d.ts +25 -0
- package/dist/browser/react/use-mount.d.ts.map +1 -0
- package/dist/browser/react/use-mount.js +30 -0
- package/dist/browser/react/use-mount.js.map +1 -0
- package/dist/browser/react/use-navigation.d.ts +27 -0
- package/dist/browser/react/use-navigation.d.ts.map +1 -0
- package/dist/browser/react/use-navigation.js +87 -0
- package/dist/browser/react/use-navigation.js.map +1 -0
- package/dist/browser/react/use-segments.d.ts +38 -0
- package/dist/browser/react/use-segments.d.ts.map +1 -0
- package/dist/browser/react/use-segments.js +130 -0
- package/dist/browser/react/use-segments.js.map +1 -0
- package/dist/browser/request-controller.d.ts +26 -0
- package/dist/browser/request-controller.d.ts.map +1 -0
- package/dist/browser/request-controller.js +147 -0
- package/dist/browser/request-controller.js.map +1 -0
- package/dist/browser/rsc-router.d.ts +129 -0
- package/dist/browser/rsc-router.d.ts.map +1 -0
- package/dist/browser/rsc-router.js +195 -0
- package/dist/browser/rsc-router.js.map +1 -0
- package/dist/browser/scroll-restoration.d.ts +93 -0
- package/dist/browser/scroll-restoration.d.ts.map +1 -0
- package/dist/browser/scroll-restoration.js +321 -0
- package/dist/browser/scroll-restoration.js.map +1 -0
- package/dist/browser/segment-structure-assert.d.ts +17 -0
- package/dist/browser/segment-structure-assert.d.ts.map +1 -0
- package/dist/browser/segment-structure-assert.js +59 -0
- package/dist/browser/segment-structure-assert.js.map +1 -0
- package/dist/browser/server-action-bridge.d.ts +26 -0
- package/dist/browser/server-action-bridge.d.ts.map +1 -0
- package/dist/browser/server-action-bridge.js +668 -0
- package/dist/browser/server-action-bridge.js.map +1 -0
- package/dist/browser/shallow.d.ts +12 -0
- package/dist/browser/shallow.d.ts.map +1 -0
- package/dist/browser/shallow.js +34 -0
- package/dist/browser/shallow.js.map +1 -0
- package/dist/browser/types.d.ts +369 -0
- package/dist/browser/types.d.ts.map +1 -0
- package/dist/browser/types.js +2 -0
- package/dist/browser/types.js.map +1 -0
- package/dist/build/__tests__/generate-cli.test.d.ts +2 -0
- package/dist/build/__tests__/generate-cli.test.d.ts.map +1 -0
- package/dist/build/__tests__/generate-cli.test.js +237 -0
- package/dist/build/__tests__/generate-cli.test.js.map +1 -0
- package/dist/build/__tests__/generate-manifest.test.d.ts +2 -0
- package/dist/build/__tests__/generate-manifest.test.d.ts.map +1 -0
- package/dist/build/__tests__/generate-manifest.test.js +119 -0
- package/dist/build/__tests__/generate-manifest.test.js.map +1 -0
- package/dist/build/__tests__/generate-route-types.test.d.ts +2 -0
- package/dist/build/__tests__/generate-route-types.test.d.ts.map +1 -0
- package/dist/build/__tests__/generate-route-types.test.js +620 -0
- package/dist/build/__tests__/generate-route-types.test.js.map +1 -0
- package/dist/build/__tests__/per-router-manifest.test.d.ts +2 -0
- package/dist/build/__tests__/per-router-manifest.test.d.ts.map +1 -0
- package/dist/build/__tests__/per-router-manifest.test.js +308 -0
- package/dist/build/__tests__/per-router-manifest.test.js.map +1 -0
- package/dist/build/generate-manifest.d.ts +81 -0
- package/dist/build/generate-manifest.d.ts.map +1 -0
- package/dist/build/generate-manifest.js +276 -0
- package/dist/build/generate-manifest.js.map +1 -0
- package/dist/build/generate-route-types.d.ts +115 -0
- package/dist/build/generate-route-types.d.ts.map +1 -0
- package/dist/build/generate-route-types.js +740 -0
- package/dist/build/generate-route-types.js.map +1 -0
- package/dist/build/index.d.ts +21 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +21 -0
- package/dist/build/index.js.map +1 -0
- package/dist/build/route-trie.d.ts +71 -0
- package/dist/build/route-trie.d.ts.map +1 -0
- package/dist/build/route-trie.js +175 -0
- package/dist/build/route-trie.js.map +1 -0
- package/dist/cache/__tests__/cache-scope.test.d.ts +2 -0
- package/dist/cache/__tests__/cache-scope.test.d.ts.map +1 -0
- package/dist/cache/__tests__/cache-scope.test.js +208 -0
- package/dist/cache/__tests__/cache-scope.test.js.map +1 -0
- package/dist/cache/__tests__/document-cache.test.d.ts +2 -0
- package/dist/cache/__tests__/document-cache.test.d.ts.map +1 -0
- package/dist/cache/__tests__/document-cache.test.js +345 -0
- package/dist/cache/__tests__/document-cache.test.js.map +1 -0
- package/dist/cache/__tests__/memory-segment-store.test.d.ts +2 -0
- package/dist/cache/__tests__/memory-segment-store.test.d.ts.map +1 -0
- package/dist/cache/__tests__/memory-segment-store.test.js +425 -0
- package/dist/cache/__tests__/memory-segment-store.test.js.map +1 -0
- package/dist/cache/__tests__/memory-store.test.d.ts +2 -0
- package/dist/cache/__tests__/memory-store.test.d.ts.map +1 -0
- package/dist/cache/__tests__/memory-store.test.js +367 -0
- package/dist/cache/__tests__/memory-store.test.js.map +1 -0
- package/dist/cache/cache-scope.d.ts +102 -0
- package/dist/cache/cache-scope.d.ts.map +1 -0
- package/dist/cache/cache-scope.js +440 -0
- package/dist/cache/cache-scope.js.map +1 -0
- package/dist/cache/cf/__tests__/cf-cache-store.test.d.ts +2 -0
- package/dist/cache/cf/__tests__/cf-cache-store.test.d.ts.map +1 -0
- package/dist/cache/cf/__tests__/cf-cache-store.test.js +330 -0
- package/dist/cache/cf/__tests__/cf-cache-store.test.js.map +1 -0
- package/dist/cache/cf/cf-cache-store.d.ts +165 -0
- package/dist/cache/cf/cf-cache-store.d.ts.map +1 -0
- package/dist/cache/cf/cf-cache-store.js +242 -0
- package/dist/cache/cf/cf-cache-store.js.map +1 -0
- package/dist/cache/cf/index.d.ts +14 -0
- package/dist/cache/cf/index.d.ts.map +1 -0
- package/dist/cache/cf/index.js +17 -0
- package/dist/cache/cf/index.js.map +1 -0
- package/dist/cache/document-cache.d.ts +64 -0
- package/dist/cache/document-cache.d.ts.map +1 -0
- package/dist/cache/document-cache.js +228 -0
- package/dist/cache/document-cache.js.map +1 -0
- package/dist/cache/index.d.ts +19 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +21 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/memory-segment-store.d.ts +110 -0
- package/dist/cache/memory-segment-store.d.ts.map +1 -0
- package/dist/cache/memory-segment-store.js +117 -0
- package/dist/cache/memory-segment-store.js.map +1 -0
- package/dist/cache/memory-store.d.ts +41 -0
- package/dist/cache/memory-store.d.ts.map +1 -0
- package/dist/cache/memory-store.js +191 -0
- package/dist/cache/memory-store.js.map +1 -0
- package/dist/cache/types.d.ts +317 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/cache/types.js +12 -0
- package/dist/cache/types.js.map +1 -0
- package/dist/client.d.ts +248 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +367 -0
- package/dist/client.js.map +1 -0
- package/dist/client.rsc.d.ts +26 -0
- package/dist/client.rsc.d.ts.map +1 -0
- package/dist/client.rsc.js +46 -0
- package/dist/client.rsc.js.map +1 -0
- package/dist/component-utils.d.ts +36 -0
- package/dist/component-utils.d.ts.map +1 -0
- package/dist/component-utils.js +61 -0
- package/dist/component-utils.js.map +1 -0
- package/dist/components/DefaultDocument.d.ts +13 -0
- package/dist/components/DefaultDocument.d.ts.map +1 -0
- package/dist/components/DefaultDocument.js +15 -0
- package/dist/components/DefaultDocument.js.map +1 -0
- package/dist/debug.d.ts +58 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +157 -0
- package/dist/debug.js.map +1 -0
- package/dist/default-error-boundary.d.ts +11 -0
- package/dist/default-error-boundary.d.ts.map +1 -0
- package/dist/default-error-boundary.js +45 -0
- package/dist/default-error-boundary.js.map +1 -0
- package/dist/deps/browser.d.ts +2 -0
- package/dist/deps/browser.d.ts.map +1 -0
- package/dist/deps/browser.js +3 -0
- package/dist/deps/browser.js.map +1 -0
- package/dist/deps/html-stream-client.d.ts +2 -0
- package/dist/deps/html-stream-client.d.ts.map +1 -0
- package/dist/deps/html-stream-client.js +3 -0
- package/dist/deps/html-stream-client.js.map +1 -0
- package/dist/deps/html-stream-server.d.ts +2 -0
- package/dist/deps/html-stream-server.d.ts.map +1 -0
- package/dist/deps/html-stream-server.js +3 -0
- package/dist/deps/html-stream-server.js.map +1 -0
- package/dist/deps/rsc.d.ts +2 -0
- package/dist/deps/rsc.d.ts.map +1 -0
- package/dist/deps/rsc.js +4 -0
- package/dist/deps/rsc.js.map +1 -0
- package/dist/deps/ssr.d.ts +2 -0
- package/dist/deps/ssr.d.ts.map +1 -0
- package/dist/deps/ssr.js +3 -0
- package/dist/deps/ssr.js.map +1 -0
- package/dist/errors.d.ts +174 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +241 -0
- package/dist/errors.js.map +1 -0
- package/dist/handle.d.ts +78 -0
- package/dist/handle.d.ts.map +1 -0
- package/dist/handle.js +82 -0
- package/dist/handle.js.map +1 -0
- package/dist/handles/MetaTags.d.ts +14 -0
- package/dist/handles/MetaTags.d.ts.map +1 -0
- package/dist/handles/MetaTags.js +136 -0
- package/dist/handles/MetaTags.js.map +1 -0
- package/dist/handles/index.d.ts +6 -0
- package/dist/handles/index.d.ts.map +1 -0
- package/dist/handles/index.js +6 -0
- package/dist/handles/index.js.map +1 -0
- package/dist/handles/meta.d.ts +39 -0
- package/dist/handles/meta.d.ts.map +1 -0
- package/dist/handles/meta.js +202 -0
- package/dist/handles/meta.js.map +1 -0
- package/dist/host/__tests__/errors.test.d.ts +2 -0
- package/dist/host/__tests__/errors.test.d.ts.map +1 -0
- package/dist/host/__tests__/errors.test.js +76 -0
- package/dist/host/__tests__/errors.test.js.map +1 -0
- package/dist/host/__tests__/pattern-comprehensive.test.d.ts +2 -0
- package/dist/host/__tests__/pattern-comprehensive.test.d.ts.map +1 -0
- package/dist/host/__tests__/pattern-comprehensive.test.js +732 -0
- package/dist/host/__tests__/pattern-comprehensive.test.js.map +1 -0
- package/dist/host/__tests__/pattern-matcher.test.d.ts +2 -0
- package/dist/host/__tests__/pattern-matcher.test.d.ts.map +1 -0
- package/dist/host/__tests__/pattern-matcher.test.js +251 -0
- package/dist/host/__tests__/pattern-matcher.test.js.map +1 -0
- package/dist/host/__tests__/router.test.d.ts +2 -0
- package/dist/host/__tests__/router.test.d.ts.map +1 -0
- package/dist/host/__tests__/router.test.js +241 -0
- package/dist/host/__tests__/router.test.js.map +1 -0
- package/dist/host/__tests__/testing.test.d.ts +2 -0
- package/dist/host/__tests__/testing.test.d.ts.map +1 -0
- package/dist/host/__tests__/testing.test.js +64 -0
- package/dist/host/__tests__/testing.test.js.map +1 -0
- package/dist/host/__tests__/utils.test.d.ts +2 -0
- package/dist/host/__tests__/utils.test.d.ts.map +1 -0
- package/dist/host/__tests__/utils.test.js +29 -0
- package/dist/host/__tests__/utils.test.js.map +1 -0
- package/dist/host/cookie-handler.d.ts +34 -0
- package/dist/host/cookie-handler.d.ts.map +1 -0
- package/dist/host/cookie-handler.js +124 -0
- package/dist/host/cookie-handler.js.map +1 -0
- package/dist/host/errors.d.ts +56 -0
- package/dist/host/errors.d.ts.map +1 -0
- package/dist/host/errors.js +79 -0
- package/dist/host/errors.js.map +1 -0
- package/dist/host/index.d.ts +29 -0
- package/dist/host/index.d.ts.map +1 -0
- package/dist/host/index.js +32 -0
- package/dist/host/index.js.map +1 -0
- package/dist/host/pattern-matcher.d.ts +36 -0
- package/dist/host/pattern-matcher.d.ts.map +1 -0
- package/dist/host/pattern-matcher.js +172 -0
- package/dist/host/pattern-matcher.js.map +1 -0
- package/dist/host/router.d.ts +26 -0
- package/dist/host/router.d.ts.map +1 -0
- package/dist/host/router.js +218 -0
- package/dist/host/router.js.map +1 -0
- package/dist/host/testing.d.ts +36 -0
- package/dist/host/testing.d.ts.map +1 -0
- package/dist/host/testing.js +55 -0
- package/dist/host/testing.js.map +1 -0
- package/dist/host/types.d.ts +115 -0
- package/dist/host/types.d.ts.map +1 -0
- package/dist/host/types.js +7 -0
- package/dist/host/types.js.map +1 -0
- package/dist/host/utils.d.ts +21 -0
- package/dist/host/utils.d.ts.map +1 -0
- package/dist/host/utils.js +23 -0
- package/dist/host/utils.js.map +1 -0
- package/dist/href-client.d.ts +131 -0
- package/dist/href-client.d.ts.map +1 -0
- package/dist/href-client.js +64 -0
- package/dist/href-client.js.map +1 -0
- package/{src/href-context.ts → dist/href-context.d.ts} +7 -11
- package/dist/href-context.d.ts.map +1 -0
- package/dist/href-context.js +21 -0
- package/dist/href-context.js.map +1 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -0
- package/dist/index.rsc.d.ts +32 -0
- package/dist/index.rsc.d.ts.map +1 -0
- package/dist/index.rsc.js +40 -0
- package/dist/index.rsc.js.map +1 -0
- package/dist/internal-debug.d.ts +2 -0
- package/dist/internal-debug.d.ts.map +1 -0
- package/dist/internal-debug.js +5 -0
- package/dist/internal-debug.js.map +1 -0
- package/dist/loader.d.ts +14 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +20 -0
- package/dist/loader.js.map +1 -0
- package/dist/loader.rsc.d.ts +19 -0
- package/dist/loader.rsc.d.ts.map +1 -0
- package/dist/loader.rsc.js +99 -0
- package/dist/loader.rsc.js.map +1 -0
- package/dist/network-error-thrower.d.ts +17 -0
- package/dist/network-error-thrower.d.ts.map +1 -0
- package/dist/network-error-thrower.js +14 -0
- package/dist/network-error-thrower.js.map +1 -0
- package/dist/outlet-context.d.ts +13 -0
- package/dist/outlet-context.d.ts.map +1 -0
- package/dist/outlet-context.js +3 -0
- package/dist/outlet-context.js.map +1 -0
- package/dist/prerender/__tests__/param-hash.test.d.ts +2 -0
- package/dist/prerender/__tests__/param-hash.test.d.ts.map +1 -0
- package/dist/prerender/__tests__/param-hash.test.js +148 -0
- package/dist/prerender/__tests__/param-hash.test.js.map +1 -0
- package/dist/prerender/param-hash.d.ts +16 -0
- package/dist/prerender/param-hash.d.ts.map +1 -0
- package/dist/prerender/param-hash.js +36 -0
- package/dist/prerender/param-hash.js.map +1 -0
- package/dist/prerender/store.d.ts +38 -0
- package/dist/prerender/store.d.ts.map +1 -0
- package/dist/prerender/store.js +61 -0
- package/dist/prerender/store.js.map +1 -0
- package/dist/prerender.d.ts +66 -0
- package/dist/prerender.d.ts.map +1 -0
- package/dist/prerender.js +57 -0
- package/dist/prerender.js.map +1 -0
- package/dist/reverse.d.ts +196 -0
- package/dist/reverse.d.ts.map +1 -0
- package/dist/reverse.js +78 -0
- package/dist/reverse.js.map +1 -0
- package/dist/root-error-boundary.d.ts +33 -0
- package/dist/root-error-boundary.d.ts.map +1 -0
- package/dist/root-error-boundary.js +165 -0
- package/dist/root-error-boundary.js.map +1 -0
- package/dist/route-content-wrapper.d.ts +46 -0
- package/dist/route-content-wrapper.d.ts.map +1 -0
- package/dist/route-content-wrapper.js +77 -0
- package/dist/route-content-wrapper.js.map +1 -0
- package/dist/route-definition.d.ts +421 -0
- package/dist/route-definition.d.ts.map +1 -0
- package/dist/route-definition.js +868 -0
- package/dist/route-definition.js.map +1 -0
- package/dist/route-map-builder.d.ts +155 -0
- package/dist/route-map-builder.d.ts.map +1 -0
- package/dist/route-map-builder.js +237 -0
- package/dist/route-map-builder.js.map +1 -0
- package/dist/route-types.d.ts +165 -0
- package/dist/route-types.d.ts.map +1 -0
- package/dist/route-types.js +7 -0
- package/dist/route-types.js.map +1 -0
- package/dist/router/__tests__/handler-context.test.d.ts +2 -0
- package/dist/router/__tests__/handler-context.test.d.ts.map +1 -0
- package/dist/router/__tests__/handler-context.test.js +65 -0
- package/dist/router/__tests__/handler-context.test.js.map +1 -0
- package/dist/router/__tests__/loader-cycle-detection.test.d.ts +2 -0
- package/dist/router/__tests__/loader-cycle-detection.test.d.ts.map +1 -0
- package/dist/router/__tests__/loader-cycle-detection.test.js +221 -0
- package/dist/router/__tests__/loader-cycle-detection.test.js.map +1 -0
- package/dist/router/__tests__/match-context.test.d.ts +2 -0
- package/dist/router/__tests__/match-context.test.d.ts.map +1 -0
- package/dist/router/__tests__/match-context.test.js +92 -0
- package/dist/router/__tests__/match-context.test.js.map +1 -0
- package/dist/router/__tests__/match-pipelines.test.d.ts +2 -0
- package/dist/router/__tests__/match-pipelines.test.d.ts.map +1 -0
- package/dist/router/__tests__/match-pipelines.test.js +417 -0
- package/dist/router/__tests__/match-pipelines.test.js.map +1 -0
- package/dist/router/__tests__/match-result.test.d.ts +2 -0
- package/dist/router/__tests__/match-result.test.d.ts.map +1 -0
- package/dist/router/__tests__/match-result.test.js +457 -0
- package/dist/router/__tests__/match-result.test.js.map +1 -0
- package/dist/router/__tests__/on-error.test.d.ts +2 -0
- package/dist/router/__tests__/on-error.test.d.ts.map +1 -0
- package/dist/router/__tests__/on-error.test.js +678 -0
- package/dist/router/__tests__/on-error.test.js.map +1 -0
- package/dist/router/__tests__/pattern-matching.test.d.ts +2 -0
- package/dist/router/__tests__/pattern-matching.test.d.ts.map +1 -0
- package/dist/router/__tests__/pattern-matching.test.js +629 -0
- package/dist/router/__tests__/pattern-matching.test.js.map +1 -0
- package/dist/router/__tests__/segment-resolution-parallel-loading.test.d.ts +2 -0
- package/dist/router/__tests__/segment-resolution-parallel-loading.test.d.ts.map +1 -0
- package/dist/router/__tests__/segment-resolution-parallel-loading.test.js +155 -0
- package/dist/router/__tests__/segment-resolution-parallel-loading.test.js.map +1 -0
- package/dist/router/error-handling.d.ts +77 -0
- package/dist/router/error-handling.d.ts.map +1 -0
- package/dist/router/error-handling.js +202 -0
- package/dist/router/error-handling.js.map +1 -0
- package/dist/router/handler-context.d.ts +20 -0
- package/dist/router/handler-context.d.ts.map +1 -0
- package/dist/router/handler-context.js +198 -0
- package/dist/router/handler-context.js.map +1 -0
- package/dist/router/intercept-resolution.d.ts +66 -0
- package/dist/router/intercept-resolution.d.ts.map +1 -0
- package/dist/router/intercept-resolution.js +246 -0
- package/dist/router/intercept-resolution.js.map +1 -0
- package/dist/router/loader-resolution.d.ts +64 -0
- package/dist/router/loader-resolution.d.ts.map +1 -0
- package/dist/router/loader-resolution.js +284 -0
- package/dist/router/loader-resolution.js.map +1 -0
- package/dist/router/logging.d.ts +15 -0
- package/dist/router/logging.d.ts.map +1 -0
- package/dist/router/logging.js +99 -0
- package/dist/router/logging.js.map +1 -0
- package/dist/router/manifest.d.ts +22 -0
- package/dist/router/manifest.d.ts.map +1 -0
- package/dist/router/manifest.js +181 -0
- package/dist/router/manifest.js.map +1 -0
- package/dist/router/match-api.d.ts +35 -0
- package/dist/router/match-api.d.ts.map +1 -0
- package/dist/router/match-api.js +406 -0
- package/dist/router/match-api.js.map +1 -0
- package/dist/router/match-context.d.ts +206 -0
- package/dist/router/match-context.d.ts.map +1 -0
- package/dist/router/match-context.js +17 -0
- package/dist/router/match-context.js.map +1 -0
- package/dist/router/match-middleware/background-revalidation.d.ts +127 -0
- package/dist/router/match-middleware/background-revalidation.d.ts.map +1 -0
- package/dist/router/match-middleware/background-revalidation.js +75 -0
- package/dist/router/match-middleware/background-revalidation.js.map +1 -0
- package/dist/router/match-middleware/cache-lookup.d.ts +112 -0
- package/dist/router/match-middleware/cache-lookup.d.ts.map +1 -0
- package/dist/router/match-middleware/cache-lookup.js +257 -0
- package/dist/router/match-middleware/cache-lookup.js.map +1 -0
- package/dist/router/match-middleware/cache-store.d.ts +113 -0
- package/dist/router/match-middleware/cache-store.d.ts.map +1 -0
- package/dist/router/match-middleware/cache-store.js +108 -0
- package/dist/router/match-middleware/cache-store.js.map +1 -0
- package/dist/router/match-middleware/index.d.ts +81 -0
- package/dist/router/match-middleware/index.d.ts.map +1 -0
- package/dist/router/match-middleware/index.js +80 -0
- package/dist/router/match-middleware/index.js.map +1 -0
- package/dist/router/match-middleware/intercept-resolution.d.ts +117 -0
- package/dist/router/match-middleware/intercept-resolution.d.ts.map +1 -0
- package/dist/router/match-middleware/intercept-resolution.js +134 -0
- package/dist/router/match-middleware/intercept-resolution.js.map +1 -0
- package/dist/router/match-middleware/segment-resolution.d.ts +99 -0
- package/dist/router/match-middleware/segment-resolution.d.ts.map +1 -0
- package/dist/router/match-middleware/segment-resolution.js +53 -0
- package/dist/router/match-middleware/segment-resolution.js.map +1 -0
- package/dist/router/match-pipelines.d.ts +147 -0
- package/dist/router/match-pipelines.d.ts.map +1 -0
- package/dist/router/match-pipelines.js +82 -0
- package/dist/router/match-pipelines.js.map +1 -0
- package/dist/router/match-result.d.ts +126 -0
- package/dist/router/match-result.d.ts.map +1 -0
- package/dist/router/match-result.js +93 -0
- package/dist/router/match-result.js.map +1 -0
- package/dist/router/metrics.d.ts +20 -0
- package/dist/router/metrics.d.ts.map +1 -0
- package/dist/router/metrics.js +47 -0
- package/dist/router/metrics.js.map +1 -0
- package/dist/router/middleware.d.ts +249 -0
- package/dist/router/middleware.d.ts.map +1 -0
- package/dist/router/middleware.js +434 -0
- package/dist/router/middleware.js.map +1 -0
- package/dist/router/middleware.test.d.ts +2 -0
- package/dist/router/middleware.test.d.ts.map +1 -0
- package/dist/router/middleware.test.js +816 -0
- package/dist/router/middleware.test.js.map +1 -0
- package/dist/router/pattern-matching.d.ts +149 -0
- package/dist/router/pattern-matching.d.ts.map +1 -0
- package/dist/router/pattern-matching.js +349 -0
- package/dist/router/pattern-matching.js.map +1 -0
- package/dist/router/revalidation.d.ts +44 -0
- package/dist/router/revalidation.d.ts.map +1 -0
- package/dist/router/revalidation.js +147 -0
- package/dist/router/revalidation.js.map +1 -0
- package/dist/router/router-context.d.ts +135 -0
- package/dist/router/router-context.d.ts.map +1 -0
- package/dist/router/router-context.js +36 -0
- package/dist/router/router-context.js.map +1 -0
- package/dist/router/segment-resolution.d.ts +127 -0
- package/dist/router/segment-resolution.d.ts.map +1 -0
- package/dist/router/segment-resolution.js +919 -0
- package/dist/router/segment-resolution.js.map +1 -0
- package/dist/router/trie-matching.d.ts +40 -0
- package/dist/router/trie-matching.d.ts.map +1 -0
- package/dist/router/trie-matching.js +127 -0
- package/dist/router/trie-matching.js.map +1 -0
- package/dist/router/types.d.ts +136 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/router/types.js +7 -0
- package/dist/router/types.js.map +1 -0
- package/dist/router.d.ts +753 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.gen.d.ts +6 -0
- package/dist/router.gen.d.ts.map +1 -0
- package/dist/router.gen.js +6 -0
- package/dist/router.gen.js.map +1 -0
- package/dist/router.js +1304 -0
- package/dist/router.js.map +1 -0
- package/dist/rsc/__tests__/helpers.test.d.ts +2 -0
- package/dist/rsc/__tests__/helpers.test.d.ts.map +1 -0
- package/dist/rsc/__tests__/helpers.test.js +140 -0
- package/dist/rsc/__tests__/helpers.test.js.map +1 -0
- package/dist/rsc/handler.d.ts +45 -0
- package/dist/rsc/handler.d.ts.map +1 -0
- package/dist/rsc/handler.js +1172 -0
- package/dist/rsc/handler.js.map +1 -0
- package/dist/rsc/helpers.d.ts +16 -0
- package/dist/rsc/helpers.d.ts.map +1 -0
- package/dist/rsc/helpers.js +55 -0
- package/dist/rsc/helpers.js.map +1 -0
- package/dist/rsc/index.d.ts +22 -0
- package/dist/rsc/index.d.ts.map +1 -0
- package/dist/rsc/index.js +23 -0
- package/dist/rsc/index.js.map +1 -0
- package/dist/rsc/nonce.d.ts +9 -0
- package/dist/rsc/nonce.d.ts.map +1 -0
- package/dist/rsc/nonce.js +18 -0
- package/dist/rsc/nonce.js.map +1 -0
- package/dist/rsc/types.d.ts +206 -0
- package/dist/rsc/types.d.ts.map +1 -0
- package/dist/rsc/types.js +8 -0
- package/dist/rsc/types.js.map +1 -0
- package/dist/search-params.d.ts +103 -0
- package/dist/search-params.d.ts.map +1 -0
- package/dist/search-params.js +74 -0
- package/dist/search-params.js.map +1 -0
- package/dist/segment-system.d.ts +75 -0
- package/dist/segment-system.d.ts.map +1 -0
- package/dist/segment-system.js +336 -0
- package/dist/segment-system.js.map +1 -0
- package/dist/server/context.d.ts +245 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +197 -0
- package/dist/server/context.js.map +1 -0
- package/dist/server/fetchable-loader-store.d.ts +18 -0
- package/dist/server/fetchable-loader-store.d.ts.map +1 -0
- package/dist/server/fetchable-loader-store.js +18 -0
- package/dist/server/fetchable-loader-store.js.map +1 -0
- package/dist/server/handle-store.d.ts +85 -0
- package/dist/server/handle-store.d.ts.map +1 -0
- package/dist/server/handle-store.js +142 -0
- package/dist/server/handle-store.js.map +1 -0
- package/dist/server/loader-registry.d.ts +55 -0
- package/dist/server/loader-registry.d.ts.map +1 -0
- package/dist/server/loader-registry.js +132 -0
- package/dist/server/loader-registry.js.map +1 -0
- package/dist/server/request-context.d.ts +226 -0
- package/dist/server/request-context.d.ts.map +1 -0
- package/dist/server/request-context.js +290 -0
- package/dist/server/request-context.js.map +1 -0
- package/dist/server/root-layout.d.ts +4 -0
- package/dist/server/root-layout.d.ts.map +1 -0
- package/dist/server/root-layout.js +5 -0
- package/dist/server/root-layout.js.map +1 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +20 -0
- package/dist/server.js.map +1 -0
- package/dist/ssr/__tests__/ssr-handler.test.d.ts +2 -0
- package/dist/ssr/__tests__/ssr-handler.test.d.ts.map +1 -0
- package/dist/ssr/__tests__/ssr-handler.test.js +132 -0
- package/dist/ssr/__tests__/ssr-handler.test.js.map +1 -0
- package/dist/ssr/index.d.ts +98 -0
- package/dist/ssr/index.d.ts.map +1 -0
- package/dist/ssr/index.js +158 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/static-handler.d.ts +50 -0
- package/dist/static-handler.d.ts.map +1 -0
- package/dist/static-handler.gen.d.ts +5 -0
- package/dist/static-handler.gen.d.ts.map +1 -0
- package/dist/static-handler.gen.js +5 -0
- package/dist/static-handler.gen.js.map +1 -0
- package/dist/static-handler.js +29 -0
- package/dist/static-handler.js.map +1 -0
- package/dist/theme/ThemeProvider.d.ts +20 -0
- package/dist/theme/ThemeProvider.d.ts.map +1 -0
- package/dist/theme/ThemeProvider.js +240 -0
- package/dist/theme/ThemeProvider.js.map +1 -0
- package/dist/theme/ThemeScript.d.ts +48 -0
- package/dist/theme/ThemeScript.d.ts.map +1 -0
- package/dist/theme/ThemeScript.js +13 -0
- package/dist/theme/ThemeScript.js.map +1 -0
- package/dist/theme/__tests__/theme.test.d.ts +2 -0
- package/dist/theme/__tests__/theme.test.d.ts.map +1 -0
- package/dist/theme/__tests__/theme.test.js +103 -0
- package/dist/theme/__tests__/theme.test.js.map +1 -0
- package/dist/theme/constants.d.ts +29 -0
- package/dist/theme/constants.d.ts.map +1 -0
- package/dist/theme/constants.js +48 -0
- package/dist/theme/constants.js.map +1 -0
- package/dist/theme/index.d.ts +31 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +36 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/theme-context.d.ts +40 -0
- package/dist/theme/theme-context.d.ts.map +1 -0
- package/dist/theme/theme-context.js +60 -0
- package/dist/theme/theme-context.js.map +1 -0
- package/dist/theme/theme-script.d.ts +27 -0
- package/dist/theme/theme-script.d.ts.map +1 -0
- package/dist/theme/theme-script.js +147 -0
- package/dist/theme/theme-script.js.map +1 -0
- package/dist/theme/types.d.ts +163 -0
- package/dist/theme/types.d.ts.map +1 -0
- package/dist/theme/types.js +11 -0
- package/dist/theme/types.js.map +1 -0
- package/dist/theme/use-theme.d.ts +12 -0
- package/dist/theme/use-theme.d.ts.map +1 -0
- package/dist/theme/use-theme.js +40 -0
- package/dist/theme/use-theme.js.map +1 -0
- package/dist/types.d.ts +1479 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/dist/urls.d.ts +441 -0
- package/dist/urls.d.ts.map +1 -0
- package/dist/urls.gen.d.ts +8 -0
- package/dist/urls.gen.d.ts.map +1 -0
- package/dist/urls.gen.js +8 -0
- package/dist/urls.gen.js.map +1 -0
- package/dist/urls.js +443 -0
- package/dist/urls.js.map +1 -0
- package/dist/use-loader.d.ts +127 -0
- package/dist/use-loader.d.ts.map +1 -0
- package/dist/use-loader.js +237 -0
- package/dist/use-loader.js.map +1 -0
- package/dist/vite/__tests__/ast-handler-extract.test.d.ts +2 -0
- package/dist/vite/__tests__/ast-handler-extract.test.d.ts.map +1 -0
- package/dist/vite/__tests__/ast-handler-extract.test.js +294 -0
- package/dist/vite/__tests__/ast-handler-extract.test.js.map +1 -0
- package/dist/vite/__tests__/expose-id-utils.test.d.ts +2 -0
- package/dist/vite/__tests__/expose-id-utils.test.d.ts.map +1 -0
- package/dist/vite/__tests__/expose-id-utils.test.js +224 -0
- package/dist/vite/__tests__/expose-id-utils.test.js.map +1 -0
- package/dist/vite/__tests__/expose-internal-ids.test.d.ts +2 -0
- package/dist/vite/__tests__/expose-internal-ids.test.d.ts.map +1 -0
- package/dist/vite/__tests__/expose-internal-ids.test.js +647 -0
- package/dist/vite/__tests__/expose-internal-ids.test.js.map +1 -0
- package/dist/vite/__tests__/expose-router-id.test.d.ts +2 -0
- package/dist/vite/__tests__/expose-router-id.test.d.ts.map +1 -0
- package/dist/vite/__tests__/expose-router-id.test.js +39 -0
- package/dist/vite/__tests__/expose-router-id.test.js.map +1 -0
- package/dist/vite/ast-handler-extract.d.ts +49 -0
- package/dist/vite/ast-handler-extract.d.ts.map +1 -0
- package/dist/vite/ast-handler-extract.js +249 -0
- package/dist/vite/ast-handler-extract.js.map +1 -0
- package/dist/vite/expose-action-id.d.ts +19 -0
- package/dist/vite/expose-action-id.d.ts.map +1 -0
- package/dist/vite/expose-action-id.js +250 -0
- package/dist/vite/expose-action-id.js.map +1 -0
- package/dist/vite/expose-id-utils.d.ts +69 -0
- package/dist/vite/expose-id-utils.d.ts.map +1 -0
- package/dist/vite/expose-id-utils.js +289 -0
- package/dist/vite/expose-id-utils.js.map +1 -0
- package/dist/vite/expose-internal-ids.d.ts +22 -0
- package/dist/vite/expose-internal-ids.d.ts.map +1 -0
- package/dist/vite/expose-internal-ids.js +886 -0
- package/dist/vite/expose-internal-ids.js.map +1 -0
- package/dist/vite/index.d.ts +149 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +3995 -2489
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/package-resolution.d.ts +43 -0
- package/dist/vite/package-resolution.d.ts.map +1 -0
- package/dist/vite/package-resolution.js +112 -0
- package/dist/vite/package-resolution.js.map +1 -0
- package/dist/vite/virtual-entries.d.ts +25 -0
- package/dist/vite/virtual-entries.d.ts.map +1 -0
- package/{src/vite/virtual-entries.ts → dist/vite/virtual-entries.js} +12 -16
- package/dist/vite/virtual-entries.js.map +1 -0
- package/package.json +57 -52
- package/skills/breadcrumbs/SKILL.md +250 -0
- package/skills/cache-guide/SKILL.md +262 -0
- package/skills/caching/SKILL.md +85 -23
- package/skills/composability/SKILL.md +172 -0
- package/skills/debug-manifest/SKILL.md +12 -8
- package/skills/document-cache/SKILL.md +18 -16
- package/skills/fonts/SKILL.md +6 -4
- package/skills/hooks/SKILL.md +328 -70
- package/skills/host-router/SKILL.md +218 -0
- package/skills/intercept/SKILL.md +131 -8
- package/skills/layout/SKILL.md +100 -3
- package/skills/links/SKILL.md +62 -15
- package/skills/loader/SKILL.md +368 -42
- package/skills/middleware/SKILL.md +171 -34
- package/skills/mime-routes/SKILL.md +14 -10
- package/skills/parallel/SKILL.md +137 -1
- package/skills/prerender/SKILL.md +366 -28
- package/skills/rango/SKILL.md +85 -21
- package/skills/response-routes/SKILL.md +136 -83
- package/skills/route/SKILL.md +195 -21
- package/skills/router-setup/SKILL.md +123 -30
- package/skills/theme/SKILL.md +9 -8
- package/skills/typesafety/SKILL.md +240 -102
- package/skills/use-cache/SKILL.md +324 -0
- package/src/__internal.ts +102 -4
- package/src/bin/rango.ts +312 -15
- package/src/browser/action-coordinator.ts +97 -0
- package/src/browser/action-response-classifier.ts +99 -0
- package/src/browser/event-controller.ts +92 -64
- package/src/browser/history-state.ts +80 -0
- package/src/browser/intercept-utils.ts +52 -0
- package/src/browser/link-interceptor.ts +24 -4
- package/src/browser/logging.ts +11 -0
- package/src/browser/merge-segment-loaders.ts +20 -12
- package/src/browser/navigation-bridge.ts +266 -558
- package/src/browser/navigation-client.ts +132 -75
- package/src/browser/navigation-store.ts +33 -50
- package/src/browser/navigation-transaction.ts +297 -0
- package/src/browser/network-error-handler.ts +61 -0
- package/src/browser/partial-update.ts +292 -309
- package/src/browser/prefetch/cache.ts +206 -0
- package/src/browser/prefetch/fetch.ts +144 -0
- package/src/browser/prefetch/observer.ts +65 -0
- package/src/browser/prefetch/policy.ts +48 -0
- package/src/browser/prefetch/queue.ts +128 -0
- package/src/browser/rango-state.ts +112 -0
- package/src/browser/react/Link.tsx +190 -70
- package/src/browser/react/NavigationProvider.tsx +78 -11
- package/src/browser/react/context.ts +6 -0
- package/src/browser/react/filter-segment-order.ts +11 -0
- package/src/browser/react/index.ts +12 -12
- package/src/browser/react/location-state-shared.ts +95 -53
- package/src/browser/react/location-state.ts +60 -15
- package/src/browser/react/mount-context.ts +6 -1
- package/src/browser/react/nonce-context.ts +23 -0
- package/src/browser/react/shallow-equal.ts +27 -0
- package/src/browser/react/use-action.ts +29 -51
- package/src/browser/react/use-client-cache.ts +5 -3
- package/src/browser/react/use-handle.ts +29 -70
- package/src/browser/react/use-link-status.ts +6 -5
- package/src/browser/react/use-navigation.ts +22 -63
- package/src/browser/react/use-params.ts +65 -0
- package/src/browser/react/use-pathname.ts +47 -0
- package/src/browser/react/use-router.ts +63 -0
- package/src/browser/react/use-search-params.ts +56 -0
- package/src/browser/react/use-segments.ts +80 -97
- package/src/browser/response-adapter.ts +73 -0
- package/src/browser/rsc-router.tsx +188 -57
- package/src/browser/scroll-restoration.ts +117 -44
- package/src/browser/segment-reconciler.ts +221 -0
- package/src/browser/segment-structure-assert.ts +16 -0
- package/src/browser/server-action-bridge.ts +488 -606
- package/src/browser/shallow.ts +6 -1
- package/src/browser/types.ts +116 -47
- package/src/browser/validate-redirect-origin.ts +29 -0
- package/src/build/generate-manifest.ts +63 -21
- package/src/build/generate-route-types.ts +36 -1038
- package/src/build/index.ts +2 -5
- package/src/build/route-trie.ts +38 -12
- package/src/build/route-types/ast-helpers.ts +25 -0
- package/src/build/route-types/ast-route-extraction.ts +98 -0
- package/src/build/route-types/codegen.ts +102 -0
- package/src/build/route-types/include-resolution.ts +411 -0
- package/src/build/route-types/param-extraction.ts +48 -0
- package/src/build/route-types/per-module-writer.ts +128 -0
- package/src/build/route-types/router-processing.ts +479 -0
- package/src/build/route-types/scan-filter.ts +78 -0
- package/src/build/runtime-discovery.ts +231 -0
- package/src/cache/background-task.ts +34 -0
- package/src/cache/cache-key-utils.ts +44 -0
- package/src/cache/cache-policy.ts +125 -0
- package/src/cache/cache-runtime.ts +338 -0
- package/src/cache/cache-scope.ts +122 -303
- package/src/cache/cf/cf-cache-store.ts +571 -17
- package/src/cache/cf/index.ts +13 -3
- package/src/cache/document-cache.ts +116 -77
- package/src/cache/handle-capture.ts +81 -0
- package/src/cache/handle-snapshot.ts +41 -0
- package/src/cache/index.ts +1 -15
- package/src/cache/memory-segment-store.ts +191 -13
- package/src/cache/profile-registry.ts +73 -0
- package/src/cache/read-through-swr.ts +134 -0
- package/src/cache/segment-codec.ts +256 -0
- package/src/cache/taint.ts +98 -0
- package/src/cache/types.ts +72 -122
- package/src/client.rsc.tsx +3 -1
- package/src/client.tsx +84 -126
- package/src/component-utils.ts +4 -4
- package/src/components/DefaultDocument.tsx +5 -1
- package/src/context-var.ts +86 -0
- package/src/debug.ts +19 -9
- package/src/errors.ts +77 -7
- package/src/handle.ts +12 -7
- package/src/handles/MetaTags.tsx +73 -20
- package/src/handles/breadcrumbs.ts +66 -0
- package/src/handles/index.ts +1 -0
- package/src/handles/meta.ts +30 -13
- package/src/host/cookie-handler.ts +21 -15
- package/src/host/errors.ts +8 -8
- package/src/host/index.ts +4 -7
- package/src/host/pattern-matcher.ts +27 -27
- package/src/host/router.ts +61 -39
- package/src/host/testing.ts +8 -8
- package/src/host/types.ts +15 -7
- package/src/host/utils.ts +1 -1
- package/src/href-client.ts +65 -45
- package/src/index.rsc.ts +104 -40
- package/src/index.ts +122 -67
- package/src/internal-debug.ts +9 -3
- package/src/loader.rsc.ts +18 -93
- package/src/loader.ts +26 -9
- package/src/network-error-thrower.tsx +3 -1
- package/src/outlet-provider.tsx +45 -0
- package/src/prerender/param-hash.ts +4 -2
- package/src/prerender/store.ts +121 -17
- package/src/prerender.ts +325 -20
- package/src/reverse.ts +144 -124
- package/src/root-error-boundary.tsx +41 -29
- package/src/route-content-wrapper.tsx +7 -4
- package/src/route-definition/dsl-helpers.ts +959 -0
- package/src/route-definition/helper-factories.ts +200 -0
- package/src/route-definition/helpers-types.ts +430 -0
- package/src/route-definition/index.ts +52 -0
- package/src/route-definition/redirect.ts +93 -0
- package/src/route-definition.ts +1 -1450
- package/src/route-map-builder.ts +87 -133
- package/src/route-name.ts +53 -0
- package/src/route-types.ts +41 -6
- package/src/router/content-negotiation.ts +116 -0
- package/src/router/debug-manifest.ts +72 -0
- package/src/router/error-handling.ts +9 -9
- package/src/router/find-match.ts +160 -0
- package/src/router/handler-context.ts +324 -116
- package/src/router/intercept-resolution.ts +11 -4
- package/src/router/lazy-includes.ts +237 -0
- package/src/router/loader-resolution.ts +179 -133
- package/src/router/logging.ts +112 -6
- package/src/router/manifest.ts +58 -19
- package/src/router/match-api.ts +89 -88
- package/src/router/match-context.ts +4 -2
- package/src/router/match-handlers.ts +440 -0
- package/src/router/match-middleware/background-revalidation.ts +84 -89
- package/src/router/match-middleware/cache-lookup.ts +261 -48
- package/src/router/match-middleware/cache-store.ts +54 -13
- package/src/router/match-middleware/intercept-resolution.ts +45 -22
- package/src/router/match-middleware/segment-resolution.ts +20 -9
- package/src/router/match-pipelines.ts +10 -45
- package/src/router/match-result.ts +34 -17
- package/src/router/metrics.ts +235 -15
- package/src/router/middleware-cookies.ts +55 -0
- package/src/router/middleware-types.ts +222 -0
- package/src/router/middleware.ts +327 -369
- package/src/router/pattern-matching.ts +169 -31
- package/src/router/prerender-match.ts +402 -0
- package/src/router/preview-match.ts +170 -0
- package/src/router/revalidation.ts +105 -14
- package/src/router/router-context.ts +40 -21
- package/src/router/router-interfaces.ts +452 -0
- package/src/router/router-options.ts +592 -0
- package/src/router/router-registry.ts +24 -0
- package/src/router/segment-resolution/fresh.ts +656 -0
- package/src/router/segment-resolution/helpers.ts +263 -0
- package/src/router/segment-resolution/loader-cache.ts +199 -0
- package/src/router/segment-resolution/revalidation.ts +1277 -0
- package/src/router/segment-resolution/static-store.ts +67 -0
- package/src/router/segment-resolution.ts +21 -1354
- package/src/router/segment-wrappers.ts +291 -0
- package/src/router/telemetry-otel.ts +299 -0
- package/src/router/telemetry.ts +300 -0
- package/src/router/timeout.ts +148 -0
- package/src/router/trie-matching.ts +96 -29
- package/src/router/types.ts +15 -9
- package/src/router.ts +642 -2366
- package/src/rsc/handler-context.ts +45 -0
- package/src/rsc/handler.ts +646 -1027
- package/src/rsc/helpers.ts +140 -6
- package/src/rsc/index.ts +0 -20
- package/src/rsc/loader-fetch.ts +209 -0
- package/src/rsc/manifest-init.ts +86 -0
- package/src/rsc/nonce.ts +14 -0
- package/src/rsc/origin-guard.ts +141 -0
- package/src/rsc/progressive-enhancement.ts +379 -0
- package/src/rsc/response-error.ts +37 -0
- package/src/rsc/response-route-handler.ts +347 -0
- package/src/rsc/rsc-rendering.ts +237 -0
- package/src/rsc/runtime-warnings.ts +42 -0
- package/src/rsc/server-action.ts +348 -0
- package/src/rsc/ssr-setup.ts +128 -0
- package/src/rsc/types.ts +38 -11
- package/src/search-params.ts +66 -54
- package/src/segment-system.tsx +165 -17
- package/src/server/context.ts +237 -54
- package/src/server/cookie-store.ts +190 -0
- package/src/server/fetchable-loader-store.ts +11 -6
- package/src/server/handle-store.ts +94 -15
- package/src/server/loader-registry.ts +15 -56
- package/src/server/request-context.ts +438 -71
- package/src/server.ts +26 -164
- package/src/ssr/index.tsx +101 -31
- package/src/static-handler.ts +22 -4
- package/src/theme/ThemeProvider.tsx +21 -15
- package/src/theme/ThemeScript.tsx +5 -5
- package/src/theme/constants.ts +5 -2
- package/src/theme/index.ts +4 -14
- package/src/theme/theme-context.ts +4 -30
- package/src/theme/theme-script.ts +21 -18
- package/src/types/boundaries.ts +158 -0
- package/src/types/cache-types.ts +198 -0
- package/src/types/error-types.ts +192 -0
- package/src/types/global-namespace.ts +100 -0
- package/src/types/handler-context.ts +687 -0
- package/src/types/index.ts +88 -0
- package/src/types/loader-types.ts +183 -0
- package/src/types/route-config.ts +170 -0
- package/src/types/route-entry.ts +109 -0
- package/src/types/segments.ts +150 -0
- package/src/types.ts +1 -1795
- package/src/urls/include-helper.ts +197 -0
- package/src/urls/index.ts +53 -0
- package/src/urls/path-helper-types.ts +339 -0
- package/src/urls/path-helper.ts +329 -0
- package/src/urls/pattern-types.ts +95 -0
- package/src/urls/response-types.ts +106 -0
- package/src/urls/type-extraction.ts +372 -0
- package/src/urls/urls-function.ts +98 -0
- package/src/urls.ts +1 -1323
- package/src/use-loader.tsx +85 -77
- package/src/vite/discovery/bundle-postprocess.ts +184 -0
- package/src/vite/discovery/discover-routers.ts +344 -0
- package/src/vite/discovery/prerender-collection.ts +385 -0
- package/src/vite/discovery/route-types-writer.ts +258 -0
- package/src/vite/discovery/self-gen-tracking.ts +47 -0
- package/src/vite/discovery/state.ts +108 -0
- package/src/vite/discovery/virtual-module-codegen.ts +203 -0
- package/src/vite/index.ts +11 -2259
- package/src/vite/plugin-types.ts +48 -0
- package/src/vite/plugins/cjs-to-esm.ts +93 -0
- package/src/vite/plugins/client-ref-dedup.ts +115 -0
- package/src/vite/plugins/client-ref-hashing.ts +105 -0
- package/src/vite/{expose-action-id.ts → plugins/expose-action-id.ts} +72 -47
- package/src/vite/{expose-id-utils.ts → plugins/expose-id-utils.ts} +8 -43
- package/src/vite/plugins/expose-ids/export-analysis.ts +296 -0
- package/src/vite/plugins/expose-ids/handler-transform.ts +179 -0
- package/src/vite/plugins/expose-ids/loader-transform.ts +74 -0
- package/src/vite/plugins/expose-ids/router-transform.ts +110 -0
- package/src/vite/plugins/expose-ids/types.ts +45 -0
- package/src/vite/plugins/expose-internal-ids.ts +569 -0
- package/src/vite/plugins/refresh-cmd.ts +65 -0
- package/src/vite/plugins/use-cache-transform.ts +323 -0
- package/src/vite/plugins/version-injector.ts +83 -0
- package/src/vite/plugins/version-plugin.ts +266 -0
- package/src/vite/plugins/virtual-entries.ts +123 -0
- package/src/vite/plugins/virtual-stub-plugin.ts +29 -0
- package/src/vite/rango.ts +445 -0
- package/src/vite/router-discovery.ts +777 -0
- package/src/vite/{ast-handler-extract.ts → utils/ast-handler-extract.ts} +181 -9
- package/src/vite/utils/banner.ts +36 -0
- package/src/vite/utils/bundle-analysis.ts +137 -0
- package/src/vite/utils/manifest-utils.ts +70 -0
- package/src/vite/{package-resolution.ts → utils/package-resolution.ts} +25 -29
- package/src/vite/utils/prerender-utils.ts +189 -0
- package/src/vite/utils/shared-utils.ts +169 -0
- package/CLAUDE.md +0 -43
- package/src/browser/lru-cache.ts +0 -69
- package/src/browser/request-controller.ts +0 -164
- package/src/cache/memory-store.ts +0 -253
- package/src/router.gen.ts +0 -6
- package/src/static-handler.gen.ts +0 -5
- package/src/urls.gen.ts +0 -8
- package/src/vite/expose-internal-ids.ts +0 -1167
- /package/src/vite/{version.d.ts → plugins/version.d.ts} +0 -0
package/src/router.ts
CHANGED
|
@@ -1,70 +1,44 @@
|
|
|
1
|
-
import type { ComponentType } from "react";
|
|
2
1
|
import { type ReactNode } from "react";
|
|
3
2
|
import { createCacheScope } from "./cache/cache-scope.js";
|
|
4
|
-
import
|
|
3
|
+
import {
|
|
4
|
+
setCacheProfiles,
|
|
5
|
+
resolveCacheProfiles,
|
|
6
|
+
} from "./cache/profile-registry.js";
|
|
7
|
+
import { isCachedFunction } from "./cache/taint.js";
|
|
5
8
|
import { assertClientComponent } from "./component-utils.js";
|
|
6
9
|
import { DefaultDocument } from "./components/DefaultDocument.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
} from "./errors";
|
|
10
|
-
import { serializeManifest, type SerializedManifest } from "./debug.js";
|
|
11
|
-
import {
|
|
12
|
-
createReverse,
|
|
13
|
-
type ReverseFunction,
|
|
14
|
-
type PrefixRoutePatterns,
|
|
15
|
-
} from "./reverse.js";
|
|
10
|
+
import type { SerializedManifest } from "./debug.js";
|
|
11
|
+
import { createReverse, type ReverseFunction } from "./reverse.js";
|
|
16
12
|
import {
|
|
17
13
|
registerRouteMap,
|
|
18
|
-
getGlobalRouteMap,
|
|
19
14
|
getPrecomputedEntries,
|
|
20
|
-
getRouteTrie,
|
|
21
15
|
getRouterManifest,
|
|
22
|
-
getRouterTrie,
|
|
23
16
|
getRouterPrecomputedEntries,
|
|
24
17
|
ensureRouterManifest,
|
|
25
18
|
} from "./route-map-builder.js";
|
|
26
|
-
import { tryTrieMatch } from "./router/trie-matching.js";
|
|
27
|
-
import {
|
|
28
|
-
createRouteHelpers,
|
|
29
|
-
type RouteHandlers,
|
|
30
|
-
} from "./route-definition.js";
|
|
31
19
|
import MapRootLayout from "./server/root-layout.js";
|
|
32
|
-
import type { AllUseItems
|
|
20
|
+
import type { AllUseItems } from "./route-types.js";
|
|
33
21
|
import type { UrlPatterns } from "./urls.js";
|
|
34
22
|
import {
|
|
35
23
|
EntryData,
|
|
36
|
-
InterceptEntry,
|
|
37
24
|
InterceptSelectorContext,
|
|
38
25
|
getContext,
|
|
39
26
|
RSCRouterContext,
|
|
40
|
-
runWithPrefixes,
|
|
41
27
|
type MetricsStore,
|
|
42
28
|
} from "./server/context";
|
|
43
29
|
import { createHandleStore, type HandleStore } from "./server/handle-store.js";
|
|
44
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
getRequestContext,
|
|
32
|
+
_getRequestContext,
|
|
33
|
+
} from "./server/request-context.js";
|
|
45
34
|
import type {
|
|
46
|
-
ErrorBoundaryHandler,
|
|
47
|
-
ErrorInfo,
|
|
48
35
|
ErrorPhase,
|
|
49
36
|
HandlerContext,
|
|
50
37
|
LoaderDataResult,
|
|
51
|
-
MatchResult,
|
|
52
|
-
NotFoundBoundaryHandler,
|
|
53
|
-
OnErrorCallback,
|
|
54
38
|
ResolvedRouteMap,
|
|
55
|
-
RouteDefinition,
|
|
56
39
|
RouteEntry,
|
|
57
40
|
TrailingSlashMode,
|
|
58
41
|
} from "./types";
|
|
59
|
-
import type {
|
|
60
|
-
NonceProvider,
|
|
61
|
-
} from "./rsc/types.js";
|
|
62
|
-
import {
|
|
63
|
-
runWithRequestContext,
|
|
64
|
-
type RequestContext,
|
|
65
|
-
type ExecutionContext,
|
|
66
|
-
} from "./server/request-context.js";
|
|
67
|
-
import type { SerializedSegmentData, SegmentHandleData } from "./cache/types.js";
|
|
68
42
|
|
|
69
43
|
// Extracted router utilities
|
|
70
44
|
import {
|
|
@@ -74,1065 +48,84 @@ import {
|
|
|
74
48
|
invokeOnError,
|
|
75
49
|
} from "./router/error-handling.js";
|
|
76
50
|
|
|
77
|
-
// Extracted
|
|
78
|
-
import {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
resolveLoadersOnlyWithRevalidation as _resolveLoadersOnlyWithRevalidation,
|
|
82
|
-
buildEntryRevalidateMap as _buildEntryRevalidateMap,
|
|
83
|
-
resolveAllSegmentsWithRevalidation as _resolveAllSegmentsWithRevalidation,
|
|
84
|
-
} from "./router/segment-resolution.js";
|
|
85
|
-
|
|
86
|
-
// Extracted intercept resolution functions
|
|
87
|
-
import {
|
|
88
|
-
findInterceptForRoute as _findInterceptForRoute,
|
|
89
|
-
resolveInterceptEntry as _resolveInterceptEntry,
|
|
90
|
-
resolveInterceptLoadersOnly as _resolveInterceptLoadersOnly,
|
|
91
|
-
} from "./router/intercept-resolution.js";
|
|
92
|
-
|
|
93
|
-
// Extracted match API functions
|
|
94
|
-
import {
|
|
95
|
-
createMatchContextForFull as _createMatchContextForFull,
|
|
96
|
-
createMatchContextForPartial as _createMatchContextForPartial,
|
|
97
|
-
matchError as _matchError,
|
|
98
|
-
} from "./router/match-api.js";
|
|
51
|
+
// Extracted module factories
|
|
52
|
+
import { createSegmentWrappers } from "./router/segment-wrappers.js";
|
|
53
|
+
import { createMatchHandlers } from "./router/match-handlers.js";
|
|
54
|
+
import { buildDebugManifest } from "./router/debug-manifest.js";
|
|
99
55
|
|
|
100
56
|
import type { SegmentResolutionDeps, MatchApiDeps } from "./router/types.js";
|
|
101
|
-
import { createHandlerContext
|
|
57
|
+
import { createHandlerContext } from "./router/handler-context.js";
|
|
102
58
|
import {
|
|
103
59
|
setupLoaderAccess,
|
|
104
60
|
setupLoaderAccessSilent,
|
|
105
|
-
setupBuildUse,
|
|
106
61
|
wrapLoaderWithErrorHandling,
|
|
107
62
|
} from "./router/loader-resolution.js";
|
|
108
63
|
import { loadManifest } from "./router/manifest.js";
|
|
64
|
+
import { createMetricsStore } from "./router/metrics.js";
|
|
109
65
|
import {
|
|
110
|
-
createMetricsStore,
|
|
111
|
-
} from "./router/metrics.js";
|
|
112
|
-
import {
|
|
113
|
-
collectRouteMiddleware,
|
|
114
66
|
parsePattern,
|
|
115
67
|
type MiddlewareEntry,
|
|
116
68
|
type MiddlewareFn,
|
|
117
69
|
} from "./router/middleware.js";
|
|
118
70
|
import {
|
|
119
71
|
extractStaticPrefix,
|
|
120
|
-
findMatch as findRouteMatch,
|
|
121
|
-
isLazyEvaluationNeeded,
|
|
122
72
|
traverseBack,
|
|
123
|
-
type RouteMatchResult,
|
|
124
73
|
} from "./router/pattern-matching.js";
|
|
74
|
+
import { resolveSink, safeEmit, getRequestId } from "./router/telemetry.js";
|
|
125
75
|
import { evaluateRevalidation } from "./router/revalidation.js";
|
|
126
76
|
import {
|
|
127
77
|
type RouterContext,
|
|
128
78
|
runWithRouterContext,
|
|
129
79
|
} from "./router/router-context.js";
|
|
130
|
-
import {
|
|
131
|
-
type ActionContext,
|
|
132
|
-
type MatchContext,
|
|
133
|
-
createPipelineState,
|
|
134
|
-
} from "./router/match-context.js";
|
|
135
|
-
import { createMatchPartialPipeline } from "./router/match-pipelines.js";
|
|
136
|
-
import { collectMatchResult } from "./router/match-result.js";
|
|
137
|
-
import {
|
|
138
|
-
runWithRouterLogContext,
|
|
139
|
-
withRouterLogScope,
|
|
140
|
-
} from "./router/logging.js";
|
|
141
80
|
import { resolveThemeConfig } from "./theme/constants.js";
|
|
81
|
+
import { resolveTimeouts } from "./router/timeout.js";
|
|
142
82
|
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
json: "application/json",
|
|
146
|
-
text: "text/plain",
|
|
147
|
-
xml: "application/xml",
|
|
148
|
-
html: "text/html",
|
|
149
|
-
md: "text/markdown",
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
// Reverse lookup: MIME type -> response type tag (e.g. "text/html" -> "html")
|
|
153
|
-
const MIME_RESPONSE_TYPE: Record<string, string> = Object.fromEntries(
|
|
154
|
-
Object.entries(RESPONSE_TYPE_MIME).map(([tag, mime]) => [mime, tag]),
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
interface AcceptEntry {
|
|
158
|
-
mime: string;
|
|
159
|
-
q: number;
|
|
160
|
-
order: number;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Parse an Accept header into a sorted array of MIME entries.
|
|
165
|
-
* Respects q-values (default 1.0) and uses client order as tiebreaker
|
|
166
|
-
* when q-values are equal (matching Express/Hono behavior).
|
|
167
|
-
*/
|
|
168
|
-
function parseAcceptTypes(accept: string): AcceptEntry[] {
|
|
169
|
-
const entries: AcceptEntry[] = [];
|
|
170
|
-
const parts = accept.split(",");
|
|
171
|
-
for (let i = 0; i < parts.length; i++) {
|
|
172
|
-
const part = parts[i]!;
|
|
173
|
-
const segments = part.split(";");
|
|
174
|
-
const mime = segments[0]!.trim();
|
|
175
|
-
if (!mime) continue;
|
|
176
|
-
let q = 1.0;
|
|
177
|
-
for (let j = 1; j < segments.length; j++) {
|
|
178
|
-
const param = segments[j]!.trim();
|
|
179
|
-
if (param.startsWith("q=")) {
|
|
180
|
-
q = Math.max(0, Math.min(1, Number(param.slice(2)) || 0));
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
entries.push({ mime, q, order: i });
|
|
184
|
-
}
|
|
185
|
-
// Sort: highest q first, then lowest client order first (stable)
|
|
186
|
-
entries.sort((a, b) => b.q - a.q || a.order - b.order);
|
|
187
|
-
return entries;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Sentinel response type for RSC routes in negotiation candidates
|
|
191
|
-
const RSC_RESPONSE_TYPE = "__rsc__";
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Pick the best negotiate variant by walking the client's sorted Accept list.
|
|
195
|
-
* For each accepted MIME type (in q-value/order priority), check if any
|
|
196
|
-
* candidate serves that type. Wildcards (*\/*) match the first candidate.
|
|
197
|
-
* Falls back to the first candidate if nothing matches.
|
|
198
|
-
*/
|
|
199
|
-
function pickNegotiateVariant(
|
|
200
|
-
acceptEntries: AcceptEntry[],
|
|
201
|
-
candidates: Array<{ routeKey: string; responseType: string }>,
|
|
202
|
-
): { routeKey: string; responseType: string } {
|
|
203
|
-
// Build a MIME -> candidate lookup for O(1) matching
|
|
204
|
-
const byCandidateMime = new Map<string, { routeKey: string; responseType: string }>();
|
|
205
|
-
for (const c of candidates) {
|
|
206
|
-
const mime = c.responseType === RSC_RESPONSE_TYPE ? "text/html" : RESPONSE_TYPE_MIME[c.responseType];
|
|
207
|
-
if (mime && !byCandidateMime.has(mime)) {
|
|
208
|
-
byCandidateMime.set(mime, c);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
for (const entry of acceptEntries) {
|
|
213
|
-
if (entry.q === 0) continue;
|
|
214
|
-
// Wildcard matches first candidate
|
|
215
|
-
if (entry.mime === "*/*") return candidates[0]!;
|
|
216
|
-
// Type wildcard (e.g. "text/*") — match first candidate with that type
|
|
217
|
-
if (entry.mime.endsWith("/*")) {
|
|
218
|
-
const typePrefix = entry.mime.slice(0, entry.mime.indexOf("/"));
|
|
219
|
-
for (const [mime, candidate] of byCandidateMime) {
|
|
220
|
-
if (mime.startsWith(typePrefix + "/")) return candidate;
|
|
221
|
-
}
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
const match = byCandidateMime.get(entry.mime);
|
|
225
|
-
if (match) return match;
|
|
226
|
-
}
|
|
227
|
-
// No match — use first candidate as default
|
|
228
|
-
return candidates[0]!;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Props passed to the root layout component
|
|
233
|
-
*/
|
|
234
|
-
export interface RootLayoutProps {
|
|
235
|
-
children: ReactNode;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Router configuration options
|
|
240
|
-
*/
|
|
241
|
-
/**
|
|
242
|
-
* Brand marker for identifying router instances at build time.
|
|
243
|
-
* Used by the Vite plugin to auto-discover routers from module exports.
|
|
244
|
-
*/
|
|
245
|
-
export const RSC_ROUTER_BRAND: "__rsc_router__" = "__rsc_router__";
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Global registry of all router instances created via createRouter().
|
|
249
|
-
* Each router is keyed by its id (auto-generated or user-provided).
|
|
250
|
-
* Used by the Vite plugin at build time to discover routers and extract
|
|
251
|
-
* manifests, prefix trees, and pre-render candidates.
|
|
252
|
-
*/
|
|
253
|
-
export const RouterRegistry: Map<string, RSCRouter<any, any>> = new Map();
|
|
254
|
-
|
|
255
|
-
let routerAutoId = 0;
|
|
256
|
-
|
|
257
|
-
export interface RSCRouterOptions<TEnv = any> {
|
|
258
|
-
/**
|
|
259
|
-
* Unique identifier for this router instance.
|
|
260
|
-
* Used to namespace static output files and route maps.
|
|
261
|
-
* Auto-generated if not provided.
|
|
262
|
-
*/
|
|
263
|
-
id?: string;
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Injected by the Vite transform at compile time.
|
|
267
|
-
* Hash of filename + line number for stable cross-environment ID.
|
|
268
|
-
* @internal
|
|
269
|
-
*/
|
|
270
|
-
$$id?: string;
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Enable performance metrics collection
|
|
274
|
-
* When enabled, metrics are output to console and available via Server-Timing header
|
|
275
|
-
*/
|
|
276
|
-
debugPerformance?: boolean;
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Allow the `?__debug_manifest` query parameter to return route manifest data as JSON.
|
|
280
|
-
* In development mode this is always enabled regardless of this setting.
|
|
281
|
-
* Defaults to true. Set to false to disable in production.
|
|
282
|
-
* @internal
|
|
283
|
-
*/
|
|
284
|
-
allowDebugManifest?: boolean;
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Document component that wraps the entire application.
|
|
288
|
-
*
|
|
289
|
-
* This component provides the HTML structure for your app and wraps
|
|
290
|
-
* both normal route content AND error states, preventing the app shell
|
|
291
|
-
* from unmounting during errors (avoids FOUC).
|
|
292
|
-
*
|
|
293
|
-
* Must be a client component ("use client") that accepts { children }.
|
|
294
|
-
*
|
|
295
|
-
* If not provided, a default document with basic HTML structure is used:
|
|
296
|
-
* `<html><head><meta charset/viewport></head><body>{children}</body></html>`
|
|
297
|
-
*
|
|
298
|
-
* @example
|
|
299
|
-
* ```typescript
|
|
300
|
-
* // components/Document.tsx
|
|
301
|
-
* "use client";
|
|
302
|
-
* export function Document({ children }: { children: ReactNode }) {
|
|
303
|
-
* return (
|
|
304
|
-
* <html lang="en">
|
|
305
|
-
* <head>
|
|
306
|
-
* <link rel="stylesheet" href="/styles.css" />
|
|
307
|
-
* </head>
|
|
308
|
-
* <body>
|
|
309
|
-
* <nav>...</nav>
|
|
310
|
-
* {children}
|
|
311
|
-
* </body>
|
|
312
|
-
* </html>
|
|
313
|
-
* );
|
|
314
|
-
* }
|
|
315
|
-
*
|
|
316
|
-
* // router.tsx
|
|
317
|
-
* const router = createRouter<AppEnv>({
|
|
318
|
-
* document: Document,
|
|
319
|
-
* });
|
|
320
|
-
* ```
|
|
321
|
-
*/
|
|
322
|
-
document?: ComponentType<RootLayoutProps>;
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Default error boundary fallback used when no error boundary is defined in the route tree
|
|
326
|
-
* If not provided, errors will propagate and crash the request
|
|
327
|
-
*/
|
|
328
|
-
defaultErrorBoundary?: ReactNode | ErrorBoundaryHandler;
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Default not-found boundary fallback used when no notFoundBoundary is defined in the route tree
|
|
332
|
-
* If not provided, DataNotFoundError will be treated as a regular error
|
|
333
|
-
*/
|
|
334
|
-
defaultNotFoundBoundary?: ReactNode | NotFoundBoundaryHandler;
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Component to render when no route matches the requested URL.
|
|
338
|
-
*
|
|
339
|
-
* This is rendered within your document/app shell with a 404 status code.
|
|
340
|
-
* Use this for a custom 404 page that maintains your app's look and feel.
|
|
341
|
-
*
|
|
342
|
-
* If not provided, a default "Page not found" component is rendered.
|
|
343
|
-
*
|
|
344
|
-
* Can be a static ReactNode or a function receiving the pathname.
|
|
345
|
-
*
|
|
346
|
-
* @example
|
|
347
|
-
* ```typescript
|
|
348
|
-
* // Simple static component
|
|
349
|
-
* const router = createRouter<AppEnv>({
|
|
350
|
-
* document: Document,
|
|
351
|
-
* notFound: <NotFound404 />,
|
|
352
|
-
* });
|
|
353
|
-
*
|
|
354
|
-
* // Dynamic component with pathname
|
|
355
|
-
* const router = createRouter<AppEnv>({
|
|
356
|
-
* document: Document,
|
|
357
|
-
* notFound: ({ pathname }) => (
|
|
358
|
-
* <div>
|
|
359
|
-
* <h1>404 - Not Found</h1>
|
|
360
|
-
* <p>No page exists at {pathname}</p>
|
|
361
|
-
* <a href="/">Go home</a>
|
|
362
|
-
* </div>
|
|
363
|
-
* ),
|
|
364
|
-
* });
|
|
365
|
-
* ```
|
|
366
|
-
*/
|
|
367
|
-
notFound?: ReactNode | ((props: { pathname: string }) => ReactNode);
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* Callback invoked when an error occurs during request handling.
|
|
371
|
-
*
|
|
372
|
-
* This callback is for notification/logging purposes - it cannot modify
|
|
373
|
-
* the error handling flow. Use errorBoundary() in route definitions to
|
|
374
|
-
* customize error UI.
|
|
375
|
-
*
|
|
376
|
-
* The callback receives comprehensive context about the error including:
|
|
377
|
-
* - The error itself
|
|
378
|
-
* - Phase where it occurred (routing, middleware, loader, handler, etc.)
|
|
379
|
-
* - Request info (URL, method, params)
|
|
380
|
-
* - Route info (routeKey, segmentId)
|
|
381
|
-
* - Environment/bindings
|
|
382
|
-
* - Duration from request start
|
|
383
|
-
*
|
|
384
|
-
* @example
|
|
385
|
-
* ```typescript
|
|
386
|
-
* const router = createRouter<AppEnv>({
|
|
387
|
-
* onError: (context) => {
|
|
388
|
-
* // Send to error tracking service
|
|
389
|
-
* Sentry.captureException(context.error, {
|
|
390
|
-
* tags: {
|
|
391
|
-
* phase: context.phase,
|
|
392
|
-
* route: context.routeKey,
|
|
393
|
-
* },
|
|
394
|
-
* extra: {
|
|
395
|
-
* url: context.url.toString(),
|
|
396
|
-
* params: context.params,
|
|
397
|
-
* duration: context.duration,
|
|
398
|
-
* },
|
|
399
|
-
* });
|
|
400
|
-
* },
|
|
401
|
-
* });
|
|
402
|
-
* ```
|
|
403
|
-
*/
|
|
404
|
-
onError?: OnErrorCallback<TEnv>;
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* Cache store for segment caching.
|
|
408
|
-
*
|
|
409
|
-
* When provided, enables route-level caching via cache() boundaries.
|
|
410
|
-
* The store handles persistence (memory, KV, Redis, etc.).
|
|
411
|
-
*
|
|
412
|
-
* Can be a static config or a function receiving env for runtime bindings.
|
|
413
|
-
*
|
|
414
|
-
* @example Static config
|
|
415
|
-
* ```typescript
|
|
416
|
-
* import { MemorySegmentCacheStore } from "rsc-router/rsc";
|
|
417
|
-
*
|
|
418
|
-
* const router = createRouter({
|
|
419
|
-
* cache: {
|
|
420
|
-
* store: new MemorySegmentCacheStore({ defaults: { ttl: 60 } }),
|
|
421
|
-
* },
|
|
422
|
-
* });
|
|
423
|
-
* ```
|
|
424
|
-
*
|
|
425
|
-
* @example Dynamic config with env (e.g., Cloudflare Workers with ExecutionContext)
|
|
426
|
-
* ```typescript
|
|
427
|
-
* const router = createRouter<AppEnv>({
|
|
428
|
-
* cache: (env) => ({
|
|
429
|
-
* store: new CFCacheStore({
|
|
430
|
-
* defaults: { ttl: 60 },
|
|
431
|
-
* ctx: env.ctx, // ExecutionContext for non-blocking writes
|
|
432
|
-
* }),
|
|
433
|
-
* }),
|
|
434
|
-
* });
|
|
435
|
-
* ```
|
|
436
|
-
*/
|
|
437
|
-
cache?:
|
|
438
|
-
| { store: SegmentCacheStore; enabled?: boolean }
|
|
439
|
-
| ((env: TEnv & { ctx?: ExecutionContext }) => {
|
|
440
|
-
store: SegmentCacheStore;
|
|
441
|
-
enabled?: boolean;
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* Theme configuration for automatic theme management.
|
|
446
|
-
*
|
|
447
|
-
* When provided, enables:
|
|
448
|
-
* - ctx.theme and ctx.setTheme() in route handlers
|
|
449
|
-
* - useTheme() hook for client components
|
|
450
|
-
* - FOUC prevention via inline script in MetaTags
|
|
451
|
-
* - Automatic ThemeProvider wrapping in NavigationProvider
|
|
452
|
-
*
|
|
453
|
-
* @example
|
|
454
|
-
* ```typescript
|
|
455
|
-
* const router = createRouter<AppEnv>({
|
|
456
|
-
* theme: {
|
|
457
|
-
* defaultTheme: "system",
|
|
458
|
-
* themes: ["light", "dark"],
|
|
459
|
-
* }
|
|
460
|
-
* });
|
|
461
|
-
*
|
|
462
|
-
* // In route handler:
|
|
463
|
-
* route("settings", (ctx) => {
|
|
464
|
-
* const theme = ctx.theme; // "light" | "dark" | "system"
|
|
465
|
-
* ctx.setTheme("dark"); // Sets cookie
|
|
466
|
-
* return <SettingsPage />;
|
|
467
|
-
* });
|
|
468
|
-
*
|
|
469
|
-
* // In client component:
|
|
470
|
-
* import { useTheme } from "@rangojs/router/theme";
|
|
471
|
-
*
|
|
472
|
-
* function ThemeToggle() {
|
|
473
|
-
* const { theme, setTheme, themes } = useTheme();
|
|
474
|
-
* return <select value={theme} onChange={e => setTheme(e.target.value)}>
|
|
475
|
-
* {themes.map(t => <option key={t}>{t}</option>)}
|
|
476
|
-
* </select>;
|
|
477
|
-
* }
|
|
478
|
-
* ```
|
|
479
|
-
*
|
|
480
|
-
* Use `theme: true` to enable with all defaults.
|
|
481
|
-
*/
|
|
482
|
-
theme?: import("./theme/types.js").ThemeConfig | true;
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* URL patterns to register with the router.
|
|
486
|
-
*
|
|
487
|
-
* Alternative to calling `.routes()` method - allows passing patterns
|
|
488
|
-
* directly in the config for a more concise setup.
|
|
489
|
-
*
|
|
490
|
-
* @example
|
|
491
|
-
* ```typescript
|
|
492
|
-
* import { urls } from "@rangojs/router/server";
|
|
493
|
-
*
|
|
494
|
-
* const urlpatterns = urls(({ path, layout }) => [
|
|
495
|
-
* path("/", HomePage, { name: "home" }),
|
|
496
|
-
* path("/about", AboutPage, { name: "about" }),
|
|
497
|
-
* ]);
|
|
498
|
-
*
|
|
499
|
-
* const router = createRouter<AppEnv>({
|
|
500
|
-
* document: Document,
|
|
501
|
-
* urls: urlpatterns,
|
|
502
|
-
* });
|
|
503
|
-
* ```
|
|
504
|
-
*/
|
|
505
|
-
urls?: UrlPatterns<TEnv, any>;
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Injected by the Vite transform at compile time.
|
|
509
|
-
* Static import of NamedRoutes from the generated named-routes file.
|
|
510
|
-
* Provides O(1) reverse() fallback when lazy includes haven't resolved.
|
|
511
|
-
* @internal
|
|
512
|
-
*/
|
|
513
|
-
$$routeNames?: Record<string, string>;
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* Nonce provider for Content Security Policy (CSP).
|
|
517
|
-
*
|
|
518
|
-
* Can be:
|
|
519
|
-
* - A function that returns a nonce string
|
|
520
|
-
* - A function that returns `true` to auto-generate a nonce
|
|
521
|
-
* - Undefined to disable nonce (default)
|
|
522
|
-
*
|
|
523
|
-
* The nonce will be applied to inline scripts injected by the RSC payload.
|
|
524
|
-
* It's also available to middleware via `ctx.get('nonce')`.
|
|
525
|
-
*
|
|
526
|
-
* @example Auto-generate nonce
|
|
527
|
-
* ```tsx
|
|
528
|
-
* createRouter({
|
|
529
|
-
* nonce: () => true,
|
|
530
|
-
* });
|
|
531
|
-
* ```
|
|
532
|
-
*
|
|
533
|
-
* @example Custom nonce from request context
|
|
534
|
-
* ```tsx
|
|
535
|
-
* createRouter({
|
|
536
|
-
* nonce: (request, env) => env.nonce,
|
|
537
|
-
* });
|
|
538
|
-
* ```
|
|
539
|
-
*/
|
|
540
|
-
nonce?: NonceProvider<TEnv>;
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* RSC version string included in metadata.
|
|
544
|
-
* The browser sends this back on partial requests to detect version mismatches.
|
|
545
|
-
*
|
|
546
|
-
* Defaults to the auto-generated VERSION from `@rangojs/router:version` virtual module.
|
|
547
|
-
* Only set this if you need a custom versioning strategy.
|
|
548
|
-
*
|
|
549
|
-
* @default VERSION from @rangojs/router:version
|
|
550
|
-
*/
|
|
551
|
-
version?: string;
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* Enable connection warmup to keep TCP+TLS alive after idle periods.
|
|
555
|
-
*
|
|
556
|
-
* When enabled, the client sends a HEAD request after the user returns
|
|
557
|
-
* from an idle period (60s+), prewarming the TLS connection before
|
|
558
|
-
* the next navigation.
|
|
559
|
-
*
|
|
560
|
-
* @default true
|
|
561
|
-
*/
|
|
562
|
-
warmup?: boolean;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* Merge route patterns with response types into a single route map.
|
|
567
|
-
* Routes with response types get { path, response } objects; others stay as strings.
|
|
568
|
-
* Handles both plain string routes and { path, search } object routes.
|
|
569
|
-
*/
|
|
570
|
-
type MergeRoutesWithResponses<
|
|
571
|
-
TRoutes extends Record<string, unknown>,
|
|
572
|
-
TResponses,
|
|
573
|
-
> = {
|
|
574
|
-
[K in keyof TRoutes]: K extends keyof NonNullable<TResponses>
|
|
575
|
-
? unknown extends NonNullable<TResponses>[K]
|
|
576
|
-
? TRoutes[K] // RSC route — TData defaults to unknown, keep as-is
|
|
577
|
-
: TRoutes[K] extends { readonly path: infer P extends string }
|
|
578
|
-
? TRoutes[K] & { readonly response: NonNullable<TResponses>[K] }
|
|
579
|
-
: { readonly path: TRoutes[K] & string; readonly response: NonNullable<TResponses>[K] }
|
|
580
|
-
: TRoutes[K]
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
/**
|
|
584
|
-
* Extract the URL pattern from a route entry (string or { path, response } object)
|
|
585
|
-
*/
|
|
586
|
-
type PatternOfEntry<V> =
|
|
587
|
-
V extends string ? V
|
|
588
|
-
: V extends { readonly path: infer P extends string } ? P
|
|
589
|
-
: never;
|
|
590
|
-
|
|
591
|
-
/**
|
|
592
|
-
* Type-level detection of conflicting route keys.
|
|
593
|
-
* Extracts keys that exist in both TExisting and TNew but with different URL patterns.
|
|
594
|
-
* Returns `never` if no conflicts exist.
|
|
595
|
-
* Compares patterns (not full entries) to handle both string and { path, response } values.
|
|
596
|
-
*
|
|
597
|
-
* @example
|
|
598
|
-
* ```typescript
|
|
599
|
-
* ConflictingKeys<{ a: "/a" }, { a: "/b" }> // "a" (conflict - same key, different URLs)
|
|
600
|
-
* ConflictingKeys<{ a: "/a" }, { a: "/a" }> // never (no conflict - same key and URL)
|
|
601
|
-
* ConflictingKeys<{ a: "/a" }, { b: "/b" }> // never (no conflict - different keys)
|
|
602
|
-
* ```
|
|
603
|
-
*/
|
|
604
|
-
type ConflictingKeys<
|
|
605
|
-
TExisting extends Record<string, unknown>,
|
|
606
|
-
TNew extends Record<string, unknown>,
|
|
607
|
-
> = {
|
|
608
|
-
[K in keyof TExisting & keyof TNew]: PatternOfEntry<TExisting[K]> extends PatternOfEntry<TNew[K]>
|
|
609
|
-
? PatternOfEntry<TNew[K]> extends PatternOfEntry<TExisting[K]>
|
|
610
|
-
? never // Same pattern, no conflict
|
|
611
|
-
: K // Different patterns, conflict
|
|
612
|
-
: K; // Different patterns, conflict
|
|
613
|
-
}[keyof TExisting & keyof TNew];
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* Error type returned when route keys conflict.
|
|
617
|
-
* Methods require an impossible `never` parameter so TypeScript errors at the call site.
|
|
618
|
-
*/
|
|
619
|
-
type RouteConflictError<TConflicts extends string> = {
|
|
620
|
-
__error: `Route key conflict! Key "${TConflicts}" already exists with a different URL pattern.`;
|
|
621
|
-
hint: "Route keys must be globally unique. Use prefixed names like 'blog.index' instead of 'index'.";
|
|
622
|
-
conflictingKeys: TConflicts;
|
|
623
|
-
// These methods require `never` so calling them produces an error at the call site
|
|
624
|
-
routes: (
|
|
625
|
-
__conflict: `Fix route key conflict: "${TConflicts}" is already defined with a different URL pattern`,
|
|
626
|
-
) => never;
|
|
627
|
-
map: (
|
|
628
|
-
__conflict: `Fix route key conflict: "${TConflicts}" is already defined with a different URL pattern`,
|
|
629
|
-
) => never;
|
|
630
|
-
};
|
|
631
|
-
|
|
632
|
-
/**
|
|
633
|
-
* Simplified route helpers for inline route definitions.
|
|
634
|
-
* Uses TRoutes (Record<string, string>) instead of RouteDefinition.
|
|
635
|
-
*
|
|
636
|
-
* Note: Some helpers use `any` for context types as a trade-off for simpler usage.
|
|
637
|
-
* The main type safety is in the `route` helper which enforces valid route names.
|
|
638
|
-
* For full type safety, use the standard map() API with separate handler files.
|
|
639
|
-
*/
|
|
640
|
-
type InlineRouteHelpers<TRoutes extends Record<string, string>, TEnv> = {
|
|
641
|
-
/**
|
|
642
|
-
* Define a route handler for a specific route pattern
|
|
643
|
-
*/
|
|
644
|
-
route: <K extends keyof TRoutes & string>(
|
|
645
|
-
name: K,
|
|
646
|
-
handler:
|
|
647
|
-
| ((ctx: HandlerContext<{}, TEnv>) => ReactNode | Promise<ReactNode>)
|
|
648
|
-
| ReactNode,
|
|
649
|
-
) => AllUseItems;
|
|
650
|
-
|
|
651
|
-
/**
|
|
652
|
-
* Define a layout that wraps child routes
|
|
653
|
-
*/
|
|
654
|
-
layout: (
|
|
655
|
-
component:
|
|
656
|
-
| ReactNode
|
|
657
|
-
| ((ctx: HandlerContext<any, TEnv>) => ReactNode | Promise<ReactNode>),
|
|
658
|
-
use?: () => AllUseItems[],
|
|
659
|
-
) => AllUseItems;
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* Define parallel routes
|
|
663
|
-
*/
|
|
664
|
-
parallel: (
|
|
665
|
-
slots: Record<
|
|
666
|
-
`@${string}`,
|
|
667
|
-
| ReactNode
|
|
668
|
-
| ((ctx: HandlerContext<any, TEnv>) => ReactNode | Promise<ReactNode>)
|
|
669
|
-
>,
|
|
670
|
-
use?: () => AllUseItems[],
|
|
671
|
-
) => AllUseItems;
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* Define route middleware
|
|
675
|
-
*/
|
|
676
|
-
middleware: (
|
|
677
|
-
fn: (ctx: any, next: () => Promise<void>) => Promise<void>,
|
|
678
|
-
) => AllUseItems;
|
|
679
|
-
|
|
680
|
-
/**
|
|
681
|
-
* Define revalidation handlers
|
|
682
|
-
*/
|
|
683
|
-
revalidate: (fn: (ctx: any) => boolean | Promise<boolean>) => AllUseItems;
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* Define data loaders
|
|
687
|
-
*/
|
|
688
|
-
loader: (loader: any, use?: () => AllUseItems[]) => AllUseItems;
|
|
689
|
-
|
|
690
|
-
/**
|
|
691
|
-
* Define loading states
|
|
692
|
-
*/
|
|
693
|
-
loading: (component: ReactNode) => AllUseItems;
|
|
694
|
-
|
|
695
|
-
/**
|
|
696
|
-
* Define error boundaries
|
|
697
|
-
*/
|
|
698
|
-
errorBoundary: (
|
|
699
|
-
handler: ReactNode | ((props: { error: Error }) => ReactNode),
|
|
700
|
-
) => AllUseItems;
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
* Define not found boundaries
|
|
704
|
-
*/
|
|
705
|
-
notFoundBoundary: (
|
|
706
|
-
handler: ReactNode | ((props: { pathname: string }) => ReactNode),
|
|
707
|
-
) => AllUseItems;
|
|
708
|
-
|
|
709
|
-
/**
|
|
710
|
-
* Define intercept routes
|
|
711
|
-
*/
|
|
712
|
-
intercept: (
|
|
713
|
-
name: string,
|
|
714
|
-
handler:
|
|
715
|
-
| ReactNode
|
|
716
|
-
| ((ctx: HandlerContext<any, TEnv>) => ReactNode | Promise<ReactNode>),
|
|
717
|
-
use?: () => AllUseItems[],
|
|
718
|
-
) => AllUseItems;
|
|
719
|
-
|
|
720
|
-
/**
|
|
721
|
-
* Define when conditions for intercepts
|
|
722
|
-
*/
|
|
723
|
-
when: (condition: (ctx: any) => boolean | Promise<boolean>) => AllUseItems;
|
|
724
|
-
|
|
725
|
-
/**
|
|
726
|
-
* Define cache configuration
|
|
727
|
-
*/
|
|
728
|
-
cache: (
|
|
729
|
-
config: { ttl?: number; swr?: number } | false,
|
|
730
|
-
use?: () => AllUseItems[],
|
|
731
|
-
) => AllUseItems;
|
|
732
|
-
};
|
|
733
|
-
|
|
734
|
-
/**
|
|
735
|
-
* Router builder for chaining .use() and .map()
|
|
736
|
-
* TRoutes accumulates all registered route types through the chain
|
|
737
|
-
* TLocalRoutes contains the routes for the current .routes() call (for inline handler typing)
|
|
738
|
-
*/
|
|
739
|
-
interface RouteBuilder<
|
|
740
|
-
T extends RouteDefinition,
|
|
741
|
-
TEnv,
|
|
742
|
-
TRoutes extends Record<string, unknown>,
|
|
743
|
-
TLocalRoutes extends Record<string, string> = Record<string, string>,
|
|
744
|
-
> {
|
|
745
|
-
/**
|
|
746
|
-
* Add middleware scoped to this mount
|
|
747
|
-
* Called between .routes() and .map()
|
|
748
|
-
*
|
|
749
|
-
* @example
|
|
750
|
-
* ```typescript
|
|
751
|
-
* .routes("/admin", adminRoutes)
|
|
752
|
-
* .use(authMiddleware) // All of /admin/*
|
|
753
|
-
* .use("/danger/*", superAuth) // Only /admin/danger/*
|
|
754
|
-
* .map(() => import("./admin"))
|
|
755
|
-
* ```
|
|
756
|
-
*/
|
|
757
|
-
use(
|
|
758
|
-
patternOrMiddleware: string | MiddlewareFn<TEnv>,
|
|
759
|
-
middleware?: MiddlewareFn<TEnv>,
|
|
760
|
-
): RouteBuilder<T, TEnv, TRoutes, TLocalRoutes>;
|
|
761
|
-
|
|
762
|
-
/**
|
|
763
|
-
* Map routes to handlers
|
|
764
|
-
*
|
|
765
|
-
* Supports two patterns:
|
|
766
|
-
*
|
|
767
|
-
* 1. Lazy loading (code-split):
|
|
768
|
-
* ```typescript
|
|
769
|
-
* .routes(homeRoutes)
|
|
770
|
-
* .map(() => import("./handlers/home"))
|
|
771
|
-
* ```
|
|
772
|
-
*
|
|
773
|
-
* 2. Inline definition:
|
|
774
|
-
* ```typescript
|
|
775
|
-
* .routes({ index: "/", about: "/about" })
|
|
776
|
-
* .map(({ route }) => [
|
|
777
|
-
* route("index", () => <HomePage />),
|
|
778
|
-
* route("about", () => <AboutPage />),
|
|
779
|
-
* ])
|
|
780
|
-
* ```
|
|
781
|
-
*/
|
|
782
|
-
// Inline definition overload - handler receives helpers (must be first for correct inference)
|
|
783
|
-
// Uses TLocalRoutes so route names don't need the prefix
|
|
784
|
-
map<
|
|
785
|
-
H extends (
|
|
786
|
-
helpers: InlineRouteHelpers<TLocalRoutes, TEnv>,
|
|
787
|
-
) => Array<AllUseItems>,
|
|
788
|
-
>(
|
|
789
|
-
handler: H,
|
|
790
|
-
): RSCRouter<TEnv, TRoutes>;
|
|
791
|
-
// Lazy loading overload - verifies imported handlers match route definition
|
|
792
|
-
map(
|
|
793
|
-
handler: () =>
|
|
794
|
-
| Array<AllUseItems>
|
|
795
|
-
| Promise<{ default: RouteHandlers<TLocalRoutes> }>
|
|
796
|
-
| Promise<RouteHandlers<TLocalRoutes>>,
|
|
797
|
-
): RSCRouter<TEnv, TRoutes>;
|
|
798
|
-
|
|
799
|
-
/**
|
|
800
|
-
* Accumulated route map for typeof extraction
|
|
801
|
-
* Used for module augmentation: `type AppRoutes = typeof _router.routeMap`
|
|
802
|
-
*/
|
|
803
|
-
readonly routeMap: TRoutes;
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* RSC Router interface
|
|
808
|
-
* TRoutes accumulates all registered route types through the builder chain
|
|
809
|
-
*/
|
|
810
|
-
export interface RSCRouter<
|
|
811
|
-
TEnv = any,
|
|
812
|
-
TRoutes extends Record<string, unknown> = Record<string, string>,
|
|
813
|
-
> {
|
|
814
|
-
/**
|
|
815
|
-
* Brand marker for build-time discovery.
|
|
816
|
-
* The Vite plugin uses this to identify router instances in module exports.
|
|
817
|
-
*/
|
|
818
|
-
readonly __brand: typeof RSC_ROUTER_BRAND;
|
|
819
|
-
|
|
820
|
-
/**
|
|
821
|
-
* Unique identifier for this router instance.
|
|
822
|
-
* Used to namespace static output and isolate route maps between routers.
|
|
823
|
-
*/
|
|
824
|
-
readonly id: string;
|
|
825
|
-
|
|
826
|
-
/**
|
|
827
|
-
* Register routes with a prefix
|
|
828
|
-
* Route keys stay unchanged, only URL patterns get the prefix applied.
|
|
829
|
-
* This enables composable route modules that work regardless of mount point.
|
|
830
|
-
*
|
|
831
|
-
* @throws Compile-time error if route keys conflict with previously registered routes
|
|
832
|
-
*/
|
|
833
|
-
routes<const TPrefix extends string, const T extends Record<string, string>>(
|
|
834
|
-
prefix: TPrefix,
|
|
835
|
-
routes: T,
|
|
836
|
-
): ConflictingKeys<TRoutes, PrefixRoutePatterns<T, TPrefix>> extends never
|
|
837
|
-
? RouteBuilder<
|
|
838
|
-
RouteDefinition,
|
|
839
|
-
TEnv,
|
|
840
|
-
TRoutes & PrefixRoutePatterns<T, TPrefix>,
|
|
841
|
-
T
|
|
842
|
-
>
|
|
843
|
-
: RouteConflictError<
|
|
844
|
-
ConflictingKeys<TRoutes, PrefixRoutePatterns<T, TPrefix>> & string
|
|
845
|
-
>;
|
|
846
|
-
|
|
847
|
-
/**
|
|
848
|
-
* Register routes without a prefix
|
|
849
|
-
* Route types are accumulated through the chain
|
|
850
|
-
*
|
|
851
|
-
* @throws Compile-time error if route keys conflict with previously registered routes
|
|
852
|
-
*/
|
|
853
|
-
routes<const T extends Record<string, string>>(
|
|
854
|
-
routes: T,
|
|
855
|
-
): ConflictingKeys<TRoutes, T> extends never
|
|
856
|
-
? RouteBuilder<RouteDefinition, TEnv, TRoutes & T, T>
|
|
857
|
-
: RouteConflictError<ConflictingKeys<TRoutes, T> & string>;
|
|
858
|
-
|
|
859
|
-
/**
|
|
860
|
-
* Register routes using Django-style URL patterns
|
|
861
|
-
* This is the new API for @rangojs/router - call once with urls() result
|
|
862
|
-
*
|
|
863
|
-
* @example
|
|
864
|
-
* ```typescript
|
|
865
|
-
* createRouter({})
|
|
866
|
-
* .routes(urlpatterns) // Single call with urls() result
|
|
867
|
-
* ```
|
|
868
|
-
*/
|
|
869
|
-
routes<T extends UrlPatterns<TEnv, any>>(
|
|
870
|
-
patterns: T,
|
|
871
|
-
): RSCRouter<
|
|
872
|
-
TEnv,
|
|
873
|
-
TRoutes &
|
|
874
|
-
(NonNullable<T["_routes"]> extends Record<string, unknown>
|
|
875
|
-
? MergeRoutesWithResponses<NonNullable<T["_routes"]>, T["_responses"]>
|
|
876
|
-
: Record<string, string>)
|
|
877
|
-
>;
|
|
878
|
-
|
|
879
|
-
/**
|
|
880
|
-
* Add global middleware that runs on all routes
|
|
881
|
-
* Position matters: middleware before any .routes() is global
|
|
882
|
-
*
|
|
883
|
-
* @example
|
|
884
|
-
* ```typescript
|
|
885
|
-
* createRouter({ document: RootLayout })
|
|
886
|
-
* .use(loggerMiddleware) // All routes
|
|
887
|
-
* .use("/api/*", rateLimiter) // Pattern match
|
|
888
|
-
* .routes(homeRoutes)
|
|
889
|
-
* .map(() => import("./home"))
|
|
890
|
-
* ```
|
|
891
|
-
*/
|
|
892
|
-
use(
|
|
893
|
-
patternOrMiddleware: string | MiddlewareFn<TEnv>,
|
|
894
|
-
middleware?: MiddlewareFn<TEnv>,
|
|
895
|
-
): RSCRouter<TEnv, TRoutes>;
|
|
896
|
-
|
|
897
|
-
/**
|
|
898
|
-
* Type-safe URL builder for registered routes
|
|
899
|
-
* Types are inferred from the accumulated route registrations
|
|
900
|
-
* Route keys stay unchanged regardless of mount prefix.
|
|
901
|
-
*
|
|
902
|
-
* @example
|
|
903
|
-
* ```typescript
|
|
904
|
-
* // Given: .routes("/shop", { cart: "/cart", detail: "/product/:slug" })
|
|
905
|
-
* router.reverse("cart"); // "/shop/cart"
|
|
906
|
-
* router.reverse("detail", { slug: "widget" }); // "/shop/product/widget"
|
|
907
|
-
* ```
|
|
908
|
-
*/
|
|
909
|
-
reverse: ReverseFunction<TRoutes>;
|
|
910
|
-
|
|
911
|
-
/**
|
|
912
|
-
* Accumulated route map for typeof extraction
|
|
913
|
-
* Used for module augmentation: `type AppRoutes = typeof _router.routeMap`
|
|
914
|
-
*
|
|
915
|
-
* @example
|
|
916
|
-
* ```typescript
|
|
917
|
-
* const _router = createRouter<AppEnv>()
|
|
918
|
-
* .routes(homeRoutes).map(() => import('./home'))
|
|
919
|
-
* .routes('/shop', shopRoutes).map(() => import('./shop'));
|
|
920
|
-
*
|
|
921
|
-
* type AppRoutes = typeof _router.routeMap;
|
|
922
|
-
*
|
|
923
|
-
* declare global {
|
|
924
|
-
* namespace RSCRouter {
|
|
925
|
-
* interface RegisteredRoutes extends AppRoutes {}
|
|
926
|
-
* }
|
|
927
|
-
* }
|
|
928
|
-
* ```
|
|
929
|
-
*/
|
|
930
|
-
readonly routeMap: TRoutes;
|
|
83
|
+
// Extracted content negotiation utilities
|
|
84
|
+
import { flattenNamedRoutes } from "./router/content-negotiation.js";
|
|
931
85
|
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
readonly cache?: RSCRouterOptions<TEnv>["cache"];
|
|
948
|
-
|
|
949
|
-
/**
|
|
950
|
-
* Not found component to render when no route matches (for internal use by RSC handler)
|
|
951
|
-
*/
|
|
952
|
-
readonly notFound?: RSCRouterOptions<TEnv>["notFound"];
|
|
953
|
-
|
|
954
|
-
/**
|
|
955
|
-
* Resolved theme configuration (null if theme not enabled)
|
|
956
|
-
* Used by NavigationProvider to include ThemeProvider and by MetaTags to render theme script
|
|
957
|
-
*/
|
|
958
|
-
readonly themeConfig: import("./theme/types.js").ResolvedThemeConfig | null;
|
|
959
|
-
|
|
960
|
-
/**
|
|
961
|
-
* Whether connection warmup is enabled.
|
|
962
|
-
* When true, the client sends HEAD /?_rsc_warmup after idle periods
|
|
963
|
-
* and the server responds with 204 No Content.
|
|
964
|
-
*/
|
|
965
|
-
readonly warmupEnabled: boolean;
|
|
966
|
-
|
|
967
|
-
/**
|
|
968
|
-
* Whether ?__debug_manifest is allowed in production.
|
|
969
|
-
* Always enabled in development.
|
|
970
|
-
* @internal
|
|
971
|
-
*/
|
|
972
|
-
readonly allowDebugManifest: boolean;
|
|
973
|
-
|
|
974
|
-
/**
|
|
975
|
-
* App-level middleware entries (for internal use by RSC handler)
|
|
976
|
-
* These wrap the entire request/response cycle
|
|
977
|
-
*/
|
|
978
|
-
readonly middleware: MiddlewareEntry<TEnv>[];
|
|
979
|
-
|
|
980
|
-
/**
|
|
981
|
-
* Nonce provider for CSP (for internal use by createHandler)
|
|
982
|
-
*/
|
|
983
|
-
readonly nonce?: NonceProvider<TEnv>;
|
|
984
|
-
|
|
985
|
-
/**
|
|
986
|
-
* RSC version string (for internal use by createHandler)
|
|
987
|
-
*/
|
|
988
|
-
readonly version?: string;
|
|
989
|
-
|
|
990
|
-
/**
|
|
991
|
-
* URL patterns reference for build-time manifest generation
|
|
992
|
-
* @internal
|
|
993
|
-
*/
|
|
994
|
-
readonly urlpatterns?: UrlPatterns<TEnv, any>;
|
|
995
|
-
|
|
996
|
-
/**
|
|
997
|
-
* Source file path where createRouter() was called.
|
|
998
|
-
* Set via Error.stack parsing at construction time.
|
|
999
|
-
* Used by the Vite plugin to write per-router named-routes.gen.ts files.
|
|
1000
|
-
* @internal
|
|
1001
|
-
*/
|
|
1002
|
-
readonly __sourceFile?: string;
|
|
1003
|
-
|
|
1004
|
-
match(request: Request, context: TEnv): Promise<MatchResult>;
|
|
1005
|
-
|
|
1006
|
-
/**
|
|
1007
|
-
* Build-time pre-render match. Resolves segments with a BuildContext
|
|
1008
|
-
* (no request/env/headers/cookies), skipping middleware and loaders.
|
|
1009
|
-
* Used by the Vite plugin to collect pre-render data at build time.
|
|
1010
|
-
* @internal
|
|
1011
|
-
*/
|
|
1012
|
-
matchForPrerender(
|
|
1013
|
-
pathname: string,
|
|
1014
|
-
params: Record<string, string>,
|
|
1015
|
-
): Promise<{
|
|
1016
|
-
segments: SerializedSegmentData[];
|
|
1017
|
-
handles: Record<string, SegmentHandleData>;
|
|
1018
|
-
routeName: string;
|
|
1019
|
-
params: Record<string, string>;
|
|
1020
|
-
} | null>;
|
|
1021
|
-
|
|
1022
|
-
/**
|
|
1023
|
-
* Preview match - returns route middleware without segment resolution.
|
|
1024
|
-
* Also returns responseType and handler for response routes (non-RSC short-circuit).
|
|
1025
|
-
*/
|
|
1026
|
-
previewMatch(
|
|
1027
|
-
request: Request,
|
|
1028
|
-
context: TEnv,
|
|
1029
|
-
): Promise<{
|
|
1030
|
-
routeMiddleware?: Array<{
|
|
1031
|
-
handler: import("./router/middleware.js").MiddlewareFn;
|
|
1032
|
-
params: Record<string, string>;
|
|
1033
|
-
}>;
|
|
1034
|
-
responseType?: string;
|
|
1035
|
-
handler?: Function;
|
|
1036
|
-
params?: Record<string, string>;
|
|
1037
|
-
negotiated?: boolean;
|
|
1038
|
-
} | null>;
|
|
1039
|
-
|
|
1040
|
-
matchPartial(
|
|
1041
|
-
request: Request,
|
|
1042
|
-
context: TEnv,
|
|
1043
|
-
actionContext?: {
|
|
1044
|
-
actionId?: string;
|
|
1045
|
-
actionUrl?: URL;
|
|
1046
|
-
actionResult?: any;
|
|
1047
|
-
formData?: FormData;
|
|
1048
|
-
},
|
|
1049
|
-
): Promise<MatchResult | null>;
|
|
1050
|
-
|
|
1051
|
-
/**
|
|
1052
|
-
* Match an error to the nearest error boundary and return error segments
|
|
1053
|
-
*
|
|
1054
|
-
* Used when an action or other operation fails and we need to render
|
|
1055
|
-
* the error boundary UI. Finds the nearest errorBoundary in the route tree
|
|
1056
|
-
* for the current URL and renders it with the error info.
|
|
1057
|
-
*
|
|
1058
|
-
* @param request - The current request (used to match the route)
|
|
1059
|
-
* @param context - Environment context
|
|
1060
|
-
* @param error - The error that occurred
|
|
1061
|
-
* @param segmentType - Type of segment where error occurred (default: "route")
|
|
1062
|
-
* @returns MatchResult with error segment, or null if no error boundary found
|
|
1063
|
-
*/
|
|
1064
|
-
matchError(
|
|
1065
|
-
request: Request,
|
|
1066
|
-
context: TEnv,
|
|
1067
|
-
error: unknown,
|
|
1068
|
-
segmentType?: ErrorInfo["segmentType"],
|
|
1069
|
-
): Promise<MatchResult | null>;
|
|
1070
|
-
|
|
1071
|
-
/**
|
|
1072
|
-
* @internal
|
|
1073
|
-
* Debug utility to serialize the manifest for inspection
|
|
1074
|
-
* Returns a JSON-friendly representation of all routes and layouts
|
|
1075
|
-
*/
|
|
1076
|
-
debugManifest(): Promise<SerializedManifest>;
|
|
1077
|
-
|
|
1078
|
-
/**
|
|
1079
|
-
* Handle an RSC request.
|
|
1080
|
-
*
|
|
1081
|
-
* Uses the router's configuration (nonce, version, cache) automatically.
|
|
1082
|
-
* The handler is lazily created on first call.
|
|
1083
|
-
*
|
|
1084
|
-
* @example Cloudflare Workers
|
|
1085
|
-
* ```tsx
|
|
1086
|
-
* import { router } from "./router";
|
|
1087
|
-
*
|
|
1088
|
-
* export default { fetch: router.fetch };
|
|
1089
|
-
* ```
|
|
1090
|
-
*
|
|
1091
|
-
* @example Direct export
|
|
1092
|
-
* ```tsx
|
|
1093
|
-
* const router = createRouter({
|
|
1094
|
-
* document: Document,
|
|
1095
|
-
* urls: urlpatterns,
|
|
1096
|
-
* nonce: () => true,
|
|
1097
|
-
* });
|
|
1098
|
-
*
|
|
1099
|
-
* export const fetch = router.fetch;
|
|
1100
|
-
* ```
|
|
1101
|
-
*/
|
|
1102
|
-
fetch(
|
|
1103
|
-
request: Request,
|
|
1104
|
-
env: TEnv & { ctx?: ExecutionContext },
|
|
1105
|
-
): Promise<Response>;
|
|
1106
|
-
}
|
|
86
|
+
// Extracted router types and registry
|
|
87
|
+
import {
|
|
88
|
+
RSC_ROUTER_BRAND,
|
|
89
|
+
RouterRegistry,
|
|
90
|
+
nextRouterAutoId,
|
|
91
|
+
} from "./router/router-registry.js";
|
|
92
|
+
import type {
|
|
93
|
+
RSCRouterOptions,
|
|
94
|
+
RootLayoutProps,
|
|
95
|
+
} from "./router/router-options.js";
|
|
96
|
+
import type {
|
|
97
|
+
RSCRouter,
|
|
98
|
+
RSCRouterInternal,
|
|
99
|
+
RouterRequestInput,
|
|
100
|
+
} from "./router/router-interfaces.js";
|
|
1107
101
|
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
*/
|
|
102
|
+
// Extracted closure functions
|
|
103
|
+
import {
|
|
104
|
+
findLazyIncludes,
|
|
105
|
+
evaluateLazyEntry as _evaluateLazyEntry,
|
|
106
|
+
type LazyEvalDeps,
|
|
107
|
+
} from "./router/lazy-includes.js";
|
|
108
|
+
import { createFindMatch } from "./router/find-match.js";
|
|
109
|
+
import {
|
|
110
|
+
matchForPrerender as _matchForPrerender,
|
|
111
|
+
renderStaticSegment as _renderStaticSegment,
|
|
112
|
+
} from "./router/prerender-match.js";
|
|
113
|
+
|
|
114
|
+
// Re-export public types and values from extracted modules
|
|
115
|
+
export { RSC_ROUTER_BRAND, RouterRegistry } from "./router/router-registry.js";
|
|
116
|
+
export type {
|
|
117
|
+
RSCRouterOptions,
|
|
118
|
+
RootLayoutProps,
|
|
119
|
+
SSRStreamMode,
|
|
120
|
+
SSROptions,
|
|
121
|
+
ResolveStreamingContext,
|
|
122
|
+
} from "./router/router-options.js";
|
|
123
|
+
export type {
|
|
124
|
+
RSCRouter,
|
|
125
|
+
RSCRouterInternal,
|
|
126
|
+
RouterRequestInput,
|
|
127
|
+
} from "./router/router-interfaces.js";
|
|
128
|
+
export { toInternal } from "./router/router-interfaces.js";
|
|
1136
129
|
|
|
1137
130
|
export function createRouter<TEnv = any>(
|
|
1138
131
|
options: RSCRouterOptions<TEnv> = {},
|
|
@@ -1147,38 +140,77 @@ export function createRouter<TEnv = any>(
|
|
|
1147
140
|
notFound,
|
|
1148
141
|
onError,
|
|
1149
142
|
cache,
|
|
143
|
+
cacheProfiles: cacheProfilesOption,
|
|
1150
144
|
theme: themeOption,
|
|
1151
145
|
urls: urlsOption,
|
|
1152
146
|
$$routeNames: staticRouteNames,
|
|
147
|
+
$$sourceFile: injectedSourceFile,
|
|
1153
148
|
nonce,
|
|
1154
149
|
version,
|
|
150
|
+
prefetchCacheTTL: prefetchCacheTTLOption,
|
|
1155
151
|
warmup: warmupOption,
|
|
1156
|
-
allowDebugManifest: allowDebugManifestOption =
|
|
152
|
+
allowDebugManifest: allowDebugManifestOption = false,
|
|
153
|
+
telemetry: telemetrySink,
|
|
154
|
+
ssr: ssrOption,
|
|
155
|
+
timeout: timeoutShorthand,
|
|
156
|
+
timeouts: timeoutsOption,
|
|
157
|
+
onTimeout,
|
|
158
|
+
originCheck: originCheckOption,
|
|
1157
159
|
} = options;
|
|
1158
160
|
|
|
1159
|
-
//
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
161
|
+
// Resolve telemetry sink (no-op when not configured)
|
|
162
|
+
const telemetry = resolveSink(telemetrySink);
|
|
163
|
+
|
|
164
|
+
// Resolve cache profiles: merge user config with guaranteed default profile.
|
|
165
|
+
// This resolved map is both stored on the router (for per-request context)
|
|
166
|
+
// and written to the global registry (for DSL-time cache("profileName")).
|
|
167
|
+
const resolvedCacheProfiles = resolveCacheProfiles(cacheProfilesOption);
|
|
168
|
+
setCacheProfiles(resolvedCacheProfiles);
|
|
169
|
+
|
|
170
|
+
// Source file: prefer Vite-injected path (zero cost), fall back to
|
|
171
|
+
// stack trace parsing for non-Vite environments (e.g. tests).
|
|
172
|
+
let __sourceFile: string | undefined = injectedSourceFile;
|
|
173
|
+
if (!__sourceFile) {
|
|
174
|
+
try {
|
|
175
|
+
const stack = new Error().stack;
|
|
176
|
+
if (stack) {
|
|
177
|
+
const lines = stack.split("\n");
|
|
178
|
+
for (const line of lines) {
|
|
179
|
+
const match = line.match(/\((.+?\.(ts|tsx|js|jsx)):\d+:\d+\)/);
|
|
180
|
+
if (
|
|
181
|
+
match &&
|
|
182
|
+
!match[1].endsWith("/router.ts") &&
|
|
183
|
+
!match[1].includes("@rangojs/router") &&
|
|
184
|
+
!match[1].includes("node_modules")
|
|
185
|
+
) {
|
|
186
|
+
__sourceFile = match[1].startsWith("file:")
|
|
187
|
+
? match[1].slice(5)
|
|
188
|
+
: match[1];
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
1172
191
|
}
|
|
1173
192
|
}
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
193
|
+
} catch {}
|
|
194
|
+
}
|
|
1176
195
|
|
|
1177
196
|
// Router ID priority: explicit id > Vite-injected $$id > counter fallback.
|
|
1178
197
|
// $$id is a hash of filename+line injected by the Vite transform at compile
|
|
1179
198
|
// time, so it's stable across build/runtime regardless of module evaluation
|
|
1180
199
|
// order (unlike the counter which depends on import order).
|
|
1181
|
-
const routerId =
|
|
200
|
+
const routerId =
|
|
201
|
+
userProvidedId ?? injectedId ?? `router_${nextRouterAutoId()}`;
|
|
202
|
+
|
|
203
|
+
// Resolve prefetch cache TTL (default: 300 seconds / 5 minutes)
|
|
204
|
+
// Clamp to a non-negative integer for valid Cache-Control max-age.
|
|
205
|
+
const rawTTL =
|
|
206
|
+
prefetchCacheTTLOption !== undefined ? prefetchCacheTTLOption : 300;
|
|
207
|
+
const prefetchCacheTTLSeconds =
|
|
208
|
+
rawTTL === false ? 0 : Math.max(0, Math.floor(rawTTL));
|
|
209
|
+
const prefetchCacheTTL = prefetchCacheTTLSeconds * 1000;
|
|
210
|
+
const prefetchCacheControl: string | false =
|
|
211
|
+
prefetchCacheTTLSeconds === 0
|
|
212
|
+
? false
|
|
213
|
+
: `private, max-age=${prefetchCacheTTLSeconds}`;
|
|
1182
214
|
|
|
1183
215
|
// Resolve warmup enabled flag (default: true)
|
|
1184
216
|
const warmupEnabled = warmupOption !== false;
|
|
@@ -1188,15 +220,29 @@ export function createRouter<TEnv = any>(
|
|
|
1188
220
|
? resolveThemeConfig(themeOption)
|
|
1189
221
|
: null;
|
|
1190
222
|
|
|
223
|
+
// Resolve timeout config (merge shorthand + structured)
|
|
224
|
+
const resolvedTimeouts = resolveTimeouts(timeoutShorthand, timeoutsOption);
|
|
225
|
+
|
|
1191
226
|
/**
|
|
1192
227
|
* Wrapper for invokeOnError that binds the router's onError callback.
|
|
1193
228
|
* Uses the shared utility from router/error-handling.ts for consistent behavior.
|
|
229
|
+
*
|
|
230
|
+
* Deduplicates via per-request WeakSet stored on the ALS request context.
|
|
231
|
+
* A closure-level WeakSet would silently swallow errors if the same object
|
|
232
|
+
* instance is thrown across separate requests (e.g. a singleton error).
|
|
1194
233
|
*/
|
|
1195
234
|
function callOnError(
|
|
1196
235
|
error: unknown,
|
|
1197
236
|
phase: ErrorPhase,
|
|
1198
237
|
context: Parameters<typeof invokeOnError<TEnv>>[3],
|
|
1199
238
|
): void {
|
|
239
|
+
if (error != null && typeof error === "object") {
|
|
240
|
+
const reportedErrors = _getRequestContext()?._reportedErrors;
|
|
241
|
+
if (reportedErrors) {
|
|
242
|
+
if (reportedErrors.has(error)) return;
|
|
243
|
+
reportedErrors.add(error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
1200
246
|
invokeOnError(onError, error, phase, context, "Router");
|
|
1201
247
|
}
|
|
1202
248
|
|
|
@@ -1239,6 +285,18 @@ export function createRouter<TEnv = any>(
|
|
|
1239
285
|
handler = patternOrMiddleware;
|
|
1240
286
|
}
|
|
1241
287
|
|
|
288
|
+
// Prevent "use cache" functions from being used as middleware.
|
|
289
|
+
// They return data/JSX and do not call next() — silently accepting
|
|
290
|
+
// them would be a confusing no-op.
|
|
291
|
+
if (isCachedFunction(handler)) {
|
|
292
|
+
throw new Error(
|
|
293
|
+
`A "use cache" function cannot be used as middleware. ` +
|
|
294
|
+
`Cached functions return data and do not participate in the ` +
|
|
295
|
+
`middleware chain. Remove the "use cache" directive or use a ` +
|
|
296
|
+
`regular middleware function instead.`,
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
1242
300
|
// If mount-scoped, prepend mount prefix to pattern
|
|
1243
301
|
let fullPattern = pattern;
|
|
1244
302
|
if (mountPrefix && pattern) {
|
|
@@ -1264,836 +322,261 @@ export function createRouter<TEnv = any>(
|
|
|
1264
322
|
regex,
|
|
1265
323
|
paramNames,
|
|
1266
324
|
handler,
|
|
1267
|
-
mountPrefix,
|
|
1268
|
-
});
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
// Track all registered routes with their prefixes for reverse()
|
|
1272
|
-
const mergedRouteMap: Record<string, string> = {};
|
|
1273
|
-
|
|
1274
|
-
// Lazy precomputed entries lookup: rebuilt when per-router data arrives.
|
|
1275
|
-
// In production multi-router setups, per-router data is loaded lazily via
|
|
1276
|
-
// ensureRouterManifest(). At createRouter() time the data isn't available yet,
|
|
1277
|
-
// so we defer building the Map until first use and invalidate when the
|
|
1278
|
-
// per-router source changes.
|
|
1279
|
-
let precomputedByPrefix: Map<string, Record<string, string>> | null = null;
|
|
1280
|
-
let precomputedSource: Array<{ staticPrefix: string; routes: Record<string, string> }> | null | undefined;
|
|
1281
|
-
|
|
1282
|
-
function getPrecomputedByPrefix(): Map<string, Record<string, string>> | null {
|
|
1283
|
-
const current = getRouterPrecomputedEntries(routerId) ?? getPrecomputedEntries();
|
|
1284
|
-
if (current !== precomputedSource) {
|
|
1285
|
-
precomputedSource = current;
|
|
1286
|
-
precomputedByPrefix = current
|
|
1287
|
-
? new Map(current.map((e) => [e.staticPrefix, e.routes]))
|
|
1288
|
-
: null;
|
|
1289
|
-
}
|
|
1290
|
-
return precomputedByPrefix;
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
// Wrapper to pass debugPerformance to external createMetricsStore
|
|
1295
|
-
const getMetricsStore = () => createMetricsStore(debugPerformance);
|
|
1296
|
-
|
|
1297
|
-
// Wrapper to pass defaults to error/notFound boundary finders
|
|
1298
|
-
const findNearestErrorBoundary = (entry: EntryData | null) =>
|
|
1299
|
-
findErrorBoundary(entry, defaultErrorBoundary);
|
|
1300
|
-
|
|
1301
|
-
const findNearestNotFoundBoundary = (entry: EntryData | null) =>
|
|
1302
|
-
findNotFoundBoundary(entry, defaultNotFoundBoundary);
|
|
1303
|
-
|
|
1304
|
-
// Helper to get handleStore from request context
|
|
1305
|
-
const getHandleStore = (): HandleStore | undefined => {
|
|
1306
|
-
return getRequestContext()?._handleStore;
|
|
1307
|
-
};
|
|
1308
|
-
|
|
1309
|
-
// Track a pending handler promise (non-blocking)
|
|
1310
|
-
const trackHandler = <T>(promise: Promise<T>): Promise<T> => {
|
|
1311
|
-
const store = getHandleStore();
|
|
1312
|
-
return store ? store.track(promise) : promise;
|
|
1313
|
-
};
|
|
1314
|
-
|
|
1315
|
-
// Wrapper for wrapLoaderWithErrorHandling that uses router's error boundary finder
|
|
1316
|
-
// Includes onError callback for loader error notification
|
|
1317
|
-
function wrapLoaderPromise<T>(
|
|
1318
|
-
promise: Promise<T>,
|
|
1319
|
-
entry: EntryData,
|
|
1320
|
-
segmentId: string,
|
|
1321
|
-
pathname: string,
|
|
1322
|
-
errorContext?: {
|
|
1323
|
-
request: Request;
|
|
1324
|
-
url: URL;
|
|
1325
|
-
routeKey?: string;
|
|
1326
|
-
params?: Record<string, string>;
|
|
1327
|
-
env?: TEnv;
|
|
1328
|
-
isPartial?: boolean;
|
|
1329
|
-
requestStartTime?: number;
|
|
1330
|
-
},
|
|
1331
|
-
): Promise<LoaderDataResult<T>> {
|
|
1332
|
-
return wrapLoaderWithErrorHandling(
|
|
1333
|
-
promise,
|
|
1334
|
-
entry,
|
|
1335
|
-
segmentId,
|
|
1336
|
-
pathname,
|
|
1337
|
-
findNearestErrorBoundary,
|
|
1338
|
-
createErrorInfo,
|
|
1339
|
-
// Invoke onError when loader fails
|
|
1340
|
-
errorContext
|
|
1341
|
-
? (error, ctx) => {
|
|
1342
|
-
callOnError(error, "loader", {
|
|
1343
|
-
request: errorContext.request,
|
|
1344
|
-
url: errorContext.url,
|
|
1345
|
-
routeKey: errorContext.routeKey,
|
|
1346
|
-
params: errorContext.params,
|
|
1347
|
-
segmentId: ctx.segmentId,
|
|
1348
|
-
segmentType: "loader",
|
|
1349
|
-
loaderName: ctx.loaderName,
|
|
1350
|
-
env: errorContext.env,
|
|
1351
|
-
isPartial: errorContext.isPartial,
|
|
1352
|
-
handledByBoundary: ctx.handledByBoundary,
|
|
1353
|
-
requestStartTime: errorContext.requestStartTime,
|
|
1354
|
-
});
|
|
1355
|
-
}
|
|
1356
|
-
: undefined,
|
|
1357
|
-
);
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
// Dependencies object for extracted segment resolution functions.
|
|
1361
|
-
// Captures closure-bound helpers from createRouter.
|
|
1362
|
-
const segmentDeps: SegmentResolutionDeps<TEnv> = {
|
|
1363
|
-
wrapLoaderPromise,
|
|
1364
|
-
trackHandler,
|
|
1365
|
-
findNearestErrorBoundary,
|
|
1366
|
-
findNearestNotFoundBoundary,
|
|
1367
|
-
callOnError,
|
|
1368
|
-
};
|
|
1369
|
-
|
|
1370
|
-
// Match API dependencies
|
|
1371
|
-
const matchApiDeps: MatchApiDeps<TEnv> = {
|
|
1372
|
-
findMatch: (pathname: string, ms?: any) => findMatch(pathname, ms),
|
|
1373
|
-
getMetricsStore,
|
|
1374
|
-
findInterceptForRoute: (routeKey, parentEntry, selectorContext, isAction) =>
|
|
1375
|
-
findInterceptForRoute(routeKey, parentEntry, selectorContext, isAction),
|
|
1376
|
-
callOnError,
|
|
1377
|
-
findNearestErrorBoundary,
|
|
1378
|
-
getRouteMap: () => getRouterManifest(routerId) ?? getGlobalRouteMap(),
|
|
1379
|
-
};
|
|
1380
|
-
|
|
1381
|
-
// Thin wrappers that bind the deps to extracted functions.
|
|
1382
|
-
// These maintain the same signatures as the original inline functions
|
|
1383
|
-
// so that RouterContext and call sites don't need to change.
|
|
1384
|
-
|
|
1385
|
-
function resolveAllSegments(
|
|
1386
|
-
entries: EntryData[],
|
|
1387
|
-
routeKey: string,
|
|
1388
|
-
params: Record<string, string>,
|
|
1389
|
-
context: HandlerContext<any, TEnv>,
|
|
1390
|
-
loaderPromises: Map<string, Promise<any>>,
|
|
1391
|
-
options?: { skipLoaders?: boolean },
|
|
1392
|
-
) {
|
|
1393
|
-
return _resolveAllSegments(entries, routeKey, params, context, loaderPromises, segmentDeps, options);
|
|
1394
|
-
}
|
|
1395
|
-
|
|
1396
|
-
function resolveLoadersOnly(
|
|
1397
|
-
entries: EntryData[],
|
|
1398
|
-
context: HandlerContext<any, TEnv>,
|
|
1399
|
-
) {
|
|
1400
|
-
return _resolveLoadersOnly(entries, context, segmentDeps);
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
function resolveLoadersOnlyWithRevalidation(
|
|
1404
|
-
entries: EntryData[],
|
|
1405
|
-
context: HandlerContext<any, TEnv>,
|
|
1406
|
-
clientSegmentIds: Set<string>,
|
|
1407
|
-
prevParams: Record<string, string>,
|
|
1408
|
-
request: Request,
|
|
1409
|
-
prevUrl: URL,
|
|
1410
|
-
nextUrl: URL,
|
|
1411
|
-
routeKey: string,
|
|
1412
|
-
actionContext?: { actionId?: string; actionUrl?: URL; actionResult?: any; formData?: FormData },
|
|
1413
|
-
) {
|
|
1414
|
-
return _resolveLoadersOnlyWithRevalidation(
|
|
1415
|
-
entries, context, clientSegmentIds, prevParams, request,
|
|
1416
|
-
prevUrl, nextUrl, routeKey, segmentDeps, actionContext,
|
|
1417
|
-
);
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
function buildEntryRevalidateMap(entries: EntryData[]) {
|
|
1421
|
-
return _buildEntryRevalidateMap(entries);
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
function resolveAllSegmentsWithRevalidation(
|
|
1425
|
-
entries: EntryData[],
|
|
1426
|
-
routeKey: string,
|
|
1427
|
-
params: Record<string, string>,
|
|
1428
|
-
context: HandlerContext<any, TEnv>,
|
|
1429
|
-
clientSegmentSet: Set<string>,
|
|
1430
|
-
prevParams: Record<string, string>,
|
|
1431
|
-
request: Request,
|
|
1432
|
-
prevUrl: URL,
|
|
1433
|
-
nextUrl: URL,
|
|
1434
|
-
loaderPromises: Map<string, Promise<any>>,
|
|
1435
|
-
actionContext: { actionId?: string; actionUrl?: URL; actionResult?: any; formData?: FormData } | undefined,
|
|
1436
|
-
interceptResult: { intercept: InterceptEntry; entry: EntryData } | null,
|
|
1437
|
-
localRouteName: string,
|
|
1438
|
-
pathname: string,
|
|
1439
|
-
) {
|
|
1440
|
-
return _resolveAllSegmentsWithRevalidation(
|
|
1441
|
-
entries, routeKey, params, context, clientSegmentSet, prevParams, request,
|
|
1442
|
-
prevUrl, nextUrl, loaderPromises, actionContext, interceptResult,
|
|
1443
|
-
localRouteName, pathname, segmentDeps,
|
|
1444
|
-
);
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
function findInterceptForRoute(
|
|
1448
|
-
targetRouteKey: string,
|
|
1449
|
-
fromEntry: EntryData | null,
|
|
1450
|
-
selectorContext: InterceptSelectorContext | null = null,
|
|
1451
|
-
isAction: boolean = false,
|
|
1452
|
-
) {
|
|
1453
|
-
return _findInterceptForRoute(targetRouteKey, fromEntry, selectorContext, isAction);
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
function resolveInterceptEntry(
|
|
1457
|
-
interceptEntry: InterceptEntry,
|
|
1458
|
-
parentEntry: EntryData,
|
|
1459
|
-
params: Record<string, string>,
|
|
1460
|
-
context: HandlerContext<any, TEnv>,
|
|
1461
|
-
belongsToRoute: boolean = true,
|
|
1462
|
-
revalidationContext?: any,
|
|
1463
|
-
) {
|
|
1464
|
-
return _resolveInterceptEntry(
|
|
1465
|
-
interceptEntry, parentEntry, params, context, belongsToRoute,
|
|
1466
|
-
segmentDeps, revalidationContext,
|
|
1467
|
-
);
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
function resolveInterceptLoadersOnly(
|
|
1471
|
-
interceptEntry: InterceptEntry,
|
|
1472
|
-
parentEntry: EntryData,
|
|
1473
|
-
params: Record<string, string>,
|
|
1474
|
-
context: HandlerContext<any, TEnv>,
|
|
1475
|
-
belongsToRoute: boolean = true,
|
|
1476
|
-
revalidationContext: any,
|
|
1477
|
-
) {
|
|
1478
|
-
return _resolveInterceptLoadersOnly(
|
|
1479
|
-
interceptEntry, parentEntry, params, context, belongsToRoute,
|
|
1480
|
-
segmentDeps, revalidationContext,
|
|
1481
|
-
);
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
|
-
// Detect lazy includes in handler result and create placeholder entries
|
|
1485
|
-
// Lazy includes are IncludeItem with lazy: true and _lazyContext
|
|
1486
|
-
// Moved to outer scope so it can be reused by evaluateLazyEntry for nested includes
|
|
1487
|
-
function findLazyIncludes(items: AllUseItems[]): Array<{
|
|
1488
|
-
prefix: string;
|
|
1489
|
-
patterns: UrlPatterns<TEnv>;
|
|
1490
|
-
context: {
|
|
1491
|
-
urlPrefix: string;
|
|
1492
|
-
namePrefix: string | undefined;
|
|
1493
|
-
parent: unknown;
|
|
1494
|
-
};
|
|
1495
|
-
}> {
|
|
1496
|
-
const lazyItems: Array<{
|
|
1497
|
-
prefix: string;
|
|
1498
|
-
patterns: UrlPatterns<TEnv>;
|
|
1499
|
-
context: {
|
|
1500
|
-
urlPrefix: string;
|
|
1501
|
-
namePrefix: string | undefined;
|
|
1502
|
-
parent: unknown;
|
|
1503
|
-
};
|
|
1504
|
-
}> = [];
|
|
1505
|
-
|
|
1506
|
-
for (const item of items) {
|
|
1507
|
-
if (!item) continue;
|
|
1508
|
-
if (item.type === "include") {
|
|
1509
|
-
const includeItem = item as IncludeItem;
|
|
1510
|
-
if (includeItem.lazy === true && includeItem._lazyContext) {
|
|
1511
|
-
lazyItems.push({
|
|
1512
|
-
prefix: includeItem.prefix,
|
|
1513
|
-
patterns: includeItem.patterns as UrlPatterns<TEnv>,
|
|
1514
|
-
context: includeItem._lazyContext,
|
|
1515
|
-
});
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
// Recursively check nested items (in layouts, etc.)
|
|
1519
|
-
if ((item as any).uses && Array.isArray((item as any).uses)) {
|
|
1520
|
-
lazyItems.push(...findLazyIncludes((item as any).uses));
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
return lazyItems;
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1527
|
-
/**
|
|
1528
|
-
* Evaluate a lazy entry's patterns and populate its routes
|
|
1529
|
-
* This runs the lazy patterns handler and updates the entry in-place
|
|
1530
|
-
* Also detects nested lazy includes and registers them as new entries
|
|
1531
|
-
*/
|
|
1532
|
-
function evaluateLazyEntry(entry: RouteEntry<TEnv>): void {
|
|
1533
|
-
if (!entry.lazy || entry.lazyEvaluated || !entry.lazyPatterns) {
|
|
1534
|
-
return;
|
|
1535
|
-
}
|
|
1536
|
-
|
|
1537
|
-
// Check for pre-computed routes from build-time data.
|
|
1538
|
-
// Only leaf nodes (no nested includes) are precomputed, so entries with
|
|
1539
|
-
// nested lazy includes fall through to the handler below.
|
|
1540
|
-
// When multiple entries share the same staticPrefix (e.g., several
|
|
1541
|
-
// include("/", ...) calls), the precomputed data merges all their routes
|
|
1542
|
-
// into one entry. Assigning that merged set to the first matching entry
|
|
1543
|
-
// causes findMatch to pick the wrong handler for routes belonging to a
|
|
1544
|
-
// different include. Skip the shortcut when the prefix is shared.
|
|
1545
|
-
const currentPrecomputed = getPrecomputedByPrefix();
|
|
1546
|
-
if (currentPrecomputed) {
|
|
1547
|
-
const routes = currentPrecomputed.get(entry.staticPrefix);
|
|
1548
|
-
if (routes) {
|
|
1549
|
-
const prefixIsShared = routesEntries.filter(
|
|
1550
|
-
(e) => e.staticPrefix === entry.staticPrefix,
|
|
1551
|
-
).length > 1;
|
|
1552
|
-
if (!prefixIsShared) {
|
|
1553
|
-
entry.lazyEvaluated = true;
|
|
1554
|
-
entry.routes = routes as ResolvedRouteMap<any>;
|
|
1555
|
-
for (const [name, pattern] of Object.entries(routes)) {
|
|
1556
|
-
mergedRouteMap[name] = pattern;
|
|
1557
|
-
}
|
|
1558
|
-
registerRouteMap(mergedRouteMap);
|
|
1559
|
-
return;
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
// Mark as evaluated immediately to prevent concurrent evaluation.
|
|
1565
|
-
// JS is single-threaded but handlers.handler() could theoretically yield,
|
|
1566
|
-
// and the while-loop in findMatch retries after evaluation.
|
|
1567
|
-
entry.lazyEvaluated = true;
|
|
1568
|
-
|
|
1569
|
-
const lazyPatterns = entry.lazyPatterns as UrlPatterns<TEnv>;
|
|
1570
|
-
const lazyContext = entry.lazyContext;
|
|
1571
|
-
|
|
1572
|
-
// Create a new context for evaluating the lazy patterns
|
|
1573
|
-
const manifest = new Map<string, EntryData>();
|
|
1574
|
-
const patterns = new Map<string, string>();
|
|
1575
|
-
const patternsByPrefix = new Map<string, Map<string, string>>();
|
|
1576
|
-
const trailingSlashMap = new Map<string, TrailingSlashMode>();
|
|
1577
|
-
|
|
1578
|
-
// Capture the handler result to detect nested lazy includes
|
|
1579
|
-
let handlerResult: AllUseItems[] = [];
|
|
1580
|
-
|
|
1581
|
-
// Merge captured counters from include() to maintain consistent
|
|
1582
|
-
// shortCode indices with sibling entries from pattern extraction
|
|
1583
|
-
const lazyCounters: Record<string, number> = {};
|
|
1584
|
-
if (lazyContext && (lazyContext as any).counters) {
|
|
1585
|
-
const captured = (lazyContext as any).counters as Record<string, number>;
|
|
1586
|
-
for (const [key, value] of Object.entries(captured)) {
|
|
1587
|
-
lazyCounters[key] = value;
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
RSCRouterContext.run(
|
|
1592
|
-
{
|
|
1593
|
-
manifest,
|
|
1594
|
-
patterns,
|
|
1595
|
-
patternsByPrefix,
|
|
1596
|
-
trailingSlash: trailingSlashMap,
|
|
1597
|
-
namespace: "lazy",
|
|
1598
|
-
parent: (lazyContext?.parent as EntryData | null) ?? null,
|
|
1599
|
-
counters: lazyCounters,
|
|
1600
|
-
},
|
|
1601
|
-
() => {
|
|
1602
|
-
// Run the lazy patterns handler with the original context prefixes
|
|
1603
|
-
// The prefix comes from the IncludeItem stored in lazyPatterns
|
|
1604
|
-
const includePrefix = (entry as any)._lazyPrefix || "";
|
|
1605
|
-
const fullPrefix = (lazyContext?.urlPrefix || "") + includePrefix;
|
|
1606
|
-
|
|
1607
|
-
if (fullPrefix || lazyContext?.namePrefix) {
|
|
1608
|
-
runWithPrefixes(fullPrefix, lazyContext?.namePrefix, () => {
|
|
1609
|
-
handlerResult = lazyPatterns.handler() as AllUseItems[];
|
|
1610
|
-
});
|
|
1611
|
-
} else {
|
|
1612
|
-
handlerResult = lazyPatterns.handler() as AllUseItems[];
|
|
1613
|
-
}
|
|
1614
|
-
},
|
|
1615
|
-
);
|
|
1616
|
-
|
|
1617
|
-
// Populate the entry's routes from the patterns
|
|
1618
|
-
const routesObject: Record<string, string> = {};
|
|
1619
|
-
for (const [name, pattern] of patterns.entries()) {
|
|
1620
|
-
routesObject[name] = pattern;
|
|
1621
|
-
// Also add to merged route map for reverse() support
|
|
1622
|
-
const existingPattern = mergedRouteMap[name];
|
|
1623
|
-
if (existingPattern !== undefined && existingPattern !== pattern) {
|
|
1624
|
-
console.warn(
|
|
1625
|
-
`[@rangojs/router] Route name conflict: "${name}" already maps to "${existingPattern}", ` +
|
|
1626
|
-
`overwriting with "${pattern}" (from lazy include). Use unique route names to avoid this.`,
|
|
1627
|
-
);
|
|
1628
|
-
}
|
|
1629
|
-
mergedRouteMap[name] = pattern;
|
|
1630
|
-
}
|
|
1631
|
-
|
|
1632
|
-
// Update the entry in-place
|
|
1633
|
-
entry.routes = routesObject as ResolvedRouteMap<any>;
|
|
1634
|
-
|
|
1635
|
-
// Note: Do NOT clear lazyPatterns/lazyContext here.
|
|
1636
|
-
// loadManifest() needs them on every request to re-run the handler
|
|
1637
|
-
// in the correct AsyncLocalStorage context (Store.manifest).
|
|
1638
|
-
|
|
1639
|
-
// Update trailing slash config if available
|
|
1640
|
-
if (trailingSlashMap.size > 0) {
|
|
1641
|
-
entry.trailingSlash = Object.fromEntries(trailingSlashMap);
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
// Detect nested lazy includes and register them as new entries
|
|
1645
|
-
const nestedLazyIncludes = findLazyIncludes(handlerResult);
|
|
1646
|
-
for (const lazyInclude of nestedLazyIncludes) {
|
|
1647
|
-
// Compute the full URL prefix (combining parent prefix if any)
|
|
1648
|
-
const fullPrefix = lazyInclude.context.urlPrefix
|
|
1649
|
-
? lazyInclude.context.urlPrefix + lazyInclude.prefix
|
|
1650
|
-
: lazyInclude.prefix;
|
|
1651
|
-
|
|
1652
|
-
const nestedEntry: RouteEntry<TEnv> & { _lazyPrefix?: string } = {
|
|
1653
|
-
prefix: "",
|
|
1654
|
-
staticPrefix: extractStaticPrefix(fullPrefix),
|
|
1655
|
-
routes: {} as ResolvedRouteMap<any>, // Empty until first match
|
|
1656
|
-
trailingSlash: entry.trailingSlash,
|
|
1657
|
-
handler: (lazyInclude.patterns as UrlPatterns<TEnv>).handler,
|
|
1658
|
-
mountIndex: entry.mountIndex,
|
|
1659
|
-
// Lazy evaluation fields
|
|
1660
|
-
lazy: true,
|
|
1661
|
-
lazyPatterns: lazyInclude.patterns,
|
|
1662
|
-
lazyContext: lazyInclude.context,
|
|
1663
|
-
lazyEvaluated: false,
|
|
1664
|
-
// Store the include prefix for evaluation
|
|
1665
|
-
_lazyPrefix: lazyInclude.prefix,
|
|
1666
|
-
};
|
|
1667
|
-
// Insert nested lazy entry before any entry whose staticPrefix is a
|
|
1668
|
-
// prefix of (but shorter than) this lazy entry's staticPrefix.
|
|
1669
|
-
// This ensures more specific lazy includes are matched before
|
|
1670
|
-
// less specific eager entries (e.g., "/href/nested" before "/href/:id").
|
|
1671
|
-
const nestedPrefix = nestedEntry.staticPrefix;
|
|
1672
|
-
let insertIndex = routesEntries.length;
|
|
1673
|
-
if (nestedPrefix) {
|
|
1674
|
-
for (let i = 0; i < routesEntries.length; i++) {
|
|
1675
|
-
const existing = routesEntries[i]!;
|
|
1676
|
-
if (
|
|
1677
|
-
nestedPrefix.startsWith(existing.staticPrefix) &&
|
|
1678
|
-
nestedPrefix.length > existing.staticPrefix.length
|
|
1679
|
-
) {
|
|
1680
|
-
insertIndex = i;
|
|
1681
|
-
break;
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
routesEntries.splice(insertIndex, 0, nestedEntry);
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
// Re-register route map for runtime reverse() usage
|
|
1689
|
-
registerRouteMap(mergedRouteMap);
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
// Single-entry cache for findMatch to avoid redundant matching within the same request.
|
|
1693
|
-
// previewMatch and match both call findMatch with the same pathname — this ensures
|
|
1694
|
-
// the route matching work (which may check thousands of routes) only happens once.
|
|
1695
|
-
let lastFindMatchPathname: string | null = null;
|
|
1696
|
-
let lastFindMatchResult: RouteMatchResult<TEnv> | null = null;
|
|
1697
|
-
|
|
1698
|
-
// Wrapper for findMatch that uses routesEntries
|
|
1699
|
-
// Handles lazy evaluation by evaluating lazy entries on first match.
|
|
1700
|
-
// Phase 1: try O(path_length) trie match.
|
|
1701
|
-
// Phase 2: fall back to regex iteration.
|
|
1702
|
-
function findMatch(
|
|
1703
|
-
pathname: string,
|
|
1704
|
-
ms?: MetricsStore,
|
|
1705
|
-
): RouteMatchResult<TEnv> | null {
|
|
1706
|
-
// Return cached result if same pathname (avoids double-match per request)
|
|
1707
|
-
if (lastFindMatchPathname === pathname) {
|
|
1708
|
-
return lastFindMatchResult;
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
|
-
// Helper to push sub-metrics
|
|
1712
|
-
const pushMetric = ms
|
|
1713
|
-
? (label: string, start: number) => {
|
|
1714
|
-
ms.metrics.push({
|
|
1715
|
-
label,
|
|
1716
|
-
duration: performance.now() - start,
|
|
1717
|
-
startTime: start - ms.requestStart,
|
|
1718
|
-
});
|
|
1719
|
-
}
|
|
1720
|
-
: undefined;
|
|
1721
|
-
|
|
1722
|
-
// Phase 1: Try trie match (O(path_length))
|
|
1723
|
-
// Prefer per-router trie (isolated) over global trie (merged).
|
|
1724
|
-
const routeTrie = getRouterTrie(routerId) ?? getRouteTrie();
|
|
1725
|
-
if (routeTrie) {
|
|
1726
|
-
const trieStart = performance.now();
|
|
1727
|
-
const trieResult = tryTrieMatch(routeTrie, pathname);
|
|
1728
|
-
pushMetric?.("match:trie", trieStart);
|
|
1729
|
-
|
|
1730
|
-
if (trieResult) {
|
|
1731
|
-
// Find the RouteEntry that contains this route.
|
|
1732
|
-
// Multiple entries can share the same staticPrefix (e.g., several
|
|
1733
|
-
// include("/", patterns) calls all produce staticPrefix=""). Evaluate
|
|
1734
|
-
// each candidate and pick the one whose routes include the matched key.
|
|
1735
|
-
const entryStart = performance.now();
|
|
1736
|
-
let entry: RouteEntry<TEnv> | undefined;
|
|
1737
|
-
let fallbackEntry: RouteEntry<TEnv> | undefined;
|
|
1738
|
-
|
|
1739
|
-
for (const e of routesEntries) {
|
|
1740
|
-
if (e.staticPrefix !== trieResult.sp) continue;
|
|
1741
|
-
if (!fallbackEntry) fallbackEntry = e;
|
|
1742
|
-
evaluateLazyEntry(e);
|
|
1743
|
-
if (
|
|
1744
|
-
e.routes &&
|
|
1745
|
-
trieResult.routeKey in (e.routes as Record<string, unknown>)
|
|
1746
|
-
) {
|
|
1747
|
-
entry = e;
|
|
1748
|
-
break;
|
|
1749
|
-
}
|
|
1750
|
-
}
|
|
1751
|
-
|
|
1752
|
-
// If no entry had the route in its routes map, use the first matching
|
|
1753
|
-
// entry as fallback (handles main entry with inline routes not yet
|
|
1754
|
-
// reflected in its routes object).
|
|
1755
|
-
if (!entry) entry = fallbackEntry;
|
|
1756
|
-
|
|
1757
|
-
// If entry not found (nested include not yet discovered), evaluate parent
|
|
1758
|
-
if (!entry) {
|
|
1759
|
-
const parent = routesEntries.find(
|
|
1760
|
-
(e) =>
|
|
1761
|
-
trieResult.sp.startsWith(e.staticPrefix) &&
|
|
1762
|
-
e.staticPrefix !== trieResult.sp,
|
|
1763
|
-
);
|
|
1764
|
-
if (parent) {
|
|
1765
|
-
const lazyStart = performance.now();
|
|
1766
|
-
evaluateLazyEntry(parent);
|
|
1767
|
-
pushMetric?.("match:lazy-eval", lazyStart);
|
|
1768
|
-
}
|
|
1769
|
-
entry = routesEntries.find((e) => e.staticPrefix === trieResult.sp);
|
|
1770
|
-
}
|
|
1771
|
-
pushMetric?.("match:entry-resolve", entryStart);
|
|
1772
|
-
|
|
1773
|
-
if (entry) {
|
|
1774
|
-
lastFindMatchPathname = pathname;
|
|
1775
|
-
lastFindMatchResult = {
|
|
1776
|
-
entry,
|
|
1777
|
-
routeKey: trieResult.routeKey,
|
|
1778
|
-
params: trieResult.params,
|
|
1779
|
-
optionalParams: new Set(trieResult.optionalParams || []),
|
|
1780
|
-
redirectTo: trieResult.redirectTo,
|
|
1781
|
-
ancestry: trieResult.ancestry,
|
|
1782
|
-
...(trieResult.pr ? { pr: true } : {}),
|
|
1783
|
-
...(trieResult.pt ? { pt: true } : {}),
|
|
1784
|
-
...(trieResult.responseType ? { responseType: trieResult.responseType } : {}),
|
|
1785
|
-
...(trieResult.negotiateVariants ? { negotiateVariants: trieResult.negotiateVariants } : {}),
|
|
1786
|
-
...(trieResult.rscFirst ? { rscFirst: true } : {}),
|
|
1787
|
-
};
|
|
1788
|
-
return lastFindMatchResult;
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
// Phase 2: Fall back to existing matching (regex iteration)
|
|
1794
|
-
const regexStart = performance.now();
|
|
1795
|
-
let result = findRouteMatch(pathname, routesEntries);
|
|
1796
|
-
|
|
1797
|
-
// If we hit a lazy entry that needs evaluation, evaluate and retry.
|
|
1798
|
-
// Cap iterations to prevent infinite loops from pathological nesting.
|
|
1799
|
-
const MAX_LAZY_ITERATIONS = 100;
|
|
1800
|
-
let iterations = 0;
|
|
1801
|
-
while (isLazyEvaluationNeeded(result)) {
|
|
1802
|
-
if (++iterations > MAX_LAZY_ITERATIONS) {
|
|
1803
|
-
console.error(
|
|
1804
|
-
`[@rangojs/router] Exceeded ${MAX_LAZY_ITERATIONS} lazy evaluation iterations ` +
|
|
1805
|
-
`for pathname "${pathname}". This likely indicates circular lazy includes.`,
|
|
1806
|
-
);
|
|
1807
|
-
lastFindMatchPathname = pathname;
|
|
1808
|
-
lastFindMatchResult = null;
|
|
1809
|
-
return null;
|
|
1810
|
-
}
|
|
1811
|
-
evaluateLazyEntry(result.lazyEntry);
|
|
1812
|
-
result = findRouteMatch(pathname, routesEntries);
|
|
1813
|
-
}
|
|
1814
|
-
pushMetric?.("match:regex-fallback", regexStart);
|
|
1815
|
-
|
|
1816
|
-
lastFindMatchPathname = pathname;
|
|
1817
|
-
lastFindMatchResult = result;
|
|
1818
|
-
return result;
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
/**
|
|
1823
|
-
* Build-time pre-render match. Resolves segments with a BuildContext
|
|
1824
|
-
* (no request/env/headers/cookies), skipping middleware and loaders.
|
|
1825
|
-
*/
|
|
1826
|
-
async function matchForPrerender(
|
|
1827
|
-
pathname: string,
|
|
1828
|
-
params: Record<string, string>,
|
|
1829
|
-
): Promise<{
|
|
1830
|
-
segments: SerializedSegmentData[];
|
|
1831
|
-
handles: Record<string, SegmentHandleData>;
|
|
1832
|
-
routeName: string;
|
|
1833
|
-
params: Record<string, string>;
|
|
1834
|
-
} | null> {
|
|
1835
|
-
// 1. Find the matching route entry
|
|
1836
|
-
const matched = findMatch(pathname);
|
|
1837
|
-
if (!matched) return null;
|
|
1838
|
-
|
|
1839
|
-
// Use params from trie match if available, fall back to provided params
|
|
1840
|
-
const matchedParams = matched.params ?? params;
|
|
1841
|
-
|
|
1842
|
-
// Build a minimal RouterContext for loadManifest/traverseBack
|
|
1843
|
-
const routerCtx: RouterContext<TEnv> = {
|
|
1844
|
-
findMatch,
|
|
1845
|
-
loadManifest,
|
|
1846
|
-
traverseBack,
|
|
1847
|
-
createHandlerContext,
|
|
1848
|
-
setupLoaderAccess,
|
|
1849
|
-
setupLoaderAccessSilent,
|
|
1850
|
-
getContext,
|
|
1851
|
-
getMetricsStore,
|
|
1852
|
-
createCacheScope,
|
|
1853
|
-
findInterceptForRoute,
|
|
1854
|
-
resolveAllSegmentsWithRevalidation,
|
|
1855
|
-
resolveInterceptEntry,
|
|
1856
|
-
evaluateRevalidation,
|
|
1857
|
-
getRequestContext,
|
|
1858
|
-
resolveAllSegments,
|
|
1859
|
-
createHandleStore,
|
|
1860
|
-
buildEntryRevalidateMap,
|
|
1861
|
-
resolveLoadersOnlyWithRevalidation,
|
|
1862
|
-
resolveInterceptLoadersOnly,
|
|
1863
|
-
resolveLoadersOnly,
|
|
1864
|
-
};
|
|
1865
|
-
|
|
1866
|
-
return runWithRouterContext(routerCtx, async () => {
|
|
1867
|
-
// 2. Load the manifest entry tree
|
|
1868
|
-
const manifestEntry = await loadManifest(
|
|
1869
|
-
matched.entry,
|
|
1870
|
-
matched.routeKey,
|
|
1871
|
-
pathname,
|
|
1872
|
-
undefined,
|
|
1873
|
-
false,
|
|
1874
|
-
);
|
|
1875
|
-
|
|
1876
|
-
// 3. Build ancestor chain [root, ..., route]
|
|
1877
|
-
const entries: EntryData[] = [];
|
|
1878
|
-
for (const entry of traverseBack(manifestEntry)) {
|
|
1879
|
-
entries.push(entry);
|
|
1880
|
-
}
|
|
1881
|
-
|
|
1882
|
-
// 4. Create handle store for collecting handle data
|
|
1883
|
-
const handleStore = createHandleStore();
|
|
1884
|
-
|
|
1885
|
-
// 5. Create a minimal request context with the handle store
|
|
1886
|
-
const stubRes = new Response(null, { status: 200 });
|
|
1887
|
-
const minimalRequestContext: RequestContext<TEnv> = {
|
|
1888
|
-
env: {} as TEnv,
|
|
1889
|
-
request: new Request("http://prerender" + pathname),
|
|
1890
|
-
url: new URL("http://prerender" + pathname),
|
|
1891
|
-
pathname,
|
|
1892
|
-
searchParams: new URLSearchParams(),
|
|
1893
|
-
var: {},
|
|
1894
|
-
get: () => undefined as any,
|
|
1895
|
-
set: () => {},
|
|
1896
|
-
params: matchedParams,
|
|
1897
|
-
res: stubRes,
|
|
1898
|
-
cookie: () => undefined,
|
|
1899
|
-
cookies: () => ({}),
|
|
1900
|
-
setCookie: () => {},
|
|
1901
|
-
deleteCookie: () => {},
|
|
1902
|
-
header: () => {},
|
|
1903
|
-
use: (() => {
|
|
1904
|
-
throw new Error("use() not available during pre-rendering");
|
|
1905
|
-
}) as any,
|
|
1906
|
-
method: "GET",
|
|
1907
|
-
_handleStore: handleStore,
|
|
1908
|
-
waitUntil: () => {},
|
|
1909
|
-
onResponse: () => {},
|
|
1910
|
-
_onResponseCallbacks: [],
|
|
1911
|
-
};
|
|
325
|
+
mountPrefix,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
1912
328
|
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
handleStore,
|
|
1919
|
-
);
|
|
329
|
+
// Track all registered routes with their prefixes for reverse().
|
|
330
|
+
// Seed from injected NamedRoutes so reverse() works at module load time
|
|
331
|
+
// for routes that come from lazy includes.
|
|
332
|
+
const mergedRouteMap: Record<string, string> =
|
|
333
|
+
flattenNamedRoutes(staticRouteNames);
|
|
1920
334
|
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
const loaderPromises = new Map<string, Promise<any>>();
|
|
1926
|
-
const allSegments = await resolveAllSegments(
|
|
1927
|
-
entries,
|
|
1928
|
-
matched.routeKey,
|
|
1929
|
-
matchedParams,
|
|
1930
|
-
buildCtx,
|
|
1931
|
-
loaderPromises,
|
|
1932
|
-
{ skipLoaders: true },
|
|
1933
|
-
);
|
|
335
|
+
// Track names that came from the static seed so we can silently overwrite
|
|
336
|
+
// them during routes() registration. The gen file may be stale during HMR,
|
|
337
|
+
// so conflicts between seeded and runtime-registered values are expected.
|
|
338
|
+
const seededNames = new Set(Object.keys(mergedRouteMap));
|
|
1934
339
|
|
|
1935
|
-
|
|
1936
|
-
|
|
340
|
+
// Lazy precomputed entries lookup: rebuilt when per-router data arrives.
|
|
341
|
+
// In production multi-router setups, per-router data is loaded lazily via
|
|
342
|
+
// ensureRouterManifest(). At createRouter() time the data isn't available yet,
|
|
343
|
+
// so we defer building the Map until first use and invalidate when the
|
|
344
|
+
// per-router source changes.
|
|
345
|
+
let precomputedByPrefix: Map<string, Record<string, string>> | null = null;
|
|
346
|
+
let precomputedSource:
|
|
347
|
+
| Array<{ staticPrefix: string; routes: Record<string, string> }>
|
|
348
|
+
| null
|
|
349
|
+
| undefined;
|
|
350
|
+
|
|
351
|
+
function getPrecomputedByPrefix(): Map<
|
|
352
|
+
string,
|
|
353
|
+
Record<string, string>
|
|
354
|
+
> | null {
|
|
355
|
+
const current =
|
|
356
|
+
getRouterPrecomputedEntries(routerId) ?? getPrecomputedEntries();
|
|
357
|
+
if (current !== precomputedSource) {
|
|
358
|
+
precomputedSource = current;
|
|
359
|
+
precomputedByPrefix = current
|
|
360
|
+
? new Map(current.map((e) => [e.staticPrefix, e.routes]))
|
|
361
|
+
: null;
|
|
362
|
+
}
|
|
363
|
+
return precomputedByPrefix;
|
|
364
|
+
}
|
|
1937
365
|
|
|
1938
|
-
|
|
1939
|
-
|
|
366
|
+
// Wrapper to pass debugPerformance to external createMetricsStore.
|
|
367
|
+
// Also checks per-request flag set by ctx.debugPerformance() in middleware.
|
|
368
|
+
const getMetricsStore = () => {
|
|
369
|
+
const reqCtx = _getRequestContext();
|
|
370
|
+
const enabled = debugPerformance || !!reqCtx?._debugPerformance;
|
|
371
|
+
if (!enabled) return undefined;
|
|
372
|
+
if (!reqCtx) {
|
|
373
|
+
return createMetricsStore(true);
|
|
374
|
+
}
|
|
375
|
+
reqCtx._metricsStore ??= createMetricsStore(true);
|
|
376
|
+
return reqCtx._metricsStore;
|
|
377
|
+
};
|
|
1940
378
|
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
379
|
+
// Wrapper to pass defaults to error/notFound boundary finders
|
|
380
|
+
const findNearestErrorBoundary = (entry: EntryData | null) =>
|
|
381
|
+
findErrorBoundary(entry, defaultErrorBoundary);
|
|
1944
382
|
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
for (const seg of nonLoaderSegments) {
|
|
1948
|
-
const segHandles = handleStore.getDataForSegment(seg.id);
|
|
1949
|
-
if (Object.keys(segHandles).length > 0) {
|
|
1950
|
-
handles[seg.id] = segHandles;
|
|
1951
|
-
}
|
|
1952
|
-
}
|
|
383
|
+
const findNearestNotFoundBoundary = (entry: EntryData | null) =>
|
|
384
|
+
findNotFoundBoundary(entry, defaultNotFoundBoundary);
|
|
1953
385
|
|
|
1954
|
-
|
|
1955
|
-
|
|
386
|
+
// Helper to get handleStore from request context
|
|
387
|
+
const getHandleStore = (): HandleStore | undefined => {
|
|
388
|
+
return _getRequestContext()?._handleStore;
|
|
389
|
+
};
|
|
1956
390
|
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
391
|
+
// Track a pending handler promise (non-blocking).
|
|
392
|
+
// Attaches a side-effect .catch() to report streaming handler errors to onError
|
|
393
|
+
// without altering the rejection chain (React's streaming error boundary still handles it).
|
|
394
|
+
const trackHandler = <T>(
|
|
395
|
+
promise: Promise<T>,
|
|
396
|
+
errorContext?: {
|
|
397
|
+
segmentId?: string;
|
|
398
|
+
segmentType?: string;
|
|
399
|
+
},
|
|
400
|
+
): Promise<T> => {
|
|
401
|
+
const store = getHandleStore();
|
|
402
|
+
const tracked = store ? store.track(promise) : promise;
|
|
403
|
+
|
|
404
|
+
// Report streaming handler errors to onError as a side-effect.
|
|
405
|
+
// The rejection still propagates to the RSC stream for client error boundaries.
|
|
406
|
+
// Captures request context eagerly (closure) so the catch handler has full context.
|
|
407
|
+
const reqCtx = _getRequestContext();
|
|
408
|
+
if (reqCtx && onError) {
|
|
409
|
+
tracked.catch((error) => {
|
|
410
|
+
callOnError(error, "handler", {
|
|
411
|
+
request: reqCtx.request,
|
|
412
|
+
url: reqCtx.url,
|
|
413
|
+
routeKey: reqCtx._routeName,
|
|
414
|
+
params: reqCtx.params as Record<string, string>,
|
|
415
|
+
env: reqCtx.env as TEnv,
|
|
416
|
+
segmentId: errorContext?.segmentId,
|
|
417
|
+
segmentType: errorContext?.segmentType as any,
|
|
418
|
+
handledByBoundary: true,
|
|
419
|
+
});
|
|
1963
420
|
});
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
421
|
+
}
|
|
1966
422
|
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
*
|
|
1970
|
-
* Uses generator middleware pipeline for clean separation of concerns:
|
|
1971
|
-
* - cache-lookup: Check cache first
|
|
1972
|
-
* - segment-resolution: Resolve segments on cache miss
|
|
1973
|
-
* - cache-store: Store results in cache
|
|
1974
|
-
* - background-revalidation: SWR revalidation
|
|
1975
|
-
*/
|
|
1976
|
-
async function match(request: Request, env: TEnv): Promise<MatchResult> {
|
|
1977
|
-
// Build RouterContext with all closure functions needed by middleware
|
|
1978
|
-
const routerCtx: RouterContext<TEnv> = {
|
|
1979
|
-
findMatch,
|
|
1980
|
-
loadManifest,
|
|
1981
|
-
traverseBack,
|
|
1982
|
-
createHandlerContext,
|
|
1983
|
-
setupLoaderAccess,
|
|
1984
|
-
setupLoaderAccessSilent,
|
|
1985
|
-
getContext,
|
|
1986
|
-
getMetricsStore,
|
|
1987
|
-
createCacheScope,
|
|
1988
|
-
findInterceptForRoute,
|
|
1989
|
-
resolveAllSegmentsWithRevalidation,
|
|
1990
|
-
resolveInterceptEntry,
|
|
1991
|
-
evaluateRevalidation,
|
|
1992
|
-
getRequestContext,
|
|
1993
|
-
resolveAllSegments,
|
|
1994
|
-
createHandleStore,
|
|
1995
|
-
buildEntryRevalidateMap,
|
|
1996
|
-
resolveLoadersOnlyWithRevalidation,
|
|
1997
|
-
resolveInterceptLoadersOnly,
|
|
1998
|
-
resolveLoadersOnly,
|
|
1999
|
-
};
|
|
423
|
+
return tracked;
|
|
424
|
+
};
|
|
2000
425
|
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
426
|
+
// Wrapper for wrapLoaderWithErrorHandling that uses router's error boundary finder
|
|
427
|
+
// Includes onError callback for loader error notification and telemetry emission.
|
|
428
|
+
function wrapLoaderPromise<T>(
|
|
429
|
+
promise: Promise<T>,
|
|
430
|
+
entry: EntryData,
|
|
431
|
+
segmentId: string,
|
|
432
|
+
pathname: string,
|
|
433
|
+
errorContext?: {
|
|
434
|
+
request: Request;
|
|
435
|
+
url: URL;
|
|
436
|
+
routeKey?: string;
|
|
437
|
+
params?: Record<string, string>;
|
|
438
|
+
env?: TEnv;
|
|
439
|
+
isPartial?: boolean;
|
|
440
|
+
requestStartTime?: number;
|
|
441
|
+
},
|
|
442
|
+
): Promise<LoaderDataResult<T>> {
|
|
443
|
+
const loaderStart = telemetrySink ? performance.now() : 0;
|
|
444
|
+
const loaderRequestId = telemetrySink
|
|
445
|
+
? errorContext?.request
|
|
446
|
+
? getRequestId(errorContext.request)
|
|
447
|
+
: undefined
|
|
448
|
+
: undefined;
|
|
449
|
+
if (telemetrySink) {
|
|
450
|
+
const loaderName = segmentId.split(".").pop() || "unknown";
|
|
451
|
+
safeEmit(telemetry, {
|
|
452
|
+
type: "loader.start",
|
|
453
|
+
timestamp: loaderStart,
|
|
454
|
+
requestId: loaderRequestId,
|
|
455
|
+
segmentId,
|
|
456
|
+
loaderName,
|
|
457
|
+
pathname,
|
|
458
|
+
});
|
|
459
|
+
}
|
|
2018
460
|
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
461
|
+
const result = wrapLoaderWithErrorHandling(
|
|
462
|
+
promise,
|
|
463
|
+
entry,
|
|
464
|
+
segmentId,
|
|
465
|
+
pathname,
|
|
466
|
+
findNearestErrorBoundary,
|
|
467
|
+
createErrorInfo,
|
|
468
|
+
// Invoke onError when loader fails
|
|
469
|
+
errorContext
|
|
470
|
+
? (error, ctx) => {
|
|
471
|
+
callOnError(error, "loader", {
|
|
472
|
+
request: errorContext.request,
|
|
473
|
+
url: errorContext.url,
|
|
474
|
+
routeKey: errorContext.routeKey,
|
|
475
|
+
params: errorContext.params,
|
|
476
|
+
segmentId: ctx.segmentId,
|
|
477
|
+
segmentType: "loader",
|
|
478
|
+
loaderName: ctx.loaderName,
|
|
479
|
+
env: errorContext.env,
|
|
480
|
+
isPartial: errorContext.isPartial,
|
|
481
|
+
handledByBoundary: ctx.handledByBoundary,
|
|
482
|
+
requestStartTime: errorContext.requestStartTime,
|
|
483
|
+
});
|
|
484
|
+
if (telemetrySink) {
|
|
485
|
+
const errorObj =
|
|
486
|
+
error instanceof Error ? error : new Error(String(error));
|
|
487
|
+
safeEmit(telemetry, {
|
|
488
|
+
type: "loader.error",
|
|
489
|
+
timestamp: performance.now(),
|
|
490
|
+
requestId: loaderRequestId,
|
|
491
|
+
segmentId: ctx.segmentId,
|
|
492
|
+
loaderName: ctx.loaderName,
|
|
493
|
+
pathname,
|
|
494
|
+
error: errorObj,
|
|
495
|
+
handledByBoundary: ctx.handledByBoundary,
|
|
2034
496
|
});
|
|
2035
|
-
throw sanitizeError(error);
|
|
2036
497
|
}
|
|
2037
|
-
}
|
|
2038
|
-
|
|
498
|
+
}
|
|
499
|
+
: undefined,
|
|
2039
500
|
);
|
|
2040
|
-
}
|
|
2041
501
|
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
),
|
|
2061
|
-
);
|
|
502
|
+
// Emit loader.end after the promise settles (fire-and-forget)
|
|
503
|
+
if (telemetrySink) {
|
|
504
|
+
const loaderName = segmentId.split(".").pop() || "unknown";
|
|
505
|
+
result.then((r) => {
|
|
506
|
+
safeEmit(telemetry, {
|
|
507
|
+
type: "loader.end",
|
|
508
|
+
timestamp: performance.now(),
|
|
509
|
+
requestId: loaderRequestId,
|
|
510
|
+
segmentId,
|
|
511
|
+
loaderName,
|
|
512
|
+
pathname,
|
|
513
|
+
durationMs: performance.now() - loaderStart,
|
|
514
|
+
ok: r.ok,
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return result;
|
|
2062
520
|
}
|
|
2063
521
|
|
|
522
|
+
// Dependencies object for extracted segment resolution functions.
|
|
523
|
+
// Captures closure-bound helpers from createRouter.
|
|
524
|
+
const segmentDeps: SegmentResolutionDeps<TEnv> = {
|
|
525
|
+
wrapLoaderPromise,
|
|
526
|
+
trackHandler,
|
|
527
|
+
findNearestErrorBoundary,
|
|
528
|
+
findNearestNotFoundBoundary,
|
|
529
|
+
callOnError,
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
// Match API dependencies
|
|
533
|
+
const matchApiDeps: MatchApiDeps<TEnv> = {
|
|
534
|
+
findMatch: (pathname: string, ms?: any) => findMatch(pathname, ms),
|
|
535
|
+
getMetricsStore,
|
|
536
|
+
findInterceptForRoute: (routeKey, parentEntry, selectorContext, isAction) =>
|
|
537
|
+
findInterceptForRoute(routeKey, parentEntry, selectorContext, isAction),
|
|
538
|
+
callOnError,
|
|
539
|
+
findNearestErrorBoundary,
|
|
540
|
+
// Use per-router manifest when available, otherwise the static named map
|
|
541
|
+
// seeded into mergedRouteMap at router creation.
|
|
542
|
+
getRouteMap: () => getRouterManifest(routerId) ?? mergedRouteMap,
|
|
543
|
+
};
|
|
2064
544
|
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
545
|
+
// Create segment resolution wrappers bound to segmentDeps
|
|
546
|
+
const {
|
|
547
|
+
resolveAllSegments,
|
|
548
|
+
resolveLoadersOnly,
|
|
549
|
+
resolveLoadersOnlyWithRevalidation,
|
|
550
|
+
buildEntryRevalidateMap,
|
|
551
|
+
resolveAllSegmentsWithRevalidation,
|
|
552
|
+
findInterceptForRoute,
|
|
553
|
+
resolveInterceptEntry,
|
|
554
|
+
resolveInterceptLoadersOnly,
|
|
555
|
+
} = createSegmentWrappers<TEnv>(segmentDeps);
|
|
556
|
+
|
|
557
|
+
// Lazy evaluation deps — captures closure state for extracted evaluateLazyEntry
|
|
558
|
+
const lazyEvalDeps: LazyEvalDeps<TEnv> = {
|
|
559
|
+
routesEntries,
|
|
560
|
+
mergedRouteMap,
|
|
561
|
+
nextMountIndex: () => mountIndex++,
|
|
562
|
+
getPrecomputedByPrefix,
|
|
563
|
+
routerId,
|
|
564
|
+
};
|
|
2071
565
|
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
env: TEnv,
|
|
2075
|
-
actionContext?: { actionId?: string; actionUrl?: URL; actionResult?: any; formData?: FormData },
|
|
2076
|
-
) {
|
|
2077
|
-
return _createMatchContextForPartial(request, env, matchApiDeps, findInterceptForRoute, actionContext);
|
|
566
|
+
function evaluateLazyEntry(entry: RouteEntry<TEnv>): void {
|
|
567
|
+
_evaluateLazyEntry(entry, lazyEvalDeps);
|
|
2078
568
|
}
|
|
2079
569
|
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
async function matchPartial(
|
|
2091
|
-
request: Request,
|
|
2092
|
-
context: TEnv,
|
|
2093
|
-
actionContext?: ActionContext,
|
|
2094
|
-
): Promise<MatchResult | null> {
|
|
2095
|
-
// Build RouterContext with all closure functions needed by middleware
|
|
2096
|
-
const routerCtx: RouterContext<TEnv> = {
|
|
570
|
+
// Create findMatch with single-entry cache, bound to router state
|
|
571
|
+
const findMatch = createFindMatch<TEnv>({
|
|
572
|
+
routesEntries,
|
|
573
|
+
evaluateLazyEntry,
|
|
574
|
+
routerId,
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
// Build a RouterContext once — shared by match, matchPartial, matchForPrerender
|
|
578
|
+
function buildRouterContext(): RouterContext<TEnv> {
|
|
579
|
+
return {
|
|
2097
580
|
findMatch,
|
|
2098
581
|
loadManifest,
|
|
2099
582
|
traverseBack,
|
|
@@ -2113,464 +596,259 @@ export function createRouter<TEnv = any>(
|
|
|
2113
596
|
buildEntryRevalidateMap,
|
|
2114
597
|
resolveLoadersOnlyWithRevalidation,
|
|
2115
598
|
resolveInterceptLoadersOnly,
|
|
599
|
+
resolveLoadersOnly,
|
|
600
|
+
telemetry: telemetrySink,
|
|
2116
601
|
};
|
|
2117
|
-
|
|
2118
|
-
return runWithRouterLogContext(
|
|
2119
|
-
{ request, transaction: "matchPartial" },
|
|
2120
|
-
() =>
|
|
2121
|
-
runWithRouterContext(routerCtx, async () =>
|
|
2122
|
-
withRouterLogScope("matchPartial", async () => {
|
|
2123
|
-
const ctx = await createMatchContextForPartial(
|
|
2124
|
-
request,
|
|
2125
|
-
context,
|
|
2126
|
-
actionContext,
|
|
2127
|
-
);
|
|
2128
|
-
if (!ctx) return null;
|
|
2129
|
-
|
|
2130
|
-
try {
|
|
2131
|
-
const state = createPipelineState();
|
|
2132
|
-
const pipeline = createMatchPartialPipeline(ctx, state);
|
|
2133
|
-
return await collectMatchResult(pipeline, ctx, state);
|
|
2134
|
-
} catch (error) {
|
|
2135
|
-
if (error instanceof Response) throw error;
|
|
2136
|
-
// Report unhandled errors during partial match pipeline
|
|
2137
|
-
callOnError(error, actionContext ? "action" : "revalidation", {
|
|
2138
|
-
request,
|
|
2139
|
-
url: ctx.url,
|
|
2140
|
-
env: context,
|
|
2141
|
-
actionId: actionContext?.actionId,
|
|
2142
|
-
isPartial: true,
|
|
2143
|
-
handledByBoundary: false,
|
|
2144
|
-
});
|
|
2145
|
-
throw sanitizeError(error);
|
|
2146
|
-
}
|
|
2147
|
-
}),
|
|
2148
|
-
),
|
|
2149
|
-
);
|
|
2150
602
|
}
|
|
2151
603
|
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
): Promise<{
|
|
2160
|
-
routeMiddleware?: Array<{
|
|
2161
|
-
handler: import("./router/middleware.js").MiddlewareFn;
|
|
2162
|
-
params: Record<string, string>;
|
|
2163
|
-
}>;
|
|
2164
|
-
responseType?: string;
|
|
2165
|
-
handler?: Function;
|
|
2166
|
-
params?: Record<string, string>;
|
|
2167
|
-
negotiated?: boolean;
|
|
2168
|
-
} | null> {
|
|
2169
|
-
return runWithRouterLogContext(
|
|
2170
|
-
{ request, transaction: "previewMatch" },
|
|
2171
|
-
async () =>
|
|
2172
|
-
withRouterLogScope("previewMatch", async () => {
|
|
2173
|
-
const url = new URL(request.url);
|
|
2174
|
-
const pathname = url.pathname;
|
|
2175
|
-
|
|
2176
|
-
// Quick route matching
|
|
2177
|
-
const matched = findMatch(pathname);
|
|
2178
|
-
if (!matched) {
|
|
2179
|
-
return null;
|
|
2180
|
-
}
|
|
2181
|
-
|
|
2182
|
-
// Skip redirect check - will be handled in full match
|
|
2183
|
-
if (matched.redirectTo) {
|
|
2184
|
-
return { routeMiddleware: undefined };
|
|
2185
|
-
}
|
|
604
|
+
// Prerender/static match deps (bind closure state for extracted functions)
|
|
605
|
+
const prerenderDeps = {
|
|
606
|
+
findMatch,
|
|
607
|
+
buildRouterContext,
|
|
608
|
+
mergedRouteMap,
|
|
609
|
+
resolveAllSegments,
|
|
610
|
+
};
|
|
2186
611
|
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
612
|
+
async function matchForPrerender(
|
|
613
|
+
pathname: string,
|
|
614
|
+
params: Record<string, string>,
|
|
615
|
+
buildVars?: Record<string, any>,
|
|
616
|
+
isPassthroughRoute?: boolean,
|
|
617
|
+
) {
|
|
618
|
+
return _matchForPrerender(
|
|
2191
619
|
pathname,
|
|
2192
|
-
|
|
2193
|
-
|
|
620
|
+
params,
|
|
621
|
+
prerenderDeps,
|
|
622
|
+
buildVars,
|
|
623
|
+
isPassthroughRoute,
|
|
2194
624
|
);
|
|
625
|
+
}
|
|
2195
626
|
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
// Content negotiation: when negotiate variants exist, pick the best
|
|
2208
|
-
// handler based on the Accept header. Uses q-values and client order
|
|
2209
|
-
// as tiebreaker (matching Express/Hono behavior). RSC routes participate
|
|
2210
|
-
// as text/html candidates so browsers naturally get HTML without
|
|
2211
|
-
// special-casing.
|
|
2212
|
-
if (matched.negotiateVariants && matched.negotiateVariants.length > 0) {
|
|
2213
|
-
const acceptEntries = parseAcceptTypes(request.headers.get("accept") || "");
|
|
2214
|
-
|
|
2215
|
-
// Build candidate list preserving definition order.
|
|
2216
|
-
// For wildcard (*/*) and no-Accept fallback, the first candidate wins.
|
|
2217
|
-
const variants = matched.negotiateVariants;
|
|
2218
|
-
let candidates: Array<{ routeKey: string; responseType: string }>;
|
|
2219
|
-
if (responseType) {
|
|
2220
|
-
// Primary is response-type — include it as a candidate
|
|
2221
|
-
candidates = [...variants, { routeKey: matched.routeKey, responseType }];
|
|
2222
|
-
} else {
|
|
2223
|
-
// Primary is RSC — insert as text/html candidate in definition order
|
|
2224
|
-
const rscCandidate = { routeKey: matched.routeKey, responseType: RSC_RESPONSE_TYPE };
|
|
2225
|
-
candidates = matched.rscFirst
|
|
2226
|
-
? [rscCandidate, ...variants]
|
|
2227
|
-
: [...variants, rscCandidate];
|
|
2228
|
-
}
|
|
2229
|
-
|
|
2230
|
-
const variant = pickNegotiateVariant(acceptEntries, candidates);
|
|
2231
|
-
|
|
2232
|
-
// If the winner is RSC, fall through to default RSC handling
|
|
2233
|
-
if (variant.responseType === RSC_RESPONSE_TYPE) {
|
|
2234
|
-
// Fall through — RSC won negotiation
|
|
2235
|
-
} else if (responseType && variant.routeKey === matched.routeKey) {
|
|
2236
|
-
// Fall through — response-type primary won, already set
|
|
2237
|
-
} else {
|
|
2238
|
-
const negotiateEntry = await loadManifest(
|
|
2239
|
-
matched.entry,
|
|
2240
|
-
variant.routeKey,
|
|
2241
|
-
pathname,
|
|
2242
|
-
undefined,
|
|
2243
|
-
false,
|
|
2244
|
-
);
|
|
2245
|
-
return {
|
|
2246
|
-
routeMiddleware: routeMiddleware.length > 0 ? routeMiddleware : undefined,
|
|
2247
|
-
responseType: variant.responseType,
|
|
2248
|
-
handler: negotiateEntry.type === "route" ? negotiateEntry.handler : undefined,
|
|
2249
|
-
params: matched.params,
|
|
2250
|
-
negotiated: true,
|
|
2251
|
-
};
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
|
-
|
|
2255
|
-
// If we passed through the negotiation block (variants exist), mark as
|
|
2256
|
-
// negotiated so the handler sets Vary: Accept on the response.
|
|
2257
|
-
const hasVariants = matched.negotiateVariants && matched.negotiateVariants.length > 0;
|
|
2258
|
-
return {
|
|
2259
|
-
routeMiddleware: routeMiddleware.length > 0 ? routeMiddleware : undefined,
|
|
2260
|
-
...(responseType ? {
|
|
2261
|
-
responseType,
|
|
2262
|
-
handler: manifestEntry.type === "route" ? manifestEntry.handler : undefined,
|
|
2263
|
-
params: matched.params,
|
|
2264
|
-
} : {}),
|
|
2265
|
-
...(hasVariants ? { negotiated: true } : {}),
|
|
2266
|
-
};
|
|
2267
|
-
}),
|
|
627
|
+
async function renderStaticSegment(
|
|
628
|
+
handler: Function,
|
|
629
|
+
handlerId: string,
|
|
630
|
+
routeName?: string,
|
|
631
|
+
) {
|
|
632
|
+
return _renderStaticSegment<TEnv>(
|
|
633
|
+
handler,
|
|
634
|
+
handlerId,
|
|
635
|
+
mergedRouteMap,
|
|
636
|
+
routeName,
|
|
2268
637
|
);
|
|
2269
638
|
}
|
|
2270
639
|
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
// Merge routes into the reverse map
|
|
2282
|
-
// Keys stay unchanged for composability - only URL patterns get prefixed
|
|
2283
|
-
const routeEntries = routes as Record<string, string>;
|
|
2284
|
-
for (const [key, pattern] of Object.entries(routeEntries)) {
|
|
2285
|
-
// Build prefixed pattern: "/shop" + "/cart" -> "/shop/cart"
|
|
2286
|
-
// Root prefix "/" is a no-op — don't double the leading slash.
|
|
2287
|
-
const effectivePrefix = prefix === "/" ? "" : prefix;
|
|
2288
|
-
const prefixedPattern =
|
|
2289
|
-
effectivePrefix && pattern !== "/"
|
|
2290
|
-
? `${effectivePrefix}${pattern}`
|
|
2291
|
-
: effectivePrefix && pattern === "/"
|
|
2292
|
-
? effectivePrefix
|
|
2293
|
-
: pattern;
|
|
2294
|
-
|
|
2295
|
-
// Runtime validation: warn if key already exists with different pattern
|
|
2296
|
-
const existingPattern = mergedRouteMap[key];
|
|
2297
|
-
if (
|
|
2298
|
-
existingPattern !== undefined &&
|
|
2299
|
-
existingPattern !== prefixedPattern
|
|
2300
|
-
) {
|
|
2301
|
-
console.warn(
|
|
2302
|
-
`[rsc-router] Route key conflict: "${key}" already maps to "${existingPattern}", ` +
|
|
2303
|
-
`overwriting with "${prefixedPattern}". Use unique key names to avoid this.`,
|
|
2304
|
-
);
|
|
2305
|
-
}
|
|
2306
|
-
|
|
2307
|
-
// Use original key - enables reusable route modules
|
|
2308
|
-
mergedRouteMap[key] = prefixedPattern;
|
|
2309
|
-
}
|
|
2310
|
-
|
|
2311
|
-
// Auto-register route map for runtime reverse() usage
|
|
2312
|
-
registerRouteMap(mergedRouteMap);
|
|
2313
|
-
|
|
2314
|
-
// Extract trailing slash config if present (attached by route())
|
|
2315
|
-
const trailingSlashConfig = (routes as any).__trailingSlash as
|
|
2316
|
-
| Record<string, TrailingSlashMode>
|
|
2317
|
-
| undefined;
|
|
2318
|
-
|
|
2319
|
-
// Create builder object so .use() can return it
|
|
2320
|
-
const builder: RouteBuilder<RouteDefinition, TEnv, any, TNewRoutes> = {
|
|
2321
|
-
use(
|
|
2322
|
-
patternOrMiddleware: string | MiddlewareFn<TEnv>,
|
|
2323
|
-
middleware?: MiddlewareFn<TEnv>,
|
|
2324
|
-
) {
|
|
2325
|
-
// Mount-scoped middleware - prefix is the mount prefix
|
|
2326
|
-
addMiddleware(patternOrMiddleware, middleware, prefix || null);
|
|
2327
|
-
return builder;
|
|
2328
|
-
},
|
|
2329
|
-
|
|
2330
|
-
map(
|
|
2331
|
-
handler:
|
|
2332
|
-
| ((
|
|
2333
|
-
helpers: InlineRouteHelpers<TNewRoutes, TEnv>,
|
|
2334
|
-
) => Array<AllUseItems>)
|
|
2335
|
-
| (() =>
|
|
2336
|
-
| Array<AllUseItems>
|
|
2337
|
-
| Promise<{ default: () => Array<AllUseItems> }>
|
|
2338
|
-
| Promise<() => Array<AllUseItems>>),
|
|
2339
|
-
) {
|
|
2340
|
-
// Store handler as-is - detection happens at call time based on return type
|
|
2341
|
-
// Both patterns use the same signature:
|
|
2342
|
-
// - Inline: ({ route }) => [...] - receives helpers, returns Array
|
|
2343
|
-
// - Lazy: () => import(...) - ignores helpers, returns Promise
|
|
2344
|
-
routesEntries.push({
|
|
2345
|
-
prefix,
|
|
2346
|
-
staticPrefix: extractStaticPrefix(prefix),
|
|
2347
|
-
routes: routes as ResolvedRouteMap<any>,
|
|
2348
|
-
trailingSlash: trailingSlashConfig,
|
|
2349
|
-
handler: handler as any,
|
|
2350
|
-
mountIndex: currentMountIndex,
|
|
2351
|
-
});
|
|
2352
|
-
// Return router with accumulated types
|
|
2353
|
-
// At runtime this is the same object, but TypeScript tracks the accumulated route types
|
|
2354
|
-
return router as any;
|
|
2355
|
-
},
|
|
2356
|
-
|
|
2357
|
-
// Expose accumulated route map for typeof extraction
|
|
2358
|
-
get routeMap() {
|
|
2359
|
-
return mergedRouteMap as TNewRoutes;
|
|
2360
|
-
},
|
|
2361
|
-
};
|
|
640
|
+
// Create match handler functions bound to router state
|
|
641
|
+
const matchHandlers = createMatchHandlers<TEnv>({
|
|
642
|
+
buildRouterContext,
|
|
643
|
+
callOnError,
|
|
644
|
+
matchApiDeps,
|
|
645
|
+
defaultErrorBoundary,
|
|
646
|
+
findMatch,
|
|
647
|
+
findInterceptForRoute,
|
|
648
|
+
telemetry: telemetrySink,
|
|
649
|
+
});
|
|
2362
650
|
|
|
2363
|
-
|
|
2364
|
-
}
|
|
651
|
+
const { match, matchPartial, matchError, previewMatch } = matchHandlers;
|
|
2365
652
|
|
|
2366
653
|
/**
|
|
2367
654
|
* Router instance
|
|
2368
655
|
* The type system tracks accumulated routes through the builder chain
|
|
2369
656
|
* Initial TRoutes is {} (empty) to avoid poisoning accumulated types with Record<string, string>
|
|
2370
657
|
*/
|
|
2371
|
-
const router:
|
|
658
|
+
const router: RSCRouterInternal<TEnv, {}> = {
|
|
2372
659
|
__brand: RSC_ROUTER_BRAND,
|
|
2373
660
|
id: routerId,
|
|
2374
661
|
|
|
2375
|
-
routes(
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
// Note: Multiple .routes() calls are allowed for backwards compatibility
|
|
2380
|
-
// with the old map() pattern. For new code, prefer urls() with include().
|
|
2381
|
-
|
|
2382
|
-
// Check if argument is UrlPatterns (new Django-style API)
|
|
2383
|
-
// Detect by checking for handler and definitions properties
|
|
2384
|
-
if (
|
|
2385
|
-
typeof prefixOrRoutes === "object" &&
|
|
2386
|
-
prefixOrRoutes !== null &&
|
|
2387
|
-
"handler" in prefixOrRoutes &&
|
|
2388
|
-
"definitions" in prefixOrRoutes &&
|
|
2389
|
-
typeof (prefixOrRoutes as UrlPatterns<TEnv>).handler === "function"
|
|
2390
|
-
) {
|
|
2391
|
-
const urlPatterns = prefixOrRoutes as UrlPatterns<TEnv>;
|
|
2392
|
-
// Store reference for runtime manifest generation
|
|
2393
|
-
storedUrlPatterns = urlPatterns;
|
|
2394
|
-
const currentMountIndex = mountIndex++;
|
|
2395
|
-
|
|
2396
|
-
// Create manifest and patterns maps for route registration
|
|
2397
|
-
const manifest = new Map<string, EntryData>();
|
|
2398
|
-
const patterns = new Map<string, string>();
|
|
2399
|
-
const patternsByPrefix = new Map<string, Map<string, string>>();
|
|
2400
|
-
const trailingSlashMap = new Map<string, TrailingSlashMode>();
|
|
2401
|
-
|
|
2402
|
-
// Run the handler once to extract patterns for route matching.
|
|
2403
|
-
// Note: loadManifest will re-run the handler to register entries in its context.
|
|
2404
|
-
// Lazy includes are detected in the return value and handled separately.
|
|
2405
|
-
//
|
|
2406
|
-
// Pattern extraction must use the same mountIndex and MapRootLayout root
|
|
2407
|
-
// parent as loadManifest so that shortCodes produced here match those at
|
|
2408
|
-
// runtime. include() captures the current parent and counters; if those
|
|
2409
|
-
// shortCodes diverge from the runtime tree the segment reconciliation on
|
|
2410
|
-
// the client will see a full mismatch and remount the entire page.
|
|
2411
|
-
const syntheticMapRoot: EntryData = {
|
|
2412
|
-
type: "layout",
|
|
2413
|
-
id: `#synthetic-maproot-M${currentMountIndex}`,
|
|
2414
|
-
shortCode: `M${currentMountIndex}L0`,
|
|
2415
|
-
parent: null,
|
|
2416
|
-
handler: MapRootLayout,
|
|
2417
|
-
middleware: [],
|
|
2418
|
-
revalidate: [],
|
|
2419
|
-
errorBoundary: [],
|
|
2420
|
-
notFoundBoundary: [],
|
|
2421
|
-
layout: [],
|
|
2422
|
-
parallel: [],
|
|
2423
|
-
intercept: [],
|
|
2424
|
-
loader: [],
|
|
2425
|
-
};
|
|
662
|
+
routes(urlPatterns: UrlPatterns<TEnv>): any {
|
|
663
|
+
// Store reference for runtime manifest generation
|
|
664
|
+
storedUrlPatterns = urlPatterns;
|
|
665
|
+
const currentMountIndex = mountIndex++;
|
|
2426
666
|
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
667
|
+
// Create manifest and patterns maps for route registration
|
|
668
|
+
const manifest = new Map<string, EntryData>();
|
|
669
|
+
const routePatterns = new Map<string, string>();
|
|
670
|
+
const patternsByPrefix = new Map<string, Map<string, string>>();
|
|
671
|
+
const trailingSlashMap = new Map<string, TrailingSlashMode>();
|
|
672
|
+
|
|
673
|
+
// Run the handler once to extract patterns for route matching.
|
|
674
|
+
// Note: loadManifest will re-run the handler to register entries in its context.
|
|
675
|
+
// Lazy includes are detected in the return value and handled separately.
|
|
676
|
+
//
|
|
677
|
+
// Pattern extraction must use the same mountIndex and MapRootLayout root
|
|
678
|
+
// parent as loadManifest so that shortCodes produced here match those at
|
|
679
|
+
// runtime. include() captures the current parent and counters; if those
|
|
680
|
+
// shortCodes diverge from the runtime tree the segment reconciliation on
|
|
681
|
+
// the client will see a full mismatch and remount the entire page.
|
|
682
|
+
const syntheticMapRoot: EntryData = {
|
|
683
|
+
type: "layout",
|
|
684
|
+
id: `#synthetic-maproot-M${currentMountIndex}`,
|
|
685
|
+
shortCode: `M${currentMountIndex}L0`,
|
|
686
|
+
parent: null,
|
|
687
|
+
handler: MapRootLayout,
|
|
688
|
+
middleware: [],
|
|
689
|
+
revalidate: [],
|
|
690
|
+
errorBoundary: [],
|
|
691
|
+
notFoundBoundary: [],
|
|
692
|
+
layout: [],
|
|
693
|
+
parallel: {},
|
|
694
|
+
intercept: [],
|
|
695
|
+
loader: [],
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
let handlerResult: AllUseItems[] = [];
|
|
699
|
+
RSCRouterContext.run(
|
|
700
|
+
{
|
|
701
|
+
manifest,
|
|
702
|
+
patterns: routePatterns,
|
|
703
|
+
patternsByPrefix,
|
|
704
|
+
trailingSlash: trailingSlashMap,
|
|
705
|
+
namespace: "root",
|
|
706
|
+
parent: syntheticMapRoot,
|
|
707
|
+
counters: {},
|
|
708
|
+
mountIndex: currentMountIndex,
|
|
709
|
+
cacheProfiles: resolvedCacheProfiles,
|
|
710
|
+
},
|
|
711
|
+
() => {
|
|
712
|
+
handlerResult = urlPatterns.handler() as AllUseItems[];
|
|
713
|
+
},
|
|
714
|
+
);
|
|
2443
715
|
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
trailingSlashMap
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
716
|
+
// Convert trailingSlash map to object for the router
|
|
717
|
+
const trailingSlashConfig =
|
|
718
|
+
trailingSlashMap.size > 0
|
|
719
|
+
? Object.fromEntries(trailingSlashMap)
|
|
720
|
+
: undefined;
|
|
721
|
+
|
|
722
|
+
// Collect route keys that have prerender handlers (for non-trie match path)
|
|
723
|
+
let prerenderRouteKeys: Set<string> | undefined;
|
|
724
|
+
let passthroughRouteKeys: Set<string> | undefined;
|
|
725
|
+
for (const [name, entry] of manifest.entries()) {
|
|
726
|
+
if (entry.type === "route" && entry.isPrerender) {
|
|
727
|
+
if (!prerenderRouteKeys) prerenderRouteKeys = new Set();
|
|
728
|
+
prerenderRouteKeys.add(name);
|
|
729
|
+
if (entry.prerenderDef?.options?.passthrough === true) {
|
|
730
|
+
if (!passthroughRouteKeys) passthroughRouteKeys = new Set();
|
|
731
|
+
passthroughRouteKeys.add(name);
|
|
2457
732
|
}
|
|
2458
733
|
}
|
|
734
|
+
}
|
|
2459
735
|
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
const routesObject: Record<string, string> = {};
|
|
2465
|
-
for (const [name, pattern] of prefixPatterns.entries()) {
|
|
2466
|
-
routesObject[name] = pattern;
|
|
2467
|
-
}
|
|
2468
|
-
|
|
2469
|
-
routesEntries.push({
|
|
2470
|
-
// prefix is "" because patterns already include the URL prefix
|
|
2471
|
-
// (e.g., "/site/:locale/user1/:id" not just "/user1/:id")
|
|
2472
|
-
prefix: "",
|
|
2473
|
-
// staticPrefix is the actual prefix for short-circuit optimization
|
|
2474
|
-
staticPrefix: extractStaticPrefix(prefix),
|
|
2475
|
-
routes: routesObject as ResolvedRouteMap<any>,
|
|
2476
|
-
trailingSlash: trailingSlashConfig,
|
|
2477
|
-
handler: urlPatterns.handler,
|
|
2478
|
-
mountIndex: currentMountIndex,
|
|
2479
|
-
...(prerenderRouteKeys ? { prerenderRouteKeys } : {}),
|
|
2480
|
-
});
|
|
2481
|
-
}
|
|
2482
|
-
} else {
|
|
2483
|
-
// Fallback: no prefix grouping, use flat patterns map
|
|
736
|
+
// Create separate RouteEntry for each URL prefix group
|
|
737
|
+
// This enables prefix-based short-circuit optimization
|
|
738
|
+
if (patternsByPrefix.size > 0) {
|
|
739
|
+
for (const [prefix, prefixPatterns] of patternsByPrefix.entries()) {
|
|
2484
740
|
const routesObject: Record<string, string> = {};
|
|
2485
|
-
for (const [name, pattern] of
|
|
741
|
+
for (const [name, pattern] of prefixPatterns.entries()) {
|
|
2486
742
|
routesObject[name] = pattern;
|
|
2487
743
|
}
|
|
2488
744
|
|
|
2489
745
|
routesEntries.push({
|
|
746
|
+
// prefix is "" because patterns already include the URL prefix
|
|
747
|
+
// (e.g., "/site/:locale/user1/:id" not just "/user1/:id")
|
|
2490
748
|
prefix: "",
|
|
2491
|
-
staticPrefix
|
|
749
|
+
// staticPrefix is the actual prefix for short-circuit optimization
|
|
750
|
+
staticPrefix: extractStaticPrefix(prefix),
|
|
2492
751
|
routes: routesObject as ResolvedRouteMap<any>,
|
|
2493
752
|
trailingSlash: trailingSlashConfig,
|
|
2494
753
|
handler: urlPatterns.handler,
|
|
2495
754
|
mountIndex: currentMountIndex,
|
|
755
|
+
routerId,
|
|
756
|
+
cacheProfiles: resolvedCacheProfiles,
|
|
2496
757
|
...(prerenderRouteKeys ? { prerenderRouteKeys } : {}),
|
|
758
|
+
...(passthroughRouteKeys ? { passthroughRouteKeys } : {}),
|
|
2497
759
|
});
|
|
2498
760
|
}
|
|
761
|
+
} else {
|
|
762
|
+
// Fallback: no prefix grouping, use flat patterns map
|
|
763
|
+
const routesObject: Record<string, string> = {};
|
|
764
|
+
for (const [name, pattern] of routePatterns.entries()) {
|
|
765
|
+
routesObject[name] = pattern;
|
|
766
|
+
}
|
|
2499
767
|
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
}
|
|
2510
|
-
|
|
768
|
+
routesEntries.push({
|
|
769
|
+
prefix: "",
|
|
770
|
+
staticPrefix: "",
|
|
771
|
+
routes: routesObject as ResolvedRouteMap<any>,
|
|
772
|
+
trailingSlash: trailingSlashConfig,
|
|
773
|
+
handler: urlPatterns.handler,
|
|
774
|
+
mountIndex: currentMountIndex,
|
|
775
|
+
routerId,
|
|
776
|
+
cacheProfiles: resolvedCacheProfiles,
|
|
777
|
+
...(prerenderRouteKeys ? { prerenderRouteKeys } : {}),
|
|
778
|
+
...(passthroughRouteKeys ? { passthroughRouteKeys } : {}),
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// Build route map from registered patterns
|
|
783
|
+
for (const [name, pattern] of routePatterns.entries()) {
|
|
784
|
+
// Runtime validation: warn if key already exists with different pattern.
|
|
785
|
+
// Skip warning for entries that came from the static seed — the gen file
|
|
786
|
+
// can be stale during HMR, so runtime registration is authoritative.
|
|
787
|
+
const existingPattern = mergedRouteMap[name];
|
|
788
|
+
if (
|
|
789
|
+
existingPattern !== undefined &&
|
|
790
|
+
existingPattern !== pattern &&
|
|
791
|
+
!seededNames.has(name)
|
|
792
|
+
) {
|
|
793
|
+
console.warn(
|
|
794
|
+
`[@rangojs/router] Route name conflict: "${name}" already maps to "${existingPattern}", ` +
|
|
795
|
+
`overwriting with "${pattern}". Use unique route names to avoid this.`,
|
|
796
|
+
);
|
|
2511
797
|
}
|
|
798
|
+
mergedRouteMap[name] = pattern;
|
|
799
|
+
seededNames.delete(name);
|
|
800
|
+
}
|
|
2512
801
|
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
const lazyIncludes = findLazyIncludes(handlerResult);
|
|
802
|
+
// Detect lazy includes in handler result and create placeholder entries
|
|
803
|
+
const lazyIncludes = findLazyIncludes(handlerResult);
|
|
2516
804
|
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
805
|
+
// Create placeholder RouteEntry for each lazy include
|
|
806
|
+
for (const lazyInclude of lazyIncludes) {
|
|
807
|
+
// Compute the full URL prefix (combining parent prefix if any)
|
|
808
|
+
const fullPrefix = lazyInclude.context.urlPrefix
|
|
809
|
+
? lazyInclude.context.urlPrefix + lazyInclude.prefix
|
|
810
|
+
: lazyInclude.prefix;
|
|
2523
811
|
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
}
|
|
812
|
+
const lazyEntry: RouteEntry<TEnv> & { _lazyPrefix?: string } = {
|
|
813
|
+
prefix: "",
|
|
814
|
+
staticPrefix: extractStaticPrefix(fullPrefix),
|
|
815
|
+
routes: {} as ResolvedRouteMap<any>, // Empty until first match
|
|
816
|
+
trailingSlash: trailingSlashConfig,
|
|
817
|
+
handler: urlPatterns.handler,
|
|
818
|
+
mountIndex: mountIndex++,
|
|
819
|
+
routerId,
|
|
820
|
+
// Lazy evaluation fields
|
|
821
|
+
lazy: true,
|
|
822
|
+
lazyPatterns: lazyInclude.patterns,
|
|
823
|
+
lazyContext: lazyInclude.context,
|
|
824
|
+
lazyEvaluated: false,
|
|
825
|
+
_lazyPrefix: lazyInclude.prefix,
|
|
826
|
+
};
|
|
827
|
+
// Insert lazy entry before any entry whose staticPrefix is a
|
|
828
|
+
// prefix of (but shorter than) this lazy entry's staticPrefix.
|
|
829
|
+
// This ensures more specific lazy includes are matched before
|
|
830
|
+
// less specific eager entries (e.g., "/href/nested" before "/href/:id").
|
|
831
|
+
const lazyPrefix = lazyEntry.staticPrefix;
|
|
832
|
+
let insertIndex = routesEntries.length;
|
|
833
|
+
if (lazyPrefix) {
|
|
834
|
+
for (let i = 0; i < routesEntries.length; i++) {
|
|
835
|
+
const existing = routesEntries[i]!;
|
|
836
|
+
if (
|
|
837
|
+
lazyPrefix.startsWith(existing.staticPrefix) &&
|
|
838
|
+
lazyPrefix.length > existing.staticPrefix.length
|
|
839
|
+
) {
|
|
840
|
+
insertIndex = i;
|
|
841
|
+
break;
|
|
2555
842
|
}
|
|
2556
843
|
}
|
|
2557
|
-
routesEntries.splice(insertIndex, 0, lazyEntry);
|
|
2558
844
|
}
|
|
2559
|
-
|
|
2560
|
-
// Auto-register route map for runtime reverse() usage
|
|
2561
|
-
registerRouteMap(mergedRouteMap);
|
|
2562
|
-
|
|
2563
|
-
// Return the router (no .map() needed for UrlPatterns)
|
|
2564
|
-
return router;
|
|
845
|
+
routesEntries.splice(insertIndex, 0, lazyEntry);
|
|
2565
846
|
}
|
|
2566
847
|
|
|
2567
|
-
//
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
}
|
|
2572
|
-
// Otherwise, first argument is routes with empty prefix
|
|
2573
|
-
return createRouteBuilder("", prefixOrRoutes as Record<string, string>);
|
|
848
|
+
// Auto-register route map for runtime reverse() usage
|
|
849
|
+
registerRouteMap(mergedRouteMap);
|
|
850
|
+
|
|
851
|
+
return router;
|
|
2574
852
|
},
|
|
2575
853
|
|
|
2576
854
|
use(
|
|
@@ -2584,8 +862,8 @@ export function createRouter<TEnv = any>(
|
|
|
2584
862
|
|
|
2585
863
|
// Type-safe URL builder using merged route map
|
|
2586
864
|
// Types are tracked through the builder chain via TRoutes parameter
|
|
2587
|
-
//
|
|
2588
|
-
reverse: createReverse(mergedRouteMap
|
|
865
|
+
// Seeded with static route names from the generated file (injected by Vite)
|
|
866
|
+
reverse: createReverse(mergedRouteMap),
|
|
2589
867
|
|
|
2590
868
|
// Expose accumulated route map for typeof extraction
|
|
2591
869
|
// Returns {} initially, but builder chain accumulates specific route types
|
|
@@ -2608,20 +886,62 @@ export function createRouter<TEnv = any>(
|
|
|
2608
886
|
// Expose resolved theme configuration for NavigationProvider and MetaTags
|
|
2609
887
|
themeConfig: resolvedThemeConfig,
|
|
2610
888
|
|
|
889
|
+
// Expose resolved cache profiles for per-request resolution
|
|
890
|
+
cacheProfiles: resolvedCacheProfiles,
|
|
891
|
+
|
|
892
|
+
// Expose prefetch cache settings
|
|
893
|
+
prefetchCacheControl,
|
|
894
|
+
prefetchCacheTTL,
|
|
895
|
+
|
|
2611
896
|
// Expose warmup enabled flag for handler and client
|
|
2612
897
|
warmupEnabled,
|
|
2613
898
|
|
|
899
|
+
// Expose router-wide performance debugging for request-level metrics setup
|
|
900
|
+
debugPerformance,
|
|
901
|
+
|
|
2614
902
|
// Expose debug manifest flag for handler
|
|
2615
903
|
allowDebugManifest: allowDebugManifestOption,
|
|
2616
904
|
|
|
905
|
+
// Expose origin check configuration for handler (default: enabled)
|
|
906
|
+
originCheck: originCheckOption ?? true,
|
|
907
|
+
|
|
908
|
+
// Expose SSR configuration for handler
|
|
909
|
+
ssr: ssrOption,
|
|
910
|
+
|
|
911
|
+
// Expose resolved timeouts for RSC handler
|
|
912
|
+
timeouts: resolvedTimeouts,
|
|
913
|
+
onTimeout,
|
|
914
|
+
|
|
2617
915
|
// Expose global middleware for RSC handler
|
|
2618
916
|
middleware: globalMiddleware,
|
|
2619
917
|
|
|
2620
|
-
match,
|
|
918
|
+
match: (request: Request, input: RouterRequestInput<TEnv> = {}) => {
|
|
919
|
+
const env = input.env ?? ({} as TEnv);
|
|
920
|
+
return match(request, env);
|
|
921
|
+
},
|
|
2621
922
|
matchForPrerender,
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
923
|
+
renderStaticSegment,
|
|
924
|
+
matchPartial: (
|
|
925
|
+
request: Request,
|
|
926
|
+
input: RouterRequestInput<TEnv> = {},
|
|
927
|
+
actionContext?: Parameters<typeof matchPartial>[2],
|
|
928
|
+
) => {
|
|
929
|
+
const env = input.env ?? ({} as TEnv);
|
|
930
|
+
return matchPartial(request, env, actionContext);
|
|
931
|
+
},
|
|
932
|
+
matchError: (
|
|
933
|
+
request: Request,
|
|
934
|
+
input: RouterRequestInput<TEnv> | undefined,
|
|
935
|
+
error: unknown,
|
|
936
|
+
segmentType?: Parameters<typeof matchError>[3],
|
|
937
|
+
) => {
|
|
938
|
+
const env = input?.env ?? ({} as TEnv);
|
|
939
|
+
return matchError(request, env, error, segmentType);
|
|
940
|
+
},
|
|
941
|
+
previewMatch: (request: Request, input: RouterRequestInput<TEnv> = {}) => {
|
|
942
|
+
const env = input.env ?? ({} as TEnv);
|
|
943
|
+
return previewMatch(request, env);
|
|
944
|
+
},
|
|
2625
945
|
|
|
2626
946
|
// Expose nonce provider for fetch
|
|
2627
947
|
nonce,
|
|
@@ -2643,79 +963,35 @@ export function createRouter<TEnv = any>(
|
|
|
2643
963
|
let handler:
|
|
2644
964
|
| ((
|
|
2645
965
|
request: Request,
|
|
2646
|
-
|
|
966
|
+
input: RouterRequestInput<TEnv>,
|
|
2647
967
|
) => Promise<Response>)
|
|
2648
968
|
| null = null;
|
|
2649
969
|
|
|
2650
|
-
return async (
|
|
2651
|
-
request: Request,
|
|
2652
|
-
env: TEnv & { ctx?: ExecutionContext },
|
|
2653
|
-
) => {
|
|
970
|
+
return async (request: Request, input: RouterRequestInput<TEnv> = {}) => {
|
|
2654
971
|
// Trigger lazy import of per-router manifest data before route matching.
|
|
2655
972
|
// No-op if data is already loaded or no loader is registered.
|
|
2656
973
|
await ensureRouterManifest(routerId);
|
|
2657
974
|
if (!handler) {
|
|
2658
975
|
// Lazy import deferred to first request to avoid dev mode issues
|
|
2659
976
|
const { createRSCHandler } = await import("./rsc/handler.js");
|
|
977
|
+
// Cast: handler.ts still accepts (request, env) — will be updated
|
|
978
|
+
// separately to accept RouterRequestInput.
|
|
2660
979
|
handler = createRSCHandler({
|
|
2661
980
|
router: router as any,
|
|
2662
981
|
cache,
|
|
2663
982
|
nonce,
|
|
2664
983
|
version,
|
|
2665
|
-
})
|
|
984
|
+
}) as (
|
|
985
|
+
request: Request,
|
|
986
|
+
input: RouterRequestInput<TEnv>,
|
|
987
|
+
) => Promise<Response>;
|
|
2666
988
|
}
|
|
2667
|
-
return handler(request,
|
|
989
|
+
return handler!(request, input);
|
|
2668
990
|
};
|
|
2669
991
|
})(),
|
|
2670
992
|
|
|
2671
993
|
// Debug utility for manifest inspection
|
|
2672
|
-
|
|
2673
|
-
const manifest = new Map<string, EntryData>();
|
|
2674
|
-
|
|
2675
|
-
for (const entry of routesEntries) {
|
|
2676
|
-
const Store = {
|
|
2677
|
-
manifest,
|
|
2678
|
-
namespace: `debug.M${entry.mountIndex}`,
|
|
2679
|
-
parent: null as EntryData | null,
|
|
2680
|
-
counters: {} as Record<string, number>,
|
|
2681
|
-
mountIndex: entry.mountIndex,
|
|
2682
|
-
patterns: new Map<string, string>(),
|
|
2683
|
-
trailingSlash: new Map<string, TrailingSlashMode>(),
|
|
2684
|
-
};
|
|
2685
|
-
|
|
2686
|
-
await getContext().runWithStore(
|
|
2687
|
-
Store,
|
|
2688
|
-
`debug.M${entry.mountIndex}`,
|
|
2689
|
-
null,
|
|
2690
|
-
async () => {
|
|
2691
|
-
const helpers = createRouteHelpers();
|
|
2692
|
-
|
|
2693
|
-
// Wrap handler execution in root layout (same as loadManifest)
|
|
2694
|
-
let promiseResult: Promise<any> | null = null;
|
|
2695
|
-
helpers.layout(MapRootLayout, () => {
|
|
2696
|
-
const result = entry.handler();
|
|
2697
|
-
if (result instanceof Promise) {
|
|
2698
|
-
promiseResult = result;
|
|
2699
|
-
return [];
|
|
2700
|
-
}
|
|
2701
|
-
return result;
|
|
2702
|
-
});
|
|
2703
|
-
|
|
2704
|
-
if (promiseResult !== null) {
|
|
2705
|
-
const load = await (promiseResult as Promise<any>);
|
|
2706
|
-
if (load && typeof load === "object" && "default" in load) {
|
|
2707
|
-
const useItems = load.default;
|
|
2708
|
-
if (typeof useItems === "function") {
|
|
2709
|
-
useItems(helpers);
|
|
2710
|
-
}
|
|
2711
|
-
}
|
|
2712
|
-
}
|
|
2713
|
-
},
|
|
2714
|
-
);
|
|
2715
|
-
}
|
|
2716
|
-
|
|
2717
|
-
return serializeManifest(manifest);
|
|
2718
|
-
},
|
|
994
|
+
debugManifest: () => buildDebugManifest<TEnv>(routesEntries),
|
|
2719
995
|
};
|
|
2720
996
|
|
|
2721
997
|
// Register router in the global registry for build-time discovery
|