@rebask/core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__type_probe__.d.ts +2 -0
- package/dist/__type_probe__.d.ts.map +1 -0
- package/dist/__type_probe__.js +4 -0
- package/dist/components/head.d.ts +2 -11
- package/dist/components/head.d.ts.map +1 -1
- package/dist/components/head.js +12 -24
- package/dist/entry.browser.js +2 -2
- package/dist/entry.ssr.d.ts.map +1 -1
- package/dist/entry.ssr.js +12 -7
- package/dist/handlers/rsc/background-render.js +2 -2
- package/dist/handlers/rsc/render-request.js +2 -2
- package/dist/handlers/rsc/render-to-response.js +2 -2
- package/dist/handlers/rsc/state.d.ts.map +1 -1
- package/dist/handlers/rsc/state.js +11 -5
- package/dist/lib/client-route-prediction.d.ts +1 -1
- package/dist/lib/client-route-prediction.d.ts.map +1 -1
- package/dist/lib/client-route-prediction.js +2 -7
- package/dist/lib/head/head-manager.d.ts +9 -0
- package/dist/lib/head/head-manager.d.ts.map +1 -0
- package/dist/lib/head/head-manager.js +98 -0
- package/dist/lib/head/head-script.js +8 -13
- package/dist/lib/image-optimization/image-plugin.d.ts +2 -0
- package/dist/lib/image-optimization/image-plugin.d.ts.map +1 -1
- package/dist/lib/image-optimization/image-plugin.js +10 -3
- package/dist/lib/plugin-names.d.ts +3 -0
- package/dist/lib/plugin-names.d.ts.map +1 -0
- package/dist/lib/plugin-names.js +2 -0
- package/dist/lib/proxy/build-proxy.d.ts +1 -1
- package/dist/lib/proxy/build-proxy.d.ts.map +1 -1
- package/dist/lib/proxy/build-proxy.js +4 -11
- package/dist/lib/proxy/pattern.d.ts +7 -0
- package/dist/lib/proxy/pattern.d.ts.map +1 -0
- package/dist/lib/proxy/pattern.js +18 -0
- package/dist/lib/proxy/types.d.ts +3 -1
- package/dist/lib/proxy/types.d.ts.map +1 -1
- package/dist/lib/route-prediction.d.ts.map +1 -1
- package/dist/lib/router-cache.d.ts +4 -0
- package/dist/lib/router-cache.d.ts.map +1 -1
- package/dist/lib/rsc-request.d.ts.map +1 -1
- package/dist/lib/rsc-request.js +6 -4
- package/dist/lib/server-router/build-entries.d.ts +76 -0
- package/dist/lib/server-router/build-entries.d.ts.map +1 -0
- package/dist/lib/server-router/build-entries.js +74 -0
- package/dist/lib/server-router/get-router.d.ts.map +1 -1
- package/dist/lib/server-router/get-router.js +55 -105
- package/dist/lib/server-router/rou3.d.ts +20 -0
- package/dist/lib/server-router/rou3.d.ts.map +1 -0
- package/dist/lib/server-router/rou3.js +55 -0
- package/dist/lib/server-router/route-entries.d.ts +16 -0
- package/dist/lib/server-router/route-entries.d.ts.map +1 -0
- package/dist/lib/server-router/route-entries.js +67 -0
- package/dist/lib/server-router/types.d.ts +24 -33
- package/dist/lib/server-router/types.d.ts.map +1 -1
- package/dist/lib/server-router/types.js +1 -6
- package/dist/lib/types.d.ts +2 -2
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/plugins/prerender.d.ts +3 -4
- package/dist/plugins/prerender.d.ts.map +1 -1
- package/dist/plugins/prerender.js +31 -0
- package/dist/plugins/proxy.d.ts.map +1 -1
- package/dist/plugins/proxy.js +7 -1
- package/dist/plugins/router/rou3-compiled.d.ts +9 -0
- package/dist/plugins/router/rou3-compiled.d.ts.map +1 -0
- package/dist/plugins/router/rou3-compiled.js +14 -0
- package/dist/plugins/router/rou3-router.d.ts +3 -0
- package/dist/plugins/router/rou3-router.d.ts.map +1 -0
- package/dist/plugins/router/rou3-router.js +16 -0
- package/dist/plugins/router/router-plugin.d.ts +6 -16
- package/dist/plugins/router/router-plugin.d.ts.map +1 -1
- package/dist/plugins/router/router-plugin.js +43 -22
- package/dist/proxy.d.ts +1 -0
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +1 -0
- package/dist/request-context.d.ts +0 -2
- package/dist/request-context.d.ts.map +1 -1
- package/dist/request-context.js +0 -4
- package/dist/router.d.ts +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +19 -9
- package/dist/server-router.d.ts +3 -3
- package/dist/server-router.d.ts.map +1 -1
- package/dist/server-router.js +2 -2
- package/dist/vite.d.ts +8 -3
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +60 -29
- package/package.json +5 -4
|
@@ -1,48 +1,39 @@
|
|
|
1
|
-
import type { ProxyHandler } from "../proxy/types.js";
|
|
2
1
|
import type { HttpMethod, LayoutRoute, Route, RouteHandlerRoute, RouteParams } from "../route-matcher.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type AppEntry<T> = {
|
|
10
|
-
methods: HttpMethod[];
|
|
11
|
-
type: RouteType.APP;
|
|
12
|
-
route: T;
|
|
13
|
-
handler: Handler;
|
|
2
|
+
import type { EntryParams } from "./rou3.js";
|
|
3
|
+
export type AppHandler = (request: Request, params: RouteParams) => Promise<Response>;
|
|
4
|
+
type AppHandlerVariant = {
|
|
5
|
+
handler: AppHandler;
|
|
6
|
+
route: Route | RouteHandlerRoute | LayoutRoute;
|
|
7
|
+
params: EntryParams;
|
|
14
8
|
};
|
|
15
|
-
type
|
|
16
|
-
type RouteHandlerEntry = AppEntry<RouteHandlerRoute>;
|
|
17
|
-
type LayoutRSCEntry = AppEntry<LayoutRoute>;
|
|
18
|
-
export type ProxyEntry = {
|
|
19
|
-
type: RouteType.PROXY;
|
|
9
|
+
export type MatcherEntry = {
|
|
20
10
|
methods: HttpMethod[];
|
|
21
11
|
pattern: string;
|
|
22
|
-
handler: ProxyHandler;
|
|
23
12
|
};
|
|
24
|
-
type
|
|
25
|
-
type:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
type AppRouteEntry = MatcherEntry & {
|
|
14
|
+
type: "app";
|
|
15
|
+
app?: AppHandlerVariant;
|
|
16
|
+
markdown?: AppHandlerVariant;
|
|
17
|
+
layout?: AppHandlerVariant;
|
|
29
18
|
};
|
|
30
|
-
|
|
31
|
-
type
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
type ImageRouteEntry = MatcherEntry & {
|
|
20
|
+
type: "image";
|
|
21
|
+
app: AppHandler;
|
|
22
|
+
layout?: AppHandlerVariant;
|
|
34
23
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
export type AppEntry = AppRouteEntry | ImageRouteEntry;
|
|
25
|
+
/** A route matcher that finds the best matching route for a given method + URL. */
|
|
26
|
+
export interface RouteMatcher<T> {
|
|
27
|
+
find(method: string, url: string): {
|
|
28
|
+
entry: T;
|
|
29
|
+
params?: Record<string, string>;
|
|
30
|
+
} | null;
|
|
38
31
|
}
|
|
39
32
|
/**
|
|
40
33
|
* A router plugin provides an implementation of this function via the
|
|
41
34
|
* `virtual:rebask/server-router` virtual module.
|
|
42
|
-
*
|
|
43
|
-
* Matched handlers must receive decoded params, splitting catch-all components before decoding.
|
|
44
35
|
*/
|
|
45
|
-
export type CreateMatcherFn = <
|
|
36
|
+
export type CreateMatcherFn = <T extends MatcherEntry>(entries: T[]) => RouteMatcher<T>;
|
|
46
37
|
export interface RebaskRouter {
|
|
47
38
|
/** Handles a request through the full router: proxy routes first, then app routes. */
|
|
48
39
|
handle: (request: Request) => Promise<Response>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/server-router/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/server-router/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,UAAU,EACV,WAAW,EACX,KAAK,EACL,iBAAiB,EACjB,WAAW,EACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAE5C,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,C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AAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC5C,qFAAqF;IACrF,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAA;CACrD"}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -48,8 +48,8 @@ export type SegmentRscPayload = PageRscPayload | LayoutRscPayload;
|
|
|
48
48
|
export type RouteRscPayload = PageRscPayload & {
|
|
49
49
|
/** Form state in case of a document form submission. */
|
|
50
50
|
formState?: ReactFormState;
|
|
51
|
-
/**
|
|
52
|
-
|
|
51
|
+
/** Regex sources the browser tests to skip route prediction for paths a proxy may answer. */
|
|
52
|
+
proxyRegexps?: string[];
|
|
53
53
|
/**
|
|
54
54
|
* Set when this document is the built-in error route rendered after a failed shell. The
|
|
55
55
|
* browser hydrates it as-is and then refreshes the URL to render the real route content.
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAElE,MAAM,WAAW,YAAY;IAC5B;;;OAGG;IACH,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,iDAAiD;IACjD,eAAe,CAAC,EAAE,qBAAqB,CAAA;CACvC;AAED,MAAM,WAAW,qBAAqB;IACrC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAA;IAChC;;;OAGG;IACH,aAAa,CAAC,EAA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AAC,EAAE,eAAe,CAAC,CAAA;AAEnF,MAAM,MAAM,cAAc,GAAG;IAC5B,QAAQ,EAAE,cAAc,CAAA;IACxB,eAAe,CAAC,EAAE,eAAe,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,EAAE,cAAc,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG,gBAAgB,CAAA;AAEjE,6DAA6D;AAC7D,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG;IAC9C,wDAAwD;IACxD,SAAS,CAAC,EAAE,cAAc,CAAA;IAC1B,6FAA6F;IAC7F,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAA;AAEzD,MAAM,MAAM,gBAAgB,GACzB;IAAE,WAAW,EAAE,YAAY,CAAC;IAAC,SAAS,CAAC,EAAE,KAAK,CAAA;CAAE,GAChD;IAAE,WAAW,CAAC,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,cAAc,CAAA;CAAE,CAAA;AAErD,MAAM,MAAM,UAAU,GAAG,eAAe,GAAG,iBAAiB,GAAG,gBAAgB,CAAA"}
|
|
@@ -4,10 +4,7 @@ import { type HasDynamicIO } from "../lib/route-prediction.js";
|
|
|
4
4
|
import type { RebaskPluginApi } from "../vite.js";
|
|
5
5
|
type CacheControl = NonNullable<BuildPrerenderMeta["cacheLife"]>;
|
|
6
6
|
type PrerenderManifestPaths = {
|
|
7
|
-
/**
|
|
8
|
-
* Concrete pathnames of a file with `allowExtraParams: false`. The field's presence is the
|
|
9
|
-
* static-only signal.
|
|
10
|
-
*/
|
|
7
|
+
/** Concrete pathnames of a file with `allowExtraParams = false`, used for static-only 404s. */
|
|
11
8
|
static?: string[];
|
|
12
9
|
/** Ordered `predictPaths` pathnames with their request-IO bits. */
|
|
13
10
|
predict?: Array<[pathname: string, hasDynamicIO: HasDynamicIO]>;
|
|
@@ -41,5 +38,7 @@ interface PrerenderPluginOptions {
|
|
|
41
38
|
failOnDynamic?: boolean;
|
|
42
39
|
}
|
|
43
40
|
export declare function prerenderPlugin(api: RebaskPluginApi, options?: PrerenderPluginOptions): Plugin;
|
|
41
|
+
/** Collects the route metadata needed at runtime when prerendering is disabled. */
|
|
42
|
+
export declare function routeMetadataPlugin(api: RebaskPluginApi): Plugin;
|
|
44
43
|
export {};
|
|
45
44
|
//# sourceMappingURL=prerender.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prerender.d.ts","sourceRoot":"","sources":["../../src/plugins/prerender.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAQlC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AASlE,OAAO,EAA0B,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACtF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOjD,KAAK,YAAY,GAAG,WAAW,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAA;AAEhE,KAAK,sBAAsB,GAAG;IAC7B
|
|
1
|
+
{"version":3,"file":"prerender.d.ts","sourceRoot":"","sources":["../../src/plugins/prerender.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAQlC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AASlE,OAAO,EAA0B,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACtF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOjD,KAAK,YAAY,GAAG,WAAW,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CA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vedParams = paramsResult && paramsResult.params.length > 0 ? paramsResult.params : null;
|
|
71
71
|
const allowExtraParams = isDynamic ? (paramsResult?.allowExtraParams ?? true) : true;
|
|
72
72
|
const { filePath, shellParams } = route;
|
|
73
|
+
if (allowExtraParams === false) {
|
|
74
|
+
staticRoutePaths[filePath] ??= [];
|
|
75
|
+
}
|
|
73
76
|
if (allowExtraParams !== false &&
|
|
74
77
|
typeof paramsResult?.predictPaths === "number" &&
|
|
75
78
|
paramsResult.predictPaths > 0) {
|
|
@@ -358,3 +361,31 @@ export function prerenderPlugin(api, options = {}) {
|
|
|
358
361
|
},
|
|
359
362
|
};
|
|
360
363
|
}
|
|
364
|
+
/** Collects the route metadata needed at runtime when prerendering is disabled. */
|
|
365
|
+
export function routeMetadataPlugin(api) {
|
|
366
|
+
return {
|
|
367
|
+
name: "rebask:route-metadata",
|
|
368
|
+
buildApp: {
|
|
369
|
+
async handler() {
|
|
370
|
+
const pageRoutes = api
|
|
371
|
+
.getRoutes()
|
|
372
|
+
.filter((route) => route.type === "page");
|
|
373
|
+
const entryModule = (await import(`file://${api.getRscEntry()}`));
|
|
374
|
+
const paths = {};
|
|
375
|
+
await Promise.all(pageRoutes.map(async (route) => {
|
|
376
|
+
if (!route.segments.some(isDynamicSegment))
|
|
377
|
+
return;
|
|
378
|
+
const result = await entryModule.getPrerenderParams(route);
|
|
379
|
+
if (result?.allowExtraParams !== false)
|
|
380
|
+
return;
|
|
381
|
+
paths[route.filePath] = {
|
|
382
|
+
static: result.params.map((params) => getRouteParamsPathname(route, params)),
|
|
383
|
+
};
|
|
384
|
+
}));
|
|
385
|
+
const dir = join(process.cwd(), "dist", ".rebask");
|
|
386
|
+
await mkdir(dir, { recursive: true });
|
|
387
|
+
await writeFile(join(dir, "prerendered-paths.json"), JSON.stringify({ noShellRoutes: [], paths }));
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/plugins/proxy.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAIX,MAAM,EAEN,MAAM,MAAM,CAAA;AAQb,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,qCAAqC;AACrC,eAAO,MAAM,wBAAwB,iBAAiB,CAAA;AAEtD,MAAM,WAAW,oBAAoB;IACpC;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,kGAAkG;IAClG,WAAW,EAAE,MAAM,MAAM,EAAE,GAAG,IAAI,CAAA;CAClC;AAyDD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/plugins/proxy.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAIX,MAAM,EAEN,MAAM,MAAM,CAAA;AAQb,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,qCAAqC;AACrC,eAAO,MAAM,wBAAwB,iBAAiB,CAAA;AAEtD,MAAM,WAAW,oBAAoB;IACpC;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,kGAAkG;IAClG,WAAW,EAAE,MAAM,MAAM,EAAE,GAAG,IAAI,CAAA;CAClC;AAyDD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAoK5D"}
|
package/dist/plugins/proxy.js
CHANGED
|
@@ -60,6 +60,7 @@ export function proxyPlugin(coreApi) {
|
|
|
60
60
|
let takenOver = false;
|
|
61
61
|
let projectRoot = process.cwd();
|
|
62
62
|
let takenOverPatterns = null;
|
|
63
|
+
let takenOverRegexps = null;
|
|
63
64
|
const api = {
|
|
64
65
|
takeover() {
|
|
65
66
|
takenOver = true;
|
|
@@ -145,6 +146,7 @@ export function proxyPlugin(coreApi) {
|
|
|
145
146
|
return;
|
|
146
147
|
const bundle = (await import(pathToFileURL(join(projectRoot, REBASK_PROXY_BUNDLE_PATH)).href));
|
|
147
148
|
takenOverPatterns = bundle.proxyPatterns;
|
|
149
|
+
takenOverRegexps = bundle.proxyRegexps;
|
|
148
150
|
},
|
|
149
151
|
},
|
|
150
152
|
async hotUpdate({ file, server }) {
|
|
@@ -171,14 +173,18 @@ export function proxyPlugin(coreApi) {
|
|
|
171
173
|
// proxy file, both are `null`.
|
|
172
174
|
if (!resolvedProxyPath || (takenOver && this.environment?.name !== "proxy")) {
|
|
173
175
|
const patterns = resolvedProxyPath ? JSON.stringify(takenOverPatterns) : "null";
|
|
174
|
-
|
|
176
|
+
const regexps = resolvedProxyPath ? JSON.stringify(takenOverRegexps) : "null";
|
|
177
|
+
return `export const proxyPatterns = ${patterns};\nexport const proxyRegexps = ${regexps};\nexport const proxyRouter = null;`;
|
|
175
178
|
}
|
|
176
179
|
const buildProxyPath = new URL("../lib/proxy/build-proxy.js", import.meta.url).pathname;
|
|
180
|
+
const patternPath = new URL("../lib/proxy/pattern.js", import.meta.url).pathname;
|
|
177
181
|
return [
|
|
178
182
|
`import proxy from ${JSON.stringify(resolvedProxyPath)};`,
|
|
179
183
|
`import { buildProxy } from ${JSON.stringify(buildProxyPath)};`,
|
|
184
|
+
`import { proxyPatternToClientSource } from ${JSON.stringify(patternPath)};`,
|
|
180
185
|
`const routes = proxy.default || proxy;`,
|
|
181
186
|
`export const proxyPatterns = Object.keys(routes);`,
|
|
187
|
+
`export const proxyRegexps = proxyPatterns.map(proxyPatternToClientSource);`,
|
|
182
188
|
`export const proxyRouter = buildProxy(routes);`,
|
|
183
189
|
].join("\n");
|
|
184
190
|
},
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MatcherEntry, RouteMatcher } from "../../lib/server-router/types.js";
|
|
2
|
+
/** A compiled `find` function returning an index into the matcher entries. */
|
|
3
|
+
export type CompiledFind = (method: string, path: string) => {
|
|
4
|
+
data: number;
|
|
5
|
+
params?: Record<string, string>;
|
|
6
|
+
} | undefined;
|
|
7
|
+
/** Wraps a compiled `find` function and resolves its entry indexes. */
|
|
8
|
+
export declare function createCompiledMatcher<T extends MatcherEntry>(find: CompiledFind, entries: T[]): RouteMatcher<T>;
|
|
9
|
+
//# sourceMappingURL=rou3-compiled.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rou3-compiled.d.ts","sourceRoot":"","sources":["../../../src/plugins/router/rou3-compiled.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAElF,8EAA8E;AAC9E,MAAM,MAAM,YAAY,GAAG,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,KACR;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,SAAS,CAAA;AAElE,uEAAuE;AACvE,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,YAAY,EAC3D,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,CAAC,EAAE,GACV,YAAY,CAAC,CAAC,CAAC,CAYjB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Wraps a compiled `find` function and resolves its entry indexes. */
|
|
2
|
+
export function createCompiledMatcher(find, entries) {
|
|
3
|
+
return {
|
|
4
|
+
find(method, url) {
|
|
5
|
+
const match = find(method, new URL(url, "http://localhost").pathname);
|
|
6
|
+
if (!match)
|
|
7
|
+
return null;
|
|
8
|
+
const entry = entries[match.data];
|
|
9
|
+
if (!entry)
|
|
10
|
+
return null;
|
|
11
|
+
return { entry, params: match.params };
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rou3-router.d.ts","sourceRoot":"","sources":["../../../src/plugins/router/rou3-router.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAElF,wBAAgB,aAAa,CAAC,CAAC,SAAS,YAAY,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,CAgBnF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { addRoute, createRouter, findRoute } from "rou3";
|
|
2
|
+
export function createMatcher(entries) {
|
|
3
|
+
const router = createRouter();
|
|
4
|
+
for (const entry of entries) {
|
|
5
|
+
for (const method of entry.methods)
|
|
6
|
+
addRoute(router, method, entry.pattern, entry);
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
find(method, url) {
|
|
10
|
+
const match = findRoute(router, method, new URL(url, "http://localhost").pathname);
|
|
11
|
+
if (!match)
|
|
12
|
+
return null;
|
|
13
|
+
return { entry: match.data, params: match.params };
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
+
import type { MatcherEntry } from "../../lib/server-router/types.js";
|
|
2
3
|
export interface RouterPluginOptions {
|
|
3
4
|
/** Plugin name. */
|
|
4
5
|
name: string;
|
|
5
6
|
/** Absolute path to the module that exports `createMatcher`. */
|
|
6
7
|
matcherModule: string;
|
|
8
|
+
/** Compiles the matcher entries into the source of a `find` function for production builds. */
|
|
9
|
+
compile?: (entries: readonly MatcherEntry[]) => string;
|
|
7
10
|
}
|
|
8
11
|
/**
|
|
9
12
|
* Create a Vite plugin that provides a custom server router for Rebask.
|
|
10
13
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
14
|
+
* `matcherModule` provides `createMatcher` in development, and in production unless `compile` is
|
|
15
|
+
* provided. `compile` replaces it in production builds.
|
|
13
16
|
*
|
|
14
17
|
* @example
|
|
15
18
|
* ```ts
|
|
@@ -24,18 +27,5 @@ export interface RouterPluginOptions {
|
|
|
24
27
|
* ```
|
|
25
28
|
*/
|
|
26
29
|
export declare function createRouterPlugin(options: RouterPluginOptions): Plugin;
|
|
27
|
-
|
|
28
|
-
* Default router of Rebask. Adding it manually is optional.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* import { rebask } from "@rebask/core/vite"
|
|
33
|
-
* import { rebaskRouter } from "@rebask/core/server-router"
|
|
34
|
-
*
|
|
35
|
-
* export default defineConfig({
|
|
36
|
-
* plugins: [rsc(), react(), rebask(), rebaskRouter()],
|
|
37
|
-
* })
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export declare function rebaskRouter(): Plugin;
|
|
30
|
+
export declare function defaultRouterPlugin(): Plugin;
|
|
41
31
|
//# sourceMappingURL=router-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/router/router-plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router-plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/router/router-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAGlC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAMpE,MAAM,WAAW,mBAAmB;IACnC,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,gEAAgE;IAChE,aAAa,EAAE,MAAM,CAAA;IACrB,+FAA+F;IAC/F,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,KAAK,MAAM,CAAA;CACtD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAkCvE;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAiB5C"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { addRoute, createRouter } from "rou3";
|
|
2
|
+
import { compileRouterToString } from "rou3/compiler";
|
|
3
|
+
import { REBASK_PLUGIN_NAME } from "../../lib/plugin-names.js";
|
|
4
|
+
import { getPluginApi } from "../../lib/plugin-utils.js";
|
|
1
5
|
const VIRTUAL_MODULE_ID = "virtual:rebask/server-router";
|
|
2
6
|
const RESOLVED_MODULE_ID = "\0virtual:rebask/server-router";
|
|
3
7
|
/**
|
|
4
8
|
* Create a Vite plugin that provides a custom server router for Rebask.
|
|
5
9
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
10
|
+
* `matcherModule` provides `createMatcher` in development, and in production unless `compile` is
|
|
11
|
+
* provided. `compile` replaces it in production builds.
|
|
8
12
|
*
|
|
9
13
|
* @example
|
|
10
14
|
* ```ts
|
|
@@ -19,36 +23,53 @@ const RESOLVED_MODULE_ID = "\0virtual:rebask/server-router";
|
|
|
19
23
|
* ```
|
|
20
24
|
*/
|
|
21
25
|
export function createRouterPlugin(options) {
|
|
26
|
+
let isBuild = false;
|
|
27
|
+
let api;
|
|
22
28
|
return {
|
|
23
29
|
name: options.name,
|
|
24
30
|
enforce: "pre",
|
|
31
|
+
configResolved(config) {
|
|
32
|
+
isBuild = config.command === "build";
|
|
33
|
+
if (options.compile) {
|
|
34
|
+
api = getPluginApi(config.plugins, REBASK_PLUGIN_NAME);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
25
37
|
resolveId(id) {
|
|
26
38
|
if (id === VIRTUAL_MODULE_ID)
|
|
27
39
|
return RESOLVED_MODULE_ID;
|
|
28
40
|
},
|
|
29
|
-
load(id) {
|
|
41
|
+
async load(id) {
|
|
30
42
|
if (id !== RESOLVED_MODULE_ID)
|
|
31
43
|
return;
|
|
32
|
-
|
|
44
|
+
if (!options.compile || !isBuild) {
|
|
45
|
+
return `export { createMatcher } from ${JSON.stringify(options.matcherModule)};`;
|
|
46
|
+
}
|
|
47
|
+
if (!api) {
|
|
48
|
+
throw new Error('createRouterPlugin with "compile" requires the Rebask Vite plugin.');
|
|
49
|
+
}
|
|
50
|
+
const entries = await api.getMatcherEntries();
|
|
51
|
+
return [
|
|
52
|
+
`import { createCompiledMatcher } from "@rebask/core/server-router";`,
|
|
53
|
+
`const find = ${options.compile(entries)};`,
|
|
54
|
+
`export function createMatcher(entries) { return createCompiledMatcher(find, entries); }`,
|
|
55
|
+
].join("\n");
|
|
33
56
|
},
|
|
34
57
|
};
|
|
35
58
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
matcherModule: new URL("./wint-router.js", import.meta.url).pathname,
|
|
53
|
-
});
|
|
59
|
+
export function defaultRouterPlugin() {
|
|
60
|
+
return {
|
|
61
|
+
...createRouterPlugin({
|
|
62
|
+
name: "rebask:server-router",
|
|
63
|
+
matcherModule: new URL("./rou3-router.js", import.meta.url).pathname,
|
|
64
|
+
compile: (entries) => {
|
|
65
|
+
const router = createRouter();
|
|
66
|
+
for (const [index, entry] of entries.entries()) {
|
|
67
|
+
for (const method of entry.methods)
|
|
68
|
+
addRoute(router, method, entry.pattern, index);
|
|
69
|
+
}
|
|
70
|
+
return compileRouterToString(router);
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
enforce: "post",
|
|
74
|
+
};
|
|
54
75
|
}
|
package/dist/proxy.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { rewrite } from "./lib/proxy/rewrite.js";
|
|
2
2
|
export { REBASK_PROXY_BUNDLE_PATH } from "./lib/proxy/types.js";
|
|
3
3
|
export type { ProxyBundle, ProxyHandler, ProxyRoutes, ProxyRouter } from "./lib/proxy/types.js";
|
|
4
|
+
export { proxyPatternToRegExpSource } from "./lib/proxy/pattern.js";
|
|
4
5
|
//# sourceMappingURL=proxy.d.ts.map
|
package/dist/proxy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAA;AAC/D,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA"}
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAA;AAC/D,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC/F,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAA"}
|
package/dist/proxy.js
CHANGED
|
@@ -96,8 +96,6 @@ export declare function trackRequestIO(): void;
|
|
|
96
96
|
export declare function hasRequestIO(): boolean;
|
|
97
97
|
/** Record that the render read `key` and the value `get` returned for it. */
|
|
98
98
|
export declare function trackSearchParam(key: string, value: SearchParamValue): void;
|
|
99
|
-
/** The search params a render read, or `undefined` when it read none. */
|
|
100
|
-
export declare function getUsedSearch(): UsedSearch | undefined;
|
|
101
99
|
/** Whether the render read dynamic data (`routeParams()`, `headers()`, `cookies()`). */
|
|
102
100
|
export declare function hasDynamicIO(): boolean;
|
|
103
101
|
/** Marks that the render failed. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-context.d.ts","sourceRoot":"","sources":["../src/request-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAA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AE7B;AAED,oFAAoF;AACpF,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED,wBAAgB,YAAY,0BAE3B;AAED,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,+BAE9C;AAED,uDAAuD;AACvD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,QAKxE;AAED,kGAAkG;AAClG,wBAAgB,iBAAiB,2BAGhC;AAED,qBAAa,uBAAwB,SAAQ,OAAO;IACnD,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,MAAM,CAAQ;IAEtB,OAAO,CAAC,gBAAgB;IAQxB,MAAM,SAEL;IAEQ,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAMjD;CACD;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAYtE"}
|
package/dist/request-context.js
CHANGED
|
@@ -51,10 +51,6 @@ export function trackSearchParam(key, value) {
|
|
|
51
51
|
state.usedSearch ??= new Map();
|
|
52
52
|
state.usedSearch.set(key, value);
|
|
53
53
|
}
|
|
54
|
-
/** The search params a render read, or `undefined` when it read none. */
|
|
55
|
-
export function getUsedSearch() {
|
|
56
|
-
return getRequiredRequestState("getUsedSearch()").usedSearch;
|
|
57
|
-
}
|
|
58
54
|
/** Whether the render read dynamic data (`routeParams()`, `headers()`, `cookies()`). */
|
|
59
55
|
export function hasDynamicIO() {
|
|
60
56
|
return getRequiredRequestState("hasDynamicIO()").dynamicIO ?? false;
|
package/dist/router.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type NavigateOptions = {
|
|
|
22
22
|
/** Control window scrolling after navigation. Defaults to `true`. */
|
|
23
23
|
scroll?: boolean;
|
|
24
24
|
};
|
|
25
|
-
export declare const
|
|
25
|
+
export declare const proxyRegexpsAtom: import("@lfades/atom").Atom<string[] | undefined>;
|
|
26
26
|
/** The tags and segment paths a cache invalidation affected. */
|
|
27
27
|
type CacheInvalidation = {
|
|
28
28
|
tags: string[];
|
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAcrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAczD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAmB,KAAK,WAAW,EAAqB,MAAM,uBAAuB,CAAA;AAC5F,OAAO,KAAK,EAAoB,OAAO,EAA+B,MAAM,uBAAuB,CAAA;AAyCnG,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAC7D,YAAY,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,MAAM,MAAM,iBAAiB,GAAG;IAC/B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC7B,qEAAqE;IACrE,MAAM,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AASD,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAcrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAczD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAmB,KAAK,WAAW,EA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EAAE,CAAC,YAAY,EAAE,iBAAiB,KAAK,IAAI,QAYzF"}
|
package/dist/router.js
CHANGED
|
@@ -28,7 +28,7 @@ const inflightTreeCache = new Map();
|
|
|
28
28
|
const inflightRouteTreeByParent = new Map();
|
|
29
29
|
const inflightSegmentCache = new Map();
|
|
30
30
|
const inflightShellCache = new Map();
|
|
31
|
-
export const
|
|
31
|
+
export const proxyRegexpsAtom = atom(undefined);
|
|
32
32
|
/** Latest cache invalidation, or `null` before the first one. */
|
|
33
33
|
const cacheInvalidationAtom = atom(null);
|
|
34
34
|
/**
|
|
@@ -320,7 +320,9 @@ class Router {
|
|
|
320
320
|
const search = segmentLocation.search ?? "";
|
|
321
321
|
const fetchKey = `${segmentPath}?${search}`;
|
|
322
322
|
const { shellable, shellKey } = this.segmentShell(segmentLocation);
|
|
323
|
-
const cachedShell = import.meta.env.PROD && shellable && !skipShell
|
|
323
|
+
const cachedShell = import.meta.env.PROD && shellable && !skipShell
|
|
324
|
+
? (this.cache.getShell(segmentPath) ?? this.cache.getShell(shellKey))
|
|
325
|
+
: undefined;
|
|
324
326
|
const reusePolicy = this.cache.getSegmentReusePolicy(segmentLocation, cachedShell);
|
|
325
327
|
const { completeShell, inBackground } = reusePolicy;
|
|
326
328
|
let shell = reusePolicy.showShell ? cachedShell : undefined;
|
|
@@ -475,8 +477,11 @@ class Router {
|
|
|
475
477
|
// constantly, so no stable shell survives to match. Serve the full segment instead.
|
|
476
478
|
if (import.meta.env.DEV)
|
|
477
479
|
return null;
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
+
const usable = (shell) => shell && !shell.stale && (!shell.staticOnly || shell.path === segmentLocation.path);
|
|
481
|
+
const concrete = this.cache.getShell(segmentLocation.path);
|
|
482
|
+
const shared = this.cache.getShell(key);
|
|
483
|
+
const cached = usable(concrete) ? concrete : usable(shared) ? shared : undefined;
|
|
484
|
+
if (cached)
|
|
480
485
|
return cached;
|
|
481
486
|
let inFlight = inflightShellCache.get(key);
|
|
482
487
|
if (!inFlight || !inFlight.isCurrent()) {
|
|
@@ -499,6 +504,10 @@ class Router {
|
|
|
499
504
|
inflightShellCache.delete(key);
|
|
500
505
|
if (!shell)
|
|
501
506
|
return null;
|
|
507
|
+
// Another path answered the shared key with a static page. It cannot serve this one.
|
|
508
|
+
if (shell.staticOnly && shell.path !== segmentLocation.path) {
|
|
509
|
+
return this.ensureShell(segmentLocation, key, expectedRoutePrediction);
|
|
510
|
+
}
|
|
502
511
|
const payload = await shell.payload;
|
|
503
512
|
if (!inFlight.isCurrent())
|
|
504
513
|
return null;
|
|
@@ -511,7 +520,7 @@ class Router {
|
|
|
511
520
|
this.cache.markSegmentStale(segmentLocation);
|
|
512
521
|
throw new RoutePredictionMismatch();
|
|
513
522
|
}
|
|
514
|
-
this.cache.cacheShell(key, shell);
|
|
523
|
+
this.cache.cacheShell(shell.staticOnly ? segmentLocation.path : key, shell);
|
|
515
524
|
return shell;
|
|
516
525
|
}
|
|
517
526
|
async fetchSegmentShell(segmentLocation) {
|
|
@@ -536,7 +545,8 @@ class Router {
|
|
|
536
545
|
}));
|
|
537
546
|
const resolvedPayload = await payload;
|
|
538
547
|
const segmentHints = id === null ? await extractSegmentHints(resolvedPayload.seedData.content) : undefined;
|
|
539
|
-
|
|
548
|
+
const staticOnly = "routePrediction" in resolvedPayload && resolvedPayload.routePrediction?.[3] === true;
|
|
549
|
+
return { bytes, path: segmentLocation.path, staticOnly, id, payload, cachedAt, ...segmentHints };
|
|
540
550
|
}
|
|
541
551
|
/**
|
|
542
552
|
* Prefetch all missing segments for a route tree and cache them.
|
|
@@ -583,8 +593,8 @@ class Router {
|
|
|
583
593
|
const parentPathname = `/${segments.slice(0, -1).join("/")}`;
|
|
584
594
|
const inflightSiblingTree = inflightRouteTreeByParent.get(parentPathname);
|
|
585
595
|
if (cache) {
|
|
586
|
-
const
|
|
587
|
-
const predicted = predictRouteTree(target.href,
|
|
596
|
+
const proxyRegexps = proxyRegexpsAtom.get();
|
|
597
|
+
const predicted = predictRouteTree(target.href, proxyRegexps);
|
|
588
598
|
if (predicted) {
|
|
589
599
|
this.cache.registerRouteTree(predicted);
|
|
590
600
|
return predicted;
|
|
@@ -657,7 +667,7 @@ class Router {
|
|
|
657
667
|
return;
|
|
658
668
|
const target = getUrl(url);
|
|
659
669
|
const routeTreeResponse = this.cache.getRouteTreeResponse(target.href) ??
|
|
660
|
-
predictRouteTree(target.href,
|
|
670
|
+
predictRouteTree(target.href, proxyRegexpsAtom.get()) ??
|
|
661
671
|
(await this.prefetchRouteTree(url));
|
|
662
672
|
const expectedRoutePrediction = routeTreeResponse.routePrediction;
|
|
663
673
|
const missing = this.cache.findMissingSegmentLocations(routeTreeResponse);
|
package/dist/server-router.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { CreateMatcherFn, MatchedHandler, RouteEntry, RouteMatcher, } from "./lib/server-router/types.js";
|
|
1
|
+
export type { CreateMatcherFn, MatcherEntry, RouteMatcher } from "./lib/server-router/types.js";
|
|
3
2
|
export type { LayoutRoute, NotFoundRoute, Route, RouteSegment, RouteHandlerRoute, } from "./lib/route-matcher.js";
|
|
4
|
-
export {
|
|
3
|
+
export { createCompiledMatcher, type CompiledFind } from "./plugins/router/rou3-compiled.js";
|
|
4
|
+
export { createRouterPlugin, type RouterPluginOptions } from "./plugins/router/router-plugin.js";
|
|
5
5
|
//# sourceMappingURL=server-router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-router.d.ts","sourceRoot":"","sources":["../src/server-router.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"server-router.d.ts","sourceRoot":"","sources":["../src/server-router.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC/F,YAAY,EACX,WAAW,EACX,aAAa,EACb,KAAK,EACL,YAAY,EACZ,iBAAiB,GACjB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,qBAAqB,EAAE,KAAK,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAC5F,OAAO,EAAE,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,MAAM,mCAAmC,CAAA"}
|
package/dist/server-router.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { createRouterPlugin
|
|
1
|
+
export { createCompiledMatcher } from "./plugins/router/rou3-compiled.js";
|
|
2
|
+
export { createRouterPlugin } from "./plugins/router/router-plugin.js";
|