@teyik0/furin 0.6.0-alpha.1 → 0.7.0-alpha.1
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/adapter/runtime-build.d.ts +1 -1
- package/dist/build/client.d.ts +4 -1
- package/dist/build/entry-template.d.ts +3 -0
- package/dist/build/entry-template.ts +7 -0
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +1671 -276
- package/dist/build/preload-manifest.d.ts +17 -0
- package/dist/build/types.d.ts +6 -0
- package/dist/cli/index.js +1672 -286
- package/dist/client/client-module.d.ts +26 -0
- package/dist/client/define-route.d.ts +9 -0
- package/dist/client/document.d.ts +2 -0
- package/dist/client/internal/runtime-types.d.ts +2 -0
- package/dist/client/link.js +932 -118
- package/dist/client/mutation.d.ts +38 -0
- package/dist/client/query-store.d.ts +85 -0
- package/dist/client/query.d.ts +14 -0
- package/dist/client/route-api.d.ts +11 -0
- package/dist/client/router/context.d.ts +3 -2
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +8 -1
- package/dist/client/router/navigation.d.ts +2 -9
- package/dist/client/router/optimistic.d.ts +41 -0
- package/dist/client/router/search/index.d.ts +3 -3
- package/dist/client/router/search-store.d.ts +1 -0
- package/dist/client/router/sync-catch-up.d.ts +3 -0
- package/dist/client/router/types.d.ts +49 -7
- package/dist/client/sync.d.ts +39 -22
- package/dist/client.d.ts +11 -33
- package/dist/client.js +1219 -59
- package/dist/config.d.ts +7 -0
- package/dist/config.js +1 -0
- package/dist/define-route.d.ts +78 -32
- package/dist/env.d.ts +2 -2
- package/dist/furin.d.ts +1 -2
- package/dist/furin.js +2448 -710
- package/dist/plugin/hmr-dependencies.d.ts +2 -0
- package/dist/plugin/index.js +349 -18
- package/dist/plugin/transform-client-module.d.ts +16 -0
- package/dist/plugin/transform-client.d.ts +2 -0
- package/dist/plugin/transform-isomorphic.d.ts +1 -1
- package/dist/routes.d.ts +6 -0
- package/dist/rsc-client.js +87 -16
- package/dist/rsc.js +87 -16
- package/dist/server/auto-invalidate/registry.d.ts +1 -0
- package/dist/server/auto-invalidate/types.d.ts +2 -0
- package/dist/server/cache/isr.d.ts +2 -4
- package/dist/server/cache/route-cache.d.ts +5 -0
- package/dist/server/dev/graph.d.ts +1 -0
- package/dist/server/dev-page-plugin.d.ts +5 -19
- package/dist/server/internal.d.ts +3 -0
- package/dist/server/internal.js +55 -35
- package/dist/server/production-server.js +54 -34
- package/dist/server/render/loaders.d.ts +4 -2
- package/dist/server/render/react-stream.d.ts +3 -0
- package/dist/server/render/ssr.d.ts +2 -1
- package/dist/server/render/template.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +2 -0
- package/dist/server/router/hmr.d.ts +1 -1
- package/dist/server/sync/adapter.d.ts +25 -4
- package/dist/server/sync/atomic.d.ts +25 -0
- package/dist/server/sync/drizzle/index.d.ts +45 -0
- package/dist/server/sync/drizzle/index.js +540 -0
- package/dist/server/sync/execution-error.d.ts +2 -0
- package/dist/server/sync/index.d.ts +2 -1
- package/dist/server/sync/index.js +533 -105
- package/dist/server/sync/mutation-handler.d.ts +4 -0
- package/dist/server/sync/plugin.d.ts +34 -11
- package/dist/server/sync/postgres/execute.d.ts +3 -0
- package/dist/server/sync/postgres/index.d.ts +12 -1
- package/dist/server/sync/postgres/index.js +34 -13
- package/dist/server/sync/postgres/sql.d.ts +8 -0
- package/dist/server/sync/prisma/index.d.ts +24 -0
- package/dist/server/sync/prisma/index.js +340 -0
- package/dist/server/sync/queries.d.ts +21 -0
- package/dist/server/sync/query-context.d.ts +5 -0
- package/dist/server/sync/redis/index.js +3 -3
- package/dist/server/sync/redis/scripts.d.ts +1 -1
- package/dist/server/sync/response.d.ts +1 -0
- package/dist/server/sync/sqlite/index.d.ts +3 -0
- package/dist/server/sync/sqlite/index.js +10 -4
- package/dist/server/sync/stream.d.ts +2 -5
- package/dist/server/sync/validation.d.ts +4 -0
- package/dist/shared/defer.d.ts +31 -0
- package/dist/shared/error.d.ts +2 -2
- package/dist/shared/page-key.d.ts +7 -0
- package/dist/shared/query-bindings.d.ts +12 -0
- package/dist/shared/route-frame.d.ts +1 -0
- package/dist/shared/sync-query.d.ts +40 -0
- package/package.json +29 -6
- package/src/adapter/package.ts +12 -2
- package/src/adapter/runtime-build.ts +63 -12
- package/src/adapter/static.ts +7 -2
- package/src/adapter/vercel.ts +15 -13
- package/src/build/client.ts +23 -5
- package/src/build/entry-template.ts +7 -0
- package/src/build/hydrate.ts +17 -3
- package/src/build/preload-manifest.ts +100 -0
- package/src/build/production-instrumentation.ts +6 -3
- package/src/build/types.ts +4 -0
- package/src/cli/index.ts +1 -0
- package/src/client/browser-events-runtime.ts +4 -0
- package/src/client/client-module.ts +57 -0
- package/src/client/define-route.ts +11 -1
- package/src/client/document.tsx +28 -18
- package/src/client/hmr.ts +2 -1
- package/src/client/internal/runtime-types.ts +2 -0
- package/src/client/link.tsx +8 -8
- package/src/client/mutation.ts +136 -0
- package/src/client/query-store.ts +418 -0
- package/src/client/query.tsx +67 -0
- package/src/client/route-api.tsx +75 -0
- package/src/client/router/boundary-tree.tsx +7 -2
- package/src/client/router/context.ts +57 -4
- package/src/client/router/index.ts +3 -0
- package/src/client/router/link-utils.ts +29 -1
- package/src/client/router/navigation.ts +3 -50
- package/src/client/router/optimistic.ts +233 -0
- package/src/client/router/provider.tsx +304 -44
- package/src/client/router/search/index.ts +37 -17
- package/src/client/router/search-store.ts +4 -0
- package/src/client/router/sync-catch-up.ts +7 -0
- package/src/client/router/types.ts +71 -9
- package/src/client/sync.ts +438 -65
- package/src/client.ts +20 -60
- package/src/config.ts +5 -0
- package/src/define-route.ts +113 -55
- package/src/env.d.ts +2 -2
- package/src/furin.ts +75 -13
- package/src/plugin/hmr-dependencies.ts +58 -0
- package/src/plugin/index.ts +38 -2
- package/src/plugin/routes.ts +3 -3
- package/src/plugin/transform-client-module.ts +123 -0
- package/src/plugin/transform-client.ts +293 -13
- package/src/plugin/transform-isomorphic.ts +11 -5
- package/src/routes.ts +8 -0
- package/src/rsc/shared.tsx +104 -18
- package/src/server/auto-invalidate/registry.ts +4 -0
- package/src/server/auto-invalidate/runtime.ts +17 -0
- package/src/server/auto-invalidate/types.ts +6 -0
- package/src/server/cache/isr.ts +6 -34
- package/src/server/cache/route-cache.ts +40 -4
- package/src/server/dev/graph.ts +16 -2
- package/src/server/dev-page-plugin.ts +93 -59
- package/src/server/internal.ts +3 -0
- package/src/server/render/document.tsx +10 -1
- package/src/server/render/element.tsx +7 -2
- package/src/server/render/isr.ts +61 -29
- package/src/server/render/loaders.ts +118 -47
- package/src/server/render/mixed-cache.ts +33 -4
- package/src/server/render/not-found.ts +4 -7
- package/src/server/render/ppr-document.ts +2 -1
- package/src/server/render/ppr-route.ts +30 -10
- package/src/server/render/react-stream.ts +17 -0
- package/src/server/render/route-frame-transport.ts +3 -0
- package/src/server/render/ssg.ts +51 -18
- package/src/server/render/ssr.ts +53 -8
- package/src/server/render/template.ts +23 -0
- package/src/server/router/defined-route.ts +3 -0
- package/src/server/router/hmr.ts +3 -2
- package/src/server/router/plugin.ts +27 -12
- package/src/server/sync/adapter.ts +41 -4
- package/src/server/sync/atomic.ts +303 -0
- package/src/server/sync/drizzle/index.ts +145 -0
- package/src/server/sync/execution-error.ts +1 -0
- package/src/server/sync/fingerprint.ts +2 -6
- package/src/server/sync/index.ts +6 -0
- package/src/server/sync/mutation-handler.ts +69 -0
- package/src/server/sync/plugin.ts +177 -60
- package/src/server/sync/postgres/execute.ts +20 -0
- package/src/server/sync/postgres/index.ts +52 -16
- package/src/server/sync/postgres/sql.ts +20 -0
- package/src/server/sync/prisma/index.ts +70 -0
- package/src/server/sync/queries.ts +75 -0
- package/src/server/sync/query-context.ts +85 -0
- package/src/server/sync/redis/index.ts +7 -3
- package/src/server/sync/redis/scripts.ts +1 -1
- package/src/server/sync/response.ts +21 -0
- package/src/server/sync/sqlite/index.ts +19 -8
- package/src/server/sync/stream.ts +14 -22
- package/src/server/sync/validation.ts +34 -0
- package/src/shared/defer.ts +48 -0
- package/src/shared/error.ts +2 -2
- package/src/shared/page-key.ts +36 -0
- package/src/shared/query-bindings.ts +138 -0
- package/src/shared/route-frame.ts +13 -1
- package/src/shared/route-map.ts +12 -2
- package/src/shared/sync-query.ts +138 -0
package/src/server/render/ssg.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// biome-ignore-all lint/performance/noAwaitInLoops: SSG rendering writes route outputs in a deterministic sequence
|
|
2
2
|
import type { Context } from "elysia";
|
|
3
3
|
import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
4
|
+
import { queryFromTag } from "../../shared/sync-query.ts";
|
|
4
5
|
import { mapWithConcurrency } from "../../shared/utils/index.ts";
|
|
6
|
+
import { getAutoInvalidateRegistry } from "../auto-invalidate/registry.ts";
|
|
5
7
|
import type { SsgCacheEntry } from "../cache/isr-ssg.ts";
|
|
6
8
|
import type { PageCacheAdapter, PageCacheIdentity, PageCacheLease } from "../cache/page-cache.ts";
|
|
7
9
|
import { waitForPageCacheEntry } from "../cache/page-cache.ts";
|
|
8
10
|
import { getPageCacheAdapter } from "../cache/page-cache-state.ts";
|
|
9
|
-
import { getSSGCache, setSSGCache } from "../cache/ssg.ts";
|
|
11
|
+
import { getSSGCache, setSSGCache, ssgRouteCache } from "../cache/ssg.ts";
|
|
10
12
|
import { createLogger, getLogger } from "../context-logger.ts";
|
|
11
13
|
import { currentInstance } from "../instance.ts";
|
|
12
14
|
import { resolveDocumentMode } from "../router/patterns.ts";
|
|
@@ -45,36 +47,64 @@ export async function prerenderRoute(
|
|
|
45
47
|
html: renderResult.html,
|
|
46
48
|
ndjson: renderResult.ndjson,
|
|
47
49
|
status: renderResult.status,
|
|
48
|
-
tags: route.tags,
|
|
50
|
+
tags: [...(route.tags ?? []), ...(renderResult.queryTags ?? [])],
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
async function prerenderLocalSSG(
|
|
53
55
|
route: ResolvedRoute,
|
|
54
56
|
params: Record<string, string>,
|
|
55
57
|
root: RootLayout,
|
|
56
58
|
origin: string,
|
|
57
59
|
basePath?: string,
|
|
58
60
|
searchRoutes?: SearchRouteMetadata[]
|
|
59
|
-
): Promise<
|
|
61
|
+
): Promise<RuntimeSsgResult> {
|
|
60
62
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
61
63
|
|
|
62
64
|
const cached = getSSGCache(resolvedPath);
|
|
63
65
|
if (cached) {
|
|
64
66
|
if (cached.tags === route.tags) {
|
|
65
|
-
return cached;
|
|
67
|
+
return { cacheStored: true, entry: cached };
|
|
66
68
|
}
|
|
67
|
-
const taggedEntry: SsgCacheEntry = {
|
|
69
|
+
const taggedEntry: SsgCacheEntry = {
|
|
70
|
+
...cached,
|
|
71
|
+
tags: [
|
|
72
|
+
...(route.tags ?? []),
|
|
73
|
+
...(cached.tags ?? []).filter((tag) => queryFromTag(tag) !== undefined),
|
|
74
|
+
],
|
|
75
|
+
};
|
|
68
76
|
setSSGCache(resolvedPath, taggedEntry);
|
|
69
|
-
return taggedEntry;
|
|
77
|
+
return { cacheStored: true, entry: taggedEntry };
|
|
70
78
|
}
|
|
71
79
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
const cache = ssgRouteCache();
|
|
81
|
+
const generation = cache.captureGeneration(resolvedPath);
|
|
82
|
+
try {
|
|
83
|
+
const entry = await prerenderRoute(route, params, root, origin, "ssg", basePath, searchRoutes);
|
|
84
|
+
if (entry instanceof Response || entry.status !== 200 || !generation.valid) {
|
|
85
|
+
return { cacheStored: false, entry };
|
|
86
|
+
}
|
|
87
|
+
setSSGCache(resolvedPath, entry);
|
|
88
|
+
return { cacheStored: true, entry };
|
|
89
|
+
} finally {
|
|
90
|
+
cache.releaseGeneration(resolvedPath, generation);
|
|
75
91
|
}
|
|
76
|
-
|
|
92
|
+
}
|
|
77
93
|
|
|
94
|
+
export async function prerenderSSG(
|
|
95
|
+
route: ResolvedRoute,
|
|
96
|
+
params: Record<string, string>,
|
|
97
|
+
root: RootLayout,
|
|
98
|
+
origin: string,
|
|
99
|
+
basePath?: string,
|
|
100
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
101
|
+
): Promise<SsgCacheEntry | Response> {
|
|
102
|
+
const { entry } = await prerenderLocalSSG(route, params, root, origin, basePath, searchRoutes);
|
|
103
|
+
if (!(entry instanceof Response) && entry.status >= 500) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`[furin] Failed to prerender SSG route "${route.pattern}" (HTTP ${entry.status}).`
|
|
106
|
+
);
|
|
107
|
+
}
|
|
78
108
|
return entry;
|
|
79
109
|
}
|
|
80
110
|
|
|
@@ -117,7 +147,11 @@ async function renderAndStoreSharedSsg(
|
|
|
117
147
|
): Promise<RuntimeSsgResult> {
|
|
118
148
|
try {
|
|
119
149
|
const entry = await input.renderFresh();
|
|
120
|
-
if (entry instanceof Response || lease === null) {
|
|
150
|
+
if (entry instanceof Response || entry.status !== 200 || lease === null) {
|
|
151
|
+
return { cacheStored: false, entry };
|
|
152
|
+
}
|
|
153
|
+
const identityTags = new Set(input.identity.tags);
|
|
154
|
+
if ((entry.tags ?? []).some((tag) => !identityTags.has(tag))) {
|
|
121
155
|
return { cacheStored: false, entry };
|
|
122
156
|
}
|
|
123
157
|
let cacheStored = false;
|
|
@@ -190,10 +224,7 @@ export async function prerenderRuntimeSSG(
|
|
|
190
224
|
): Promise<RuntimeSsgResult> {
|
|
191
225
|
const pageCache = getPageCacheAdapter();
|
|
192
226
|
if (pageCache === undefined) {
|
|
193
|
-
return
|
|
194
|
-
cacheStored: true,
|
|
195
|
-
entry: await prerenderSSG(route, params, root, origin, undefined, searchRoutes),
|
|
196
|
-
};
|
|
227
|
+
return prerenderLocalSSG(route, params, root, origin, undefined, searchRoutes);
|
|
197
228
|
}
|
|
198
229
|
|
|
199
230
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
@@ -203,11 +234,13 @@ export async function prerenderRuntimeSSG(
|
|
|
203
234
|
mode: "ssg",
|
|
204
235
|
path: resolvedPath,
|
|
205
236
|
scope: currentInstance().prefix,
|
|
206
|
-
tags:
|
|
237
|
+
tags: [
|
|
238
|
+
...new Set([...(route.tags ?? []), ...getAutoInvalidateRegistry().tagsForPath(resolvedPath)]),
|
|
239
|
+
],
|
|
207
240
|
};
|
|
208
241
|
const renderFresh = () =>
|
|
209
242
|
prerenderRoute(route, params, root, origin, "ssg", undefined, searchRoutes);
|
|
210
|
-
return resolveSharedSsg({ identity, pageCache, renderFresh });
|
|
243
|
+
return await resolveSharedSsg({ identity, pageCache, renderFresh });
|
|
211
244
|
}
|
|
212
245
|
|
|
213
246
|
/**
|
package/src/server/render/ssr.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Context } from "elysia";
|
|
2
2
|
import { createElement, type ReactNode } from "react";
|
|
3
|
-
import { renderToReadableStream } from "react-dom/server";
|
|
4
3
|
import { toCrossJSON, toCrossJSONAsync } from "seroval";
|
|
5
4
|
import { type DocumentAssets, FurinDocumentFallback } from "../../client/document.tsx";
|
|
6
5
|
import { RouterContext } from "../../client/router/context.ts";
|
|
@@ -17,8 +16,11 @@ import { computeErrorDigest } from "../../shared/digest.ts";
|
|
|
17
16
|
import { isProductionBuild } from "../../shared/production-build.ts";
|
|
18
17
|
import { containsRscSource, serializeRouteFrames } from "../../shared/route-frame.ts";
|
|
19
18
|
import type { SearchParamsInput, SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
19
|
+
import { queryTagsFromData } from "../../shared/sync-query.ts";
|
|
20
20
|
import { getLogger, runInSyntheticRenderScope } from "../context-logger.ts";
|
|
21
21
|
import { currentInstance } from "../instance.ts";
|
|
22
|
+
import { mergeRouteSchemas } from "../router/schema-merge.ts";
|
|
23
|
+
import { parseRouteParams, parseRouteQuery } from "../router/schemas.ts";
|
|
22
24
|
// FurinNotFoundError is used indirectly via buildNotFoundElement in element.tsx
|
|
23
25
|
import type { ResolvedRoute, RootLayout } from "../router/types.ts";
|
|
24
26
|
import { IS_DEV } from "../runtime-env.ts";
|
|
@@ -50,12 +52,14 @@ import {
|
|
|
50
52
|
runSegmentPublicLoaders,
|
|
51
53
|
serializeDeferredRejection,
|
|
52
54
|
} from "./loaders.ts";
|
|
55
|
+
import { renderToReadableStream } from "./react-stream.ts";
|
|
53
56
|
import { serializeDeferredRouteFrame } from "./route-frame-transport.ts";
|
|
54
57
|
import { generateIndexHtml, safeJson } from "./shell.ts";
|
|
55
58
|
import {
|
|
56
59
|
documentAssetsFromTemplate,
|
|
57
60
|
getDevDocumentAssets,
|
|
58
61
|
getProductionDocumentAssets,
|
|
62
|
+
getProductionPreloadManifest,
|
|
59
63
|
} from "./template.ts";
|
|
60
64
|
|
|
61
65
|
// Re-export types consumed by sibling render modules (not a public barrel).
|
|
@@ -74,6 +78,7 @@ export interface RenderResult {
|
|
|
74
78
|
* interchangeably.
|
|
75
79
|
*/
|
|
76
80
|
ndjson: string;
|
|
81
|
+
queryTags?: string[];
|
|
77
82
|
status: number;
|
|
78
83
|
}
|
|
79
84
|
|
|
@@ -266,9 +271,8 @@ export function assertDeferredModeAllowed(
|
|
|
266
271
|
route: ResolvedRoute,
|
|
267
272
|
deferredPromises: Record<string, Promise<unknown>> | undefined
|
|
268
273
|
): void {
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
);
|
|
274
|
+
const requestKeys = new Set(route.requestKeys);
|
|
275
|
+
const deferredKeys = Object.keys(deferredPromises ?? {}).filter((key) => !requestKeys.has(key));
|
|
272
276
|
if (deferredKeys.length > 0 && route.mode !== "ssr" && !hasSsrLoaderAncestor(route)) {
|
|
273
277
|
throw new Error(
|
|
274
278
|
`[furin] page "${route.pattern}" returned defer() but the route is rendered in "${route.mode}" mode. ` +
|
|
@@ -343,6 +347,11 @@ function resolveDocumentAssets(ctx: Context): DocumentAssets | Promise<DocumentA
|
|
|
343
347
|
return documentAssetsFromTemplate(generateIndexHtml());
|
|
344
348
|
}
|
|
345
349
|
|
|
350
|
+
function withRouteModulePreloads(assets: DocumentAssets, pattern: string): DocumentAssets {
|
|
351
|
+
const modulePreloads = getProductionPreloadManifest()?.routes[pattern];
|
|
352
|
+
return modulePreloads ? { ...assets, modulePreloads } : assets;
|
|
353
|
+
}
|
|
354
|
+
|
|
346
355
|
/**
|
|
347
356
|
* Shared pipeline steps used by both `renderToHTML` (buffered) and `renderSSR`
|
|
348
357
|
* (streaming). Runs loaders, builds props, head data, resolves assets,
|
|
@@ -368,9 +377,9 @@ export async function prepareRender(
|
|
|
368
377
|
return loaderResult.response;
|
|
369
378
|
}
|
|
370
379
|
|
|
371
|
-
// Build-time paths (SSG)
|
|
372
|
-
//
|
|
373
|
-
if (throwOnFailure &&
|
|
380
|
+
// Build-time paths (SSG) rethrow loader failures; authored notFound results
|
|
381
|
+
// still render their 404 document for static export.
|
|
382
|
+
if (throwOnFailure && loaderResult.type === "error") {
|
|
374
383
|
throw loaderResult.error;
|
|
375
384
|
}
|
|
376
385
|
|
|
@@ -388,7 +397,7 @@ export async function prepareRender(
|
|
|
388
397
|
const componentProps =
|
|
389
398
|
deferredPromises === undefined ? syncData : { ...syncData, ...deferredPromises };
|
|
390
399
|
|
|
391
|
-
const assets = await resolveDocumentAssets(ctx);
|
|
400
|
+
const assets = withRouteModulePreloads(await resolveDocumentAssets(ctx), route.pattern);
|
|
392
401
|
const errorComponent = route.error ?? root.error;
|
|
393
402
|
|
|
394
403
|
let element: ReactNode;
|
|
@@ -433,6 +442,7 @@ export async function prepareRender(
|
|
|
433
442
|
const ssrContext: RouterContextValue = {
|
|
434
443
|
basePath: resolvedBasePath,
|
|
435
444
|
currentHref: currentHrefFromContext(ctx, resolvedBasePath),
|
|
445
|
+
currentPattern: route.pattern,
|
|
436
446
|
defaultPreload: "intent",
|
|
437
447
|
defaultPreloadDelay: 50,
|
|
438
448
|
defaultPreloadStaleTime: 30_000,
|
|
@@ -509,10 +519,41 @@ async function renderBufferedResult(
|
|
|
509
519
|
headers,
|
|
510
520
|
html,
|
|
511
521
|
ndjson: await serializeLoaderDataNdjson(syncData, deferredPromises),
|
|
522
|
+
queryTags: queryTagsFromData(syncData),
|
|
512
523
|
status: prepared.status,
|
|
513
524
|
};
|
|
514
525
|
}
|
|
515
526
|
|
|
527
|
+
async function normalizePrerenderContext(
|
|
528
|
+
route: ResolvedRoute,
|
|
529
|
+
ctx: Omit<Context, "params" | "query"> & {
|
|
530
|
+
params: { [key: string]: unknown };
|
|
531
|
+
query: SearchParamsInput;
|
|
532
|
+
}
|
|
533
|
+
): Promise<void> {
|
|
534
|
+
const parsedParams = await parseRouteParams(
|
|
535
|
+
ctx.params,
|
|
536
|
+
mergeRouteSchemas(route.routeChain, "params")
|
|
537
|
+
);
|
|
538
|
+
if (!parsedParams.ok) {
|
|
539
|
+
throw new Error(`[furin] Invalid prerender params for "${route.pattern}".`, {
|
|
540
|
+
cause: parsedParams.errors,
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
ctx.params = parsedParams.params;
|
|
544
|
+
const querySchema = mergeRouteSchemas(route.routeChain, "query");
|
|
545
|
+
if (querySchema === undefined) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
const parsedQuery = await parseRouteQuery(new URL(ctx.request.url), querySchema);
|
|
549
|
+
if (!parsedQuery.ok) {
|
|
550
|
+
throw new Error(`[furin] Invalid prerender query for "${route.pattern}".`, {
|
|
551
|
+
cause: parsedQuery.errors,
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
ctx.query = parsedQuery.query;
|
|
555
|
+
}
|
|
556
|
+
|
|
516
557
|
export function renderForPath(
|
|
517
558
|
route: ResolvedRoute,
|
|
518
559
|
params: Record<string, string>,
|
|
@@ -553,6 +594,10 @@ export function renderForPath(
|
|
|
553
594
|
set: { headers: {} },
|
|
554
595
|
} as Context);
|
|
555
596
|
|
|
597
|
+
if (requestContext === undefined) {
|
|
598
|
+
await normalizePrerenderContext(route, ctx);
|
|
599
|
+
}
|
|
600
|
+
|
|
556
601
|
const loaderResult = await (hasMixedLoaderModes(route)
|
|
557
602
|
? runSegmentPublicLoaders(route, ctx)
|
|
558
603
|
: runPublicLoaders(route, ctx));
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// ── HTML template state (per furin instance) ────────────────────────────────
|
|
2
2
|
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
|
+
import type { ClientPreloadManifest } from "../../build/preload-manifest.ts";
|
|
5
|
+
import { setClientModuleHrefResolver } from "../../client/client-module.ts";
|
|
4
6
|
import type { DocumentAssets } from "../../client/document.tsx";
|
|
5
7
|
import { injectBrowserEventsClient } from "../browser-events/plugin.ts";
|
|
6
8
|
import { injectInstrumentationClient } from "../devtools/instrumentation.ts";
|
|
@@ -18,6 +20,7 @@ interface TemplateState {
|
|
|
18
20
|
prodAssets: DocumentAssets | null;
|
|
19
21
|
prodContent: string | null;
|
|
20
22
|
prodPath: string | null;
|
|
23
|
+
prodPreload: ClientPreloadManifest | null;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
const instanceTemplateState = instanceSlot(
|
|
@@ -27,6 +30,7 @@ const instanceTemplateState = instanceSlot(
|
|
|
27
30
|
prodAssets: null,
|
|
28
31
|
prodContent: null,
|
|
29
32
|
prodPath: null,
|
|
33
|
+
prodPreload: null,
|
|
30
34
|
})
|
|
31
35
|
);
|
|
32
36
|
|
|
@@ -206,6 +210,24 @@ function readDocumentAssets(state: TemplateState): DocumentAssets | null {
|
|
|
206
210
|
return state.prodAssets;
|
|
207
211
|
}
|
|
208
212
|
|
|
213
|
+
export function setProductionPreloadManifest(
|
|
214
|
+
manifest: ClientPreloadManifest,
|
|
215
|
+
instance?: FurinInstance
|
|
216
|
+
): void {
|
|
217
|
+
instanceTemplateState(instance).prodPreload = manifest;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** The client build's preload manifest, or `null` in dev and before a build. */
|
|
221
|
+
export function getProductionPreloadManifest(): ClientPreloadManifest | null {
|
|
222
|
+
return (
|
|
223
|
+
instanceTemplateState().prodPreload ??
|
|
224
|
+
instanceTemplateState(defaultInstanceBucket()).prodPreload
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Server-side clientModule() calls carry a build key instead of chunk URLs.
|
|
229
|
+
setClientModuleHrefResolver((key) => getProductionPreloadManifest()?.modules[key] ?? []);
|
|
230
|
+
|
|
209
231
|
/** @internal test-only — resets all template state */
|
|
210
232
|
export function __resetTemplateState(): void {
|
|
211
233
|
for (const instance of allStateBuckets()) {
|
|
@@ -215,5 +237,6 @@ export function __resetTemplateState(): void {
|
|
|
215
237
|
state.prodAssets = null;
|
|
216
238
|
state.prodContent = null;
|
|
217
239
|
state.prodPath = null;
|
|
240
|
+
state.prodPreload = null;
|
|
218
241
|
}
|
|
219
242
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RuntimePage, RuntimeRoute } from "../../client/internal/runtime-types.ts";
|
|
2
2
|
import type { HeadOptions, RenderingMode } from "../../client.ts";
|
|
3
|
+
import type { RemountDependency } from "../../shared/page-key.ts";
|
|
3
4
|
|
|
4
5
|
interface DefinedRouteTerminal {
|
|
5
6
|
__type: "FURIN_ROUTE";
|
|
@@ -10,6 +11,7 @@ interface DefinedRouteTerminal {
|
|
|
10
11
|
loader?: (...args: never[]) => unknown;
|
|
11
12
|
mode?: RenderingMode;
|
|
12
13
|
page?: (...args: never[]) => React.ReactNode;
|
|
14
|
+
remountDeps?: (context: never) => readonly RemountDependency[];
|
|
13
15
|
requestLoader?: (...args: never[]) => unknown;
|
|
14
16
|
revalidate?: number;
|
|
15
17
|
schemas?: { params?: unknown; query?: unknown };
|
|
@@ -66,6 +68,7 @@ export function adaptDefinedPage(route: DefinedRouteTerminal, parent: RuntimeRou
|
|
|
66
68
|
params: route.schemas?.params,
|
|
67
69
|
parent,
|
|
68
70
|
query: route.schemas?.query,
|
|
71
|
+
remountDeps: route.remountDeps as RuntimeRoute["remountDeps"],
|
|
69
72
|
requestLoader: route.requestLoader as RuntimeRoute["requestLoader"],
|
|
70
73
|
},
|
|
71
74
|
component,
|
package/src/server/router/hmr.ts
CHANGED
|
@@ -564,7 +564,7 @@ export async function renderDevSSGWithLoaderCache(
|
|
|
564
564
|
/**
|
|
565
565
|
* @internal Lists every source file whose contents can affect the render
|
|
566
566
|
* output for a given page: the page itself, every intermediate `_route.*`
|
|
567
|
-
* between the page and the pages root,
|
|
567
|
+
* between the page and the pages root, `root.tsx`, and their local imports.
|
|
568
568
|
*
|
|
569
569
|
* Only paths that EXIST on disk are returned. `isDevLoaderCacheValid` treats
|
|
570
570
|
* a `statSync` throw as "invalid" (conservative on missing files), so listing
|
|
@@ -583,5 +583,6 @@ export function computeRouteDependencies(pagePath: string, rootPath: string): st
|
|
|
583
583
|
}
|
|
584
584
|
}
|
|
585
585
|
}
|
|
586
|
-
|
|
586
|
+
const graph = devGraph(undefined);
|
|
587
|
+
return [...new Set(deps.flatMap((path) => graph.sourceDependencies(path)))].filter(existsSync);
|
|
587
588
|
}
|
|
@@ -3,6 +3,7 @@ import { toCrossJSONAsync } from "seroval";
|
|
|
3
3
|
import type { HeadOptions } from "../../client.ts";
|
|
4
4
|
import { computeErrorDigest } from "../../shared/digest.ts";
|
|
5
5
|
import type { FurinSchema } from "../../shared/elysia-contract.ts";
|
|
6
|
+
import { physicalPath } from "../../shared/prefix.ts";
|
|
6
7
|
import { containsRscSource } from "../../shared/route-frame.ts";
|
|
7
8
|
import type { SearchParamsInput, SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
8
9
|
import { getLogger } from "../context-logger.ts";
|
|
@@ -109,13 +110,10 @@ async function serializeLoaderDataResponse(
|
|
|
109
110
|
routeContext: RouteDataContext
|
|
110
111
|
): Promise<Response> {
|
|
111
112
|
if (result.type === "redirect") {
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return new Response(`${JSON.stringify(serialized)}\n`, {
|
|
117
|
-
headers: { "content-type": "application/x-ndjson" },
|
|
118
|
-
});
|
|
113
|
+
const { prefix } = currentInstance();
|
|
114
|
+
const pageUrl = new URL(requestUrl);
|
|
115
|
+
pageUrl.pathname = physicalPath(prefix, pageUrl.pathname);
|
|
116
|
+
return serializeNavigationRedirect(result.response, pageUrl, prefix);
|
|
119
117
|
}
|
|
120
118
|
if (result.type === "not-found") {
|
|
121
119
|
const serialized = await toCrossJSONAsync({
|
|
@@ -169,15 +167,29 @@ export async function serializeGuardRedirect(
|
|
|
169
167
|
const pageUrl = logicalPath
|
|
170
168
|
? new URL(prefix + logicalPath.pathname + logicalPath.url.search, requestUrl)
|
|
171
169
|
: requestUrl;
|
|
170
|
+
|
|
171
|
+
return await serializeNavigationRedirect(response, pageUrl, prefix);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function serializeNavigationRedirect(
|
|
175
|
+
response: Response,
|
|
176
|
+
pageUrl: URL,
|
|
177
|
+
prefix: string
|
|
178
|
+
): Promise<Response> {
|
|
179
|
+
const location = response.headers.get("location");
|
|
180
|
+
if (!location) {
|
|
181
|
+
return response;
|
|
182
|
+
}
|
|
172
183
|
const target = new URL(location, pageUrl);
|
|
173
184
|
const withinMount =
|
|
174
185
|
prefix === "" || target.pathname === prefix || target.pathname.startsWith(`${prefix}/`);
|
|
175
186
|
const href =
|
|
176
|
-
target.origin ===
|
|
187
|
+
target.origin === pageUrl.origin && withinMount
|
|
177
188
|
? (target.pathname.slice(prefix.length) || "/") + target.search + target.hash
|
|
178
189
|
: target.href;
|
|
179
190
|
const serialized = await toCrossJSONAsync({ __furinRedirect: href });
|
|
180
191
|
const headers = new Headers(response.headers);
|
|
192
|
+
headers.delete("content-length");
|
|
181
193
|
headers.delete("location");
|
|
182
194
|
headers.set("content-type", "application/x-ndjson");
|
|
183
195
|
headers.set("cache-control", "private, no-store");
|
|
@@ -343,11 +355,13 @@ async function handleSSGRequest(
|
|
|
343
355
|
return entry;
|
|
344
356
|
}
|
|
345
357
|
|
|
358
|
+
ctx.set.status = entry.status;
|
|
359
|
+
|
|
346
360
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
347
361
|
|
|
348
362
|
// ETag: "buildId:cachedAt" — unique per render cycle, changes after revalidatePath
|
|
349
363
|
const etag = buildId ? `"${buildId}:${entry.cachedAt}"` : null;
|
|
350
|
-
if (etag && ctx.request.headers.get("if-none-match") === etag) {
|
|
364
|
+
if (entry.status === 200 && etag && ctx.request.headers.get("if-none-match") === etag) {
|
|
351
365
|
ctx.set.status = 304;
|
|
352
366
|
return;
|
|
353
367
|
}
|
|
@@ -355,9 +369,10 @@ async function handleSSGRequest(
|
|
|
355
369
|
ctx.set.headers["content-type"] = "text/html; charset=utf-8";
|
|
356
370
|
// Browser: max-age=0 + must-revalidate → always validates via ETag (304 = free)
|
|
357
371
|
// CDN: s-maxage=31536000 → cache for 1 year, purge via revalidatePath + purger
|
|
358
|
-
ctx.set.headers["cache-control"] =
|
|
359
|
-
|
|
360
|
-
|
|
372
|
+
ctx.set.headers["cache-control"] =
|
|
373
|
+
cacheStored && entry.status === 200
|
|
374
|
+
? "public, max-age=0, must-revalidate, s-maxage=31536000"
|
|
375
|
+
: "no-store";
|
|
361
376
|
if (etag) {
|
|
362
377
|
ctx.set.headers.etag = etag;
|
|
363
378
|
}
|
|
@@ -59,9 +59,11 @@ export interface SyncAdapter {
|
|
|
59
59
|
completeMutation: (input: CompleteMutationInput) => Promise<CompleteMutationResult>;
|
|
60
60
|
currentCursor: () => Promise<string>;
|
|
61
61
|
/**
|
|
62
|
-
* Identifies
|
|
62
|
+
* Identifies the journal namespace's notification channel.
|
|
63
63
|
*/
|
|
64
64
|
readonly notificationChannel?: string;
|
|
65
|
+
/** False when completion requires an explicit wake-up after cache invalidation. */
|
|
66
|
+
readonly publishesNotifications?: boolean;
|
|
65
67
|
readChanges: (input: ReadChangesInput) => Promise<ChangePage>;
|
|
66
68
|
renewMutation: (lease: MutationLease) => Promise<"lost" | "renewed">;
|
|
67
69
|
readonly scope: "distributed" | "host-local" | "process-local";
|
|
@@ -73,7 +75,7 @@ export interface SyncSubscription {
|
|
|
73
75
|
|
|
74
76
|
export interface SyncNotifier {
|
|
75
77
|
/**
|
|
76
|
-
* Matches
|
|
78
|
+
* Matches the adapter's journal namespace for notifications and recovery.
|
|
77
79
|
*/
|
|
78
80
|
readonly notificationChannel?: string;
|
|
79
81
|
publish: (cursor: string) => Promise<void>;
|
|
@@ -85,8 +87,43 @@ export interface SyncNotifier {
|
|
|
85
87
|
subscribe: (listener: (cursor: string) => void) => Promise<SyncSubscription>;
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
export interface
|
|
89
|
-
|
|
90
|
+
export interface AtomicMutationValue<T> {
|
|
91
|
+
invalidations: readonly SyncInvalidation[];
|
|
92
|
+
response: StoredResponse;
|
|
93
|
+
value: T;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface AtomicMutationResult<T> {
|
|
97
|
+
cursor: string | undefined;
|
|
98
|
+
kind: "committed";
|
|
99
|
+
response: StoredResponse;
|
|
100
|
+
value: T;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface TransactionalSyncAdapter<Tx, Mode extends "async" | "sync"> extends SyncAdapter {
|
|
104
|
+
executeMutation: <T>(
|
|
105
|
+
lease: MutationLease,
|
|
106
|
+
callback: (tx: Tx) => AtomicMutationValue<T> | Promise<AtomicMutationValue<T>>
|
|
107
|
+
) => Promise<AtomicMutationResult<T>>;
|
|
108
|
+
readonly transactionMode: Mode;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type SyncTransaction<Adapter> =
|
|
112
|
+
Adapter extends TransactionalSyncAdapter<infer Tx, "async" | "sync"> ? Tx : never;
|
|
113
|
+
|
|
114
|
+
export type SyncMutation<Adapter> = <T>(
|
|
115
|
+
callback: (
|
|
116
|
+
tx: SyncTransaction<Adapter>
|
|
117
|
+
) => T &
|
|
118
|
+
(Adapter extends { transactionMode: "sync" }
|
|
119
|
+
? T extends PromiseLike<unknown>
|
|
120
|
+
? never
|
|
121
|
+
: unknown
|
|
122
|
+
: unknown)
|
|
123
|
+
) => Promise<Awaited<T>>;
|
|
124
|
+
|
|
125
|
+
export interface SyncRuntimeOptions<Adapter extends SyncAdapter = SyncAdapter> {
|
|
126
|
+
adapter: Adapter;
|
|
90
127
|
notifier?: SyncNotifier;
|
|
91
128
|
principal: (context: Context) => Promise<string> | string;
|
|
92
129
|
}
|