@teyik0/furin 0.6.0-alpha.1 → 0.7.0-alpha.2
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/elysia-aot-worker.d.ts +22 -0
- package/dist/build/elysia-aot.d.ts +1 -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 +1880 -401
- package/dist/build/preload-manifest.d.ts +17 -0
- package/dist/build/types.d.ts +6 -0
- package/dist/cli/index.js +1878 -408
- 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 +942 -122
- 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 +51 -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 +2484 -708
- 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/router/patterns.d.ts +2 -0
- package/dist/server/router/types.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/elysia-aot-worker.ts +51 -0
- package/src/build/elysia-aot.ts +83 -19
- package/src/build/entry-template.ts +7 -0
- package/src/build/hydrate.ts +21 -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 +19 -12
- 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 +306 -46
- 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 +73 -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 +28 -16
- 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 +21 -11
- 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/discovery.ts +25 -9
- package/src/server/router/hmr.ts +3 -2
- package/src/server/router/patterns.ts +16 -0
- package/src/server/router/plugin.ts +27 -12
- package/src/server/router/types.ts +1 -1
- 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/isr.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { createElement } from "react";
|
|
|
4
4
|
import { FurinDocumentFallback } from "../../client/document.tsx";
|
|
5
5
|
import { isNotFoundError } from "../../shared/not-found.ts";
|
|
6
6
|
import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
7
|
-
import {
|
|
7
|
+
import { queryTagsFromData } from "../../shared/sync-query.ts";
|
|
8
|
+
import { autoInvalidateRegistry, getAutoInvalidateRegistry } from "../auto-invalidate/registry.ts";
|
|
8
9
|
import {
|
|
9
10
|
captureISRCacheGeneration,
|
|
10
11
|
deleteISRCache,
|
|
@@ -452,11 +453,16 @@ async function renderISRCacheMiss(input: ISRCacheMissInput): Promise<Response |
|
|
|
452
453
|
route: input.route.pattern,
|
|
453
454
|
},
|
|
454
455
|
});
|
|
455
|
-
const
|
|
456
|
+
const discoveredTags = queryTagsFromData(syncData);
|
|
457
|
+
const identityTags = new Set(input.pageCacheIdentity.tags);
|
|
458
|
+
const cacheStored =
|
|
459
|
+
input.pageCache !== undefined && discoveredTags.some((tag) => !identityTags.has(tag))
|
|
460
|
+
? false
|
|
461
|
+
: await storeRenderedISR(input, html, generatedAt);
|
|
456
462
|
if (cacheStored && input.pageCache === undefined) {
|
|
457
463
|
autoInvalidateRegistry.registerLoaderTags(
|
|
458
464
|
input.cacheKey,
|
|
459
|
-
input.route.tags,
|
|
465
|
+
[...(input.route.tags ?? []), ...discoveredTags],
|
|
460
466
|
"render:isr-html"
|
|
461
467
|
);
|
|
462
468
|
}
|
|
@@ -496,7 +502,9 @@ export async function handleISR(
|
|
|
496
502
|
mode: "isr",
|
|
497
503
|
path: resolvedPath,
|
|
498
504
|
scope: currentInstance().prefix,
|
|
499
|
-
tags:
|
|
505
|
+
tags: [
|
|
506
|
+
...new Set([...(route.tags ?? []), ...getAutoInvalidateRegistry().tagsForPath(cacheKey)]),
|
|
507
|
+
],
|
|
500
508
|
};
|
|
501
509
|
|
|
502
510
|
const lookup = await lookupISRCache(
|
|
@@ -662,33 +670,11 @@ async function handleBackgroundRevalidationError(
|
|
|
662
670
|
input: BackgroundRevalidationInput,
|
|
663
671
|
error: unknown
|
|
664
672
|
): Promise<void> {
|
|
665
|
-
const logger = createLogger({});
|
|
666
673
|
if (isNotFoundError(error)) {
|
|
667
|
-
|
|
668
|
-
deleteISRCache(input.cacheKey);
|
|
669
|
-
} else {
|
|
670
|
-
try {
|
|
671
|
-
await input.sharedCache.adapter.invalidate({
|
|
672
|
-
kind: "path",
|
|
673
|
-
path: input.sharedCache.identity.path,
|
|
674
|
-
scope: input.sharedCache.identity.scope,
|
|
675
|
-
type: "page",
|
|
676
|
-
});
|
|
677
|
-
} catch {
|
|
678
|
-
logger.warn("ISR shared page cache invalidation failed after not-found revalidation");
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
logger.set({
|
|
682
|
-
furin: {
|
|
683
|
-
cache: "revalidation_invalidated",
|
|
684
|
-
reason: "not_found",
|
|
685
|
-
render: "isr",
|
|
686
|
-
route: input.route.pattern,
|
|
687
|
-
},
|
|
688
|
-
});
|
|
689
|
-
logger.emit();
|
|
674
|
+
await invalidateBackgroundNotFound(input);
|
|
690
675
|
return;
|
|
691
676
|
}
|
|
677
|
+
const logger = createLogger({});
|
|
692
678
|
logger.set({
|
|
693
679
|
furin: {
|
|
694
680
|
cache: "revalidation_failed",
|
|
@@ -700,6 +686,36 @@ async function handleBackgroundRevalidationError(
|
|
|
700
686
|
logger.emit();
|
|
701
687
|
}
|
|
702
688
|
|
|
689
|
+
async function invalidateBackgroundNotFound(input: BackgroundRevalidationInput): Promise<void> {
|
|
690
|
+
if (input.sharedCache === undefined && !input.cacheGeneration?.valid) {
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
const logger = createLogger({});
|
|
694
|
+
if (input.sharedCache === undefined) {
|
|
695
|
+
deleteISRCache(input.cacheKey);
|
|
696
|
+
} else {
|
|
697
|
+
try {
|
|
698
|
+
await input.sharedCache.adapter.invalidate({
|
|
699
|
+
kind: "path",
|
|
700
|
+
path: input.sharedCache.identity.path,
|
|
701
|
+
scope: input.sharedCache.identity.scope,
|
|
702
|
+
type: "page",
|
|
703
|
+
});
|
|
704
|
+
} catch {
|
|
705
|
+
logger.warn("ISR shared page cache invalidation failed after not-found revalidation");
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
logger.set({
|
|
709
|
+
furin: {
|
|
710
|
+
cache: "revalidation_invalidated",
|
|
711
|
+
reason: "not_found",
|
|
712
|
+
render: "isr",
|
|
713
|
+
route: input.route.pattern,
|
|
714
|
+
},
|
|
715
|
+
});
|
|
716
|
+
logger.emit();
|
|
717
|
+
}
|
|
718
|
+
|
|
703
719
|
async function releaseBackgroundRevalidation(
|
|
704
720
|
input: BackgroundRevalidationInput,
|
|
705
721
|
lease: PageCacheLease | null
|
|
@@ -742,22 +758,38 @@ async function performBackgroundRevalidation(input: BackgroundRevalidationInput)
|
|
|
742
758
|
if (result instanceof Response) {
|
|
743
759
|
return;
|
|
744
760
|
}
|
|
761
|
+
if (result.status === 404) {
|
|
762
|
+
await invalidateBackgroundNotFound(input);
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
745
765
|
if (result.status !== 200) {
|
|
746
766
|
logRevalidationSkipped(input.route, "non_200_render", result.status);
|
|
747
767
|
return;
|
|
748
768
|
}
|
|
749
769
|
if (input.sharedCache !== undefined && lease !== null) {
|
|
770
|
+
const { identity } = input.sharedCache;
|
|
771
|
+
const identityTags = new Set(identity.tags);
|
|
772
|
+
if ((result.queryTags ?? []).some((tag) => !identityTags.has(tag))) {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
750
775
|
await input.sharedCache.adapter.commit({
|
|
751
776
|
entry: { cachedAt: Date.now(), payload: result.html, revalidate: input.revalidate },
|
|
752
777
|
identity: input.sharedCache.identity,
|
|
753
778
|
lease,
|
|
754
779
|
});
|
|
755
780
|
} else if (input.cacheGeneration !== undefined) {
|
|
756
|
-
setISRCacheIfGenerationUnchanged(
|
|
781
|
+
const stored = setISRCacheIfGenerationUnchanged(
|
|
757
782
|
input.cacheKey,
|
|
758
783
|
{ generatedAt: Date.now(), html: result.html, revalidate: input.revalidate },
|
|
759
784
|
input.cacheGeneration
|
|
760
785
|
);
|
|
786
|
+
if (stored) {
|
|
787
|
+
autoInvalidateRegistry.registerLoaderTags(
|
|
788
|
+
input.cacheKey,
|
|
789
|
+
[...(input.route.tags ?? []), ...(result.queryTags ?? [])],
|
|
790
|
+
"render:isr-html"
|
|
791
|
+
);
|
|
792
|
+
}
|
|
761
793
|
}
|
|
762
794
|
} catch (error: unknown) {
|
|
763
795
|
await handleBackgroundRevalidationError(input, error);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Context } from "elysia";
|
|
2
2
|
import type { RuntimePage, RuntimeRoute } from "../../client/internal/runtime-types.ts";
|
|
3
|
-
import { isDeferred } from "../../client.ts";
|
|
4
3
|
import type { RequestLoaderContext } from "../../define-route.ts";
|
|
5
4
|
import { isFurinRscRenderError } from "../../rsc/render-error.ts";
|
|
5
|
+
import { isDeferred } from "../../shared/defer.ts";
|
|
6
6
|
import { computeErrorDigest } from "../../shared/digest.ts";
|
|
7
7
|
import { type FurinNotFoundError, isNotFoundError } from "../../shared/not-found.ts";
|
|
8
8
|
import { getLogger } from "../context-logger.ts";
|
|
@@ -10,6 +10,7 @@ import { currentInstrumentationRequest, emitLoaderFinished } from "../devtools/i
|
|
|
10
10
|
import { resolveRouteRevalidate } from "../router/patterns.ts";
|
|
11
11
|
import type { ResolvedRoute } from "../router/types.ts";
|
|
12
12
|
import { IS_DEV } from "../runtime-env.ts";
|
|
13
|
+
import { captureQueryReads } from "../sync/query-context.ts";
|
|
13
14
|
import { cacheMixedPublicLoader } from "./mixed-cache.ts";
|
|
14
15
|
|
|
15
16
|
export type LoaderResult =
|
|
@@ -38,12 +39,13 @@ export type LoaderResult =
|
|
|
38
39
|
* has already been consumed by `runLoaders` (do NOT read it again).
|
|
39
40
|
*/
|
|
40
41
|
error: unknown;
|
|
41
|
-
/** HTTP status to return. Default 500; sourced from
|
|
42
|
+
/** HTTP status to return. Default 500; sourced from thrown Responses and Eden problems. */
|
|
42
43
|
status: number;
|
|
43
44
|
/**
|
|
44
45
|
* Safe public message extracted at the loader boundary. For thrown
|
|
45
46
|
* `Response` objects: response body or `statusText`. For thrown `Error`
|
|
46
|
-
*
|
|
47
|
+
* values carrying an Eden problem: its detail or title. For other
|
|
48
|
+
* `Error` / non-Error values: a generic "Something went wrong" string (the raw
|
|
47
49
|
* error/message is never leaked here — `errorMessageOf` decides what to
|
|
48
50
|
* surface from the original `error` value when an `error.tsx` fallback
|
|
49
51
|
* exists).
|
|
@@ -90,6 +92,19 @@ function assertPublicLoaderKey(key: string): void {
|
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
|
|
95
|
+
function assertRequestLoaderKey(key: string, ctx: Context): void {
|
|
96
|
+
assertPublicLoaderKey(key);
|
|
97
|
+
if (
|
|
98
|
+
key === "log" ||
|
|
99
|
+
Object.hasOwn(ctx, key) ||
|
|
100
|
+
(key in ctx && !Object.hasOwn(Object.prototype, key))
|
|
101
|
+
) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`[furin] requestLoader data key "${key}" is reserved: it is overwritten by the SSR loader context. Rename this field to avoid conflicts.`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
93
108
|
/**
|
|
94
109
|
* `true` only for HTTP responses that are syntactically valid redirects:
|
|
95
110
|
* a navigation redirect status code AND a `Location` header. A redirect status
|
|
@@ -120,8 +135,9 @@ async function readResponseMessage(res: Response): Promise<string> {
|
|
|
120
135
|
/**
|
|
121
136
|
* Wraps the Elysia context so that any property NOT present on `ctx` is
|
|
122
137
|
* returned as an individual `Promise<value>` resolved from the accumulated
|
|
123
|
-
* parent data.
|
|
124
|
-
*
|
|
138
|
+
* parent data. Inherited request fields use their own promises, independent
|
|
139
|
+
* of public parent loaders. Properties that ARE present on `ctx` (request,
|
|
140
|
+
* params, set, …) are returned as-is.
|
|
125
141
|
*
|
|
126
142
|
* A per-prop cache ensures the same Promise instance is returned on repeated
|
|
127
143
|
* access of the same field (stable reference for Promise.all etc.).
|
|
@@ -129,6 +145,7 @@ async function readResponseMessage(res: Response): Promise<string> {
|
|
|
129
145
|
function createLoaderCtx(
|
|
130
146
|
ctx: Record<string, unknown>,
|
|
131
147
|
accumulatedParentPromise: Promise<Record<string, unknown>>,
|
|
148
|
+
inheritedRequestFields: Record<string, Promise<unknown>> | undefined,
|
|
132
149
|
onParentFieldAccess?: (key: string) => void
|
|
133
150
|
): Record<string, unknown> {
|
|
134
151
|
const cache = new Map<string, Promise<unknown>>();
|
|
@@ -152,6 +169,9 @@ function createLoaderCtx(
|
|
|
152
169
|
) {
|
|
153
170
|
return target[prop];
|
|
154
171
|
}
|
|
172
|
+
if (inheritedRequestFields && Object.hasOwn(inheritedRequestFields, prop)) {
|
|
173
|
+
return inheritedRequestFields[prop];
|
|
174
|
+
}
|
|
155
175
|
// Everything else is a parent-data field → individual lazy Promise.
|
|
156
176
|
onParentFieldAccess?.(prop);
|
|
157
177
|
let entry = cache.get(prop);
|
|
@@ -284,7 +304,13 @@ function observeLoader<T extends object>(
|
|
|
284
304
|
export function runRequestLoaderFields(
|
|
285
305
|
route: ResolvedRoute,
|
|
286
306
|
ctx: Context
|
|
287
|
-
):
|
|
307
|
+
):
|
|
308
|
+
| {
|
|
309
|
+
fields: Record<string, Promise<unknown>>;
|
|
310
|
+
fieldsByLoader: Record<string, Promise<unknown>>[];
|
|
311
|
+
noFieldCompletion: Promise<void>;
|
|
312
|
+
}
|
|
313
|
+
| undefined {
|
|
288
314
|
const loaderIndexes = route.routeChain.flatMap((entry, index) =>
|
|
289
315
|
entry.requestLoader ? [index] : []
|
|
290
316
|
);
|
|
@@ -304,6 +330,8 @@ export function runRequestLoaderFields(
|
|
|
304
330
|
if (declarations?.length !== route.routeChain.length) {
|
|
305
331
|
throw new Error(`[furin] Missing per-loader request field metadata for ${route.pattern}.`);
|
|
306
332
|
}
|
|
333
|
+
const declaredKeys = declarations.map((keys) => new Set(keys));
|
|
334
|
+
const requestKeys = new Set(route.requestKeys);
|
|
307
335
|
const requestContext = createRequestLoaderContext(ctx);
|
|
308
336
|
const results = loaderIndexes.map((index) => {
|
|
309
337
|
const loader = route.routeChain[index]?.requestLoader;
|
|
@@ -314,8 +342,8 @@ export function runRequestLoaderFields(
|
|
|
314
342
|
const result = observeLoader(() => invocation, `request:${index}`, ctx.path).then((value) => {
|
|
315
343
|
const data = value as Record<string, unknown>;
|
|
316
344
|
for (const key of Object.keys(data)) {
|
|
317
|
-
|
|
318
|
-
if (!
|
|
345
|
+
assertRequestLoaderKey(key, ctx);
|
|
346
|
+
if (!declaredKeys[index]?.has(key)) {
|
|
319
347
|
throw new Error(
|
|
320
348
|
`[furin] requestLoader in ${route.pattern} returned undeclared field "${key}".`
|
|
321
349
|
);
|
|
@@ -328,23 +356,34 @@ export function runRequestLoaderFields(
|
|
|
328
356
|
});
|
|
329
357
|
return { index, result };
|
|
330
358
|
});
|
|
331
|
-
|
|
359
|
+
let fields: Record<string, Promise<unknown>> = {};
|
|
360
|
+
const fieldsByLoader = route.routeChain.map((_, boundaryIndex) => {
|
|
361
|
+
fields = { ...fields };
|
|
362
|
+
for (const key of declarations[boundaryIndex] ?? []) {
|
|
363
|
+
if (!requestKeys.has(key)) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
const candidates = results.filter(
|
|
367
|
+
({ index }) => index <= boundaryIndex && declaredKeys[index]?.has(key)
|
|
368
|
+
);
|
|
369
|
+
fields[key] = Promise.all(candidates.map(({ result }) => result)).then((values) => {
|
|
370
|
+
for (let index = values.length - 1; index >= 0; index -= 1) {
|
|
371
|
+
const data = values[index];
|
|
372
|
+
if (data && Object.hasOwn(data, key)) {
|
|
373
|
+
return data[key];
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
fields[key].catch(() => {
|
|
378
|
+
/* React or the transport observes the original rejection after public loaders settle. */
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
return fields;
|
|
382
|
+
});
|
|
332
383
|
for (const key of route.requestKeys) {
|
|
333
|
-
|
|
334
|
-
if (candidates.length === 0) {
|
|
384
|
+
if (!Object.hasOwn(fields, key)) {
|
|
335
385
|
throw new Error(`[furin] No requestLoader declares field "${key}" in ${route.pattern}.`);
|
|
336
386
|
}
|
|
337
|
-
fields[key] = Promise.all(candidates.map(({ result }) => result)).then((values) => {
|
|
338
|
-
for (let index = values.length - 1; index >= 0; index -= 1) {
|
|
339
|
-
const data = values[index];
|
|
340
|
-
if (data && Object.hasOwn(data, key)) {
|
|
341
|
-
return data[key];
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
fields[key].catch(() => {
|
|
346
|
-
/* React or the transport observes the original rejection after public loaders settle. */
|
|
347
|
-
});
|
|
348
387
|
}
|
|
349
388
|
const noFieldCompletion = Promise.all(
|
|
350
389
|
results.filter(({ index }) => declarations[index]?.length === 0).map(({ result }) => result)
|
|
@@ -352,7 +391,7 @@ export function runRequestLoaderFields(
|
|
|
352
391
|
noFieldCompletion.catch(() => {
|
|
353
392
|
/* The caller observes this after the public loaders settle. */
|
|
354
393
|
});
|
|
355
|
-
return { fields, noFieldCompletion };
|
|
394
|
+
return { fields, fieldsByLoader, noFieldCompletion };
|
|
356
395
|
}
|
|
357
396
|
|
|
358
397
|
function requestFieldPromises(
|
|
@@ -371,30 +410,36 @@ function requestFieldPromises(
|
|
|
371
410
|
return fields;
|
|
372
411
|
}
|
|
373
412
|
|
|
374
|
-
export
|
|
413
|
+
export function withRequestLoaderData(
|
|
375
414
|
route: ResolvedRoute,
|
|
376
415
|
ctx: Context,
|
|
377
416
|
publicResult: Extract<LoaderResult, { type: "data" }>
|
|
378
417
|
): Promise<Extract<LoaderResult, { type: "data" }>> {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
418
|
+
return captureQueryReads(
|
|
419
|
+
ctx,
|
|
420
|
+
async () => {
|
|
421
|
+
const requestFields = runRequestLoaderFields(route, ctx);
|
|
422
|
+
if (requestFields === undefined) {
|
|
423
|
+
throw new Error(
|
|
424
|
+
"[furin] internal invariant: requestLoader data requested for a route without requestLoader"
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
await requestFields.noFieldCompletion;
|
|
428
|
+
return {
|
|
429
|
+
...publicResult,
|
|
430
|
+
deferredPromises: {
|
|
431
|
+
...(publicResult.deferredPromises ?? {}),
|
|
432
|
+
...requestFieldPromises(
|
|
433
|
+
route,
|
|
434
|
+
requestFields.fields,
|
|
435
|
+
publicResult.syncData,
|
|
436
|
+
publicResult.deferredPromises
|
|
437
|
+
),
|
|
438
|
+
},
|
|
439
|
+
};
|
|
396
440
|
},
|
|
397
|
-
|
|
441
|
+
"eden-request-queries"
|
|
442
|
+
);
|
|
398
443
|
}
|
|
399
444
|
|
|
400
445
|
/**
|
|
@@ -512,6 +557,28 @@ async function normalizeLoaderError(
|
|
|
512
557
|
const message = body || "Something went wrong";
|
|
513
558
|
return { error: err, headers, message, status, type: "error" };
|
|
514
559
|
}
|
|
560
|
+
if (
|
|
561
|
+
err instanceof Error &&
|
|
562
|
+
"status" in err &&
|
|
563
|
+
typeof err.status === "number" &&
|
|
564
|
+
err.status >= 400 &&
|
|
565
|
+
err.status <= 599 &&
|
|
566
|
+
"value" in err &&
|
|
567
|
+
err.value !== null &&
|
|
568
|
+
typeof err.value === "object" &&
|
|
569
|
+
"status" in err.value &&
|
|
570
|
+
err.value.status === err.status &&
|
|
571
|
+
"type" in err.value &&
|
|
572
|
+
typeof err.value.type === "string"
|
|
573
|
+
) {
|
|
574
|
+
let message = "Something went wrong";
|
|
575
|
+
if ("detail" in err.value && typeof err.value.detail === "string") {
|
|
576
|
+
message = err.value.detail;
|
|
577
|
+
} else if ("title" in err.value && typeof err.value.title === "string") {
|
|
578
|
+
message = err.value.title;
|
|
579
|
+
}
|
|
580
|
+
return { error: err, headers, message, status: err.status, type: "error" };
|
|
581
|
+
}
|
|
515
582
|
if (isFurinRscRenderError(err)) {
|
|
516
583
|
getLogger().error(err);
|
|
517
584
|
return {
|
|
@@ -556,6 +623,7 @@ function startSegmentLoader(
|
|
|
556
623
|
label: string,
|
|
557
624
|
parent: Promise<Record<string, unknown>>,
|
|
558
625
|
publicParent: Promise<Record<string, unknown>>,
|
|
626
|
+
inheritedRequestFields: Record<string, Promise<unknown>> | undefined,
|
|
559
627
|
ctxRecord: Record<string, unknown>,
|
|
560
628
|
publicCtxRecord: Record<string, unknown>,
|
|
561
629
|
mixed: boolean
|
|
@@ -565,6 +633,7 @@ function startSegmentLoader(
|
|
|
565
633
|
const loaderCtx = createLoaderCtx(
|
|
566
634
|
publicSegment ? publicCtxRecord : ctxRecord,
|
|
567
635
|
publicSegment ? publicParent : parent,
|
|
636
|
+
publicSegment ? undefined : inheritedRequestFields,
|
|
568
637
|
publicSegment ? (key) => parentFieldsRead.add(key) : undefined
|
|
569
638
|
);
|
|
570
639
|
return observeLoader(
|
|
@@ -605,7 +674,7 @@ async function runLoadersInternal(
|
|
|
605
674
|
let publicParentPromise: Promise<Record<string, unknown>> = Promise.resolve({});
|
|
606
675
|
|
|
607
676
|
let loaderIndex = 0;
|
|
608
|
-
for (const r of route.routeChain) {
|
|
677
|
+
for (const [routeIndex, r] of route.routeChain.entries()) {
|
|
609
678
|
const parentAccum = accumulatedParentPromise; // capture for closure
|
|
610
679
|
const publicParent = publicParentPromise;
|
|
611
680
|
const privateSegment = mixed && (r.mode ?? route.mode) === "ssr";
|
|
@@ -620,6 +689,7 @@ async function runLoadersInternal(
|
|
|
620
689
|
`layout:${loaderIndex}`,
|
|
621
690
|
parentAccum,
|
|
622
691
|
publicParent,
|
|
692
|
+
requestFields?.fieldsByLoader[routeIndex - 1],
|
|
623
693
|
ctxRecord,
|
|
624
694
|
publicCtxRecord,
|
|
625
695
|
mixed
|
|
@@ -662,6 +732,7 @@ async function runLoadersInternal(
|
|
|
662
732
|
"page",
|
|
663
733
|
accumulatedParentPromise,
|
|
664
734
|
publicParentPromise,
|
|
735
|
+
requestFields?.fields,
|
|
665
736
|
ctxRecord,
|
|
666
737
|
publicCtxRecord,
|
|
667
738
|
mixed
|
|
@@ -730,11 +801,11 @@ function createPublicLoaderContext(ctx: Context): { [key: string]: unknown } {
|
|
|
730
801
|
}
|
|
731
802
|
|
|
732
803
|
export function runLoaders(route: ResolvedRoute, ctx: Context): Promise<LoaderResult> {
|
|
733
|
-
return runLoadersInternal(route, ctx, true, false);
|
|
804
|
+
return captureQueryReads(ctx, () => runLoadersInternal(route, ctx, true, false));
|
|
734
805
|
}
|
|
735
806
|
|
|
736
807
|
export function runPublicLoaders(route: ResolvedRoute, ctx: Context): Promise<LoaderResult> {
|
|
737
|
-
return runLoadersInternal(route, ctx, false, false);
|
|
808
|
+
return captureQueryReads(ctx, () => runLoadersInternal(route, ctx, false, false));
|
|
738
809
|
}
|
|
739
810
|
|
|
740
811
|
export function hasSsrLoaderAncestor(route: ResolvedRoute): boolean {
|
|
@@ -754,7 +825,7 @@ export function hasMixedLoaderModes(route: ResolvedRoute): boolean {
|
|
|
754
825
|
}
|
|
755
826
|
|
|
756
827
|
export function runMixedLoaders(route: ResolvedRoute, ctx: Context): Promise<LoaderResult> {
|
|
757
|
-
return runLoadersInternal(route, ctx, true, true);
|
|
828
|
+
return captureQueryReads(ctx, () => runLoadersInternal(route, ctx, true, true));
|
|
758
829
|
}
|
|
759
830
|
|
|
760
831
|
export function runRouteLoaders(route: ResolvedRoute, ctx: Context): Promise<LoaderResult> {
|
|
@@ -762,7 +833,7 @@ export function runRouteLoaders(route: ResolvedRoute, ctx: Context): Promise<Loa
|
|
|
762
833
|
}
|
|
763
834
|
|
|
764
835
|
export function runSegmentPublicLoaders(route: ResolvedRoute, ctx: Context): Promise<LoaderResult> {
|
|
765
|
-
return runLoadersInternal(route, ctx, false, true);
|
|
836
|
+
return captureQueryReads(ctx, () => runLoadersInternal(route, ctx, false, true));
|
|
766
837
|
}
|
|
767
838
|
|
|
768
839
|
export function hasRequestLoader(route: ResolvedRoute): boolean {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Context } from "elysia";
|
|
2
2
|
import { fromCrossJSON, toCrossJSONAsync } from "seroval";
|
|
3
3
|
import type { RuntimePage, RuntimeRoute } from "../../client/internal/runtime-types.ts";
|
|
4
|
+
import { currentQueryEnvironment } from "../../client/query-store.ts";
|
|
4
5
|
import { toLogical } from "../../client/router/link-utils.ts";
|
|
5
|
-
import { isDeferred } from "../../
|
|
6
|
+
import { isDeferred } from "../../shared/defer.ts";
|
|
7
|
+
import { bindQueryData, projectQueryData } from "../../shared/query-bindings.ts";
|
|
8
|
+
import { type QuerySeed, queryTag } from "../../shared/sync-query.ts";
|
|
6
9
|
import { autoInvalidateRegistry, getAutoInvalidateRegistry } from "../auto-invalidate/registry.ts";
|
|
7
10
|
import type { PageCacheAdapter, PageCacheIdentity, PageCacheLease } from "../cache/page-cache.ts";
|
|
8
11
|
import { getPageCacheAdapter } from "../cache/page-cache-state.ts";
|
|
@@ -27,6 +30,15 @@ interface ParentDependency {
|
|
|
27
30
|
interface SegmentSnapshot {
|
|
28
31
|
data: Parameters<typeof fromCrossJSON>[0];
|
|
29
32
|
dependencies: ParentDependency[];
|
|
33
|
+
queries?: QuerySeed[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function capturedQueryTags(): string[] {
|
|
37
|
+
return (
|
|
38
|
+
currentQueryEnvironment()
|
|
39
|
+
?.store.dehydrate()
|
|
40
|
+
.map((seed) => queryTag(seed.identity)) ?? []
|
|
41
|
+
);
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
const mixedCacheKey = Symbol("furin-mixed-loader-cache");
|
|
@@ -115,7 +127,11 @@ async function readCachedSegment(
|
|
|
115
127
|
return;
|
|
116
128
|
}
|
|
117
129
|
}
|
|
118
|
-
|
|
130
|
+
const environment = currentQueryEnvironment();
|
|
131
|
+
environment?.store.hydrate(snapshot.queries ?? []);
|
|
132
|
+
environment?.onRead();
|
|
133
|
+
const data = fromCrossJSON(snapshot.data, {}) as Record<string, unknown>;
|
|
134
|
+
return projectQueryData(data, snapshot.queries ?? [], (seed) => seed.data);
|
|
119
135
|
} catch {
|
|
120
136
|
getLogger().warn("Mixed loader cache entry is invalid; loading fresh data");
|
|
121
137
|
}
|
|
@@ -136,6 +152,9 @@ async function createSegmentSnapshot(
|
|
|
136
152
|
return JSON.stringify({
|
|
137
153
|
data: await toCrossJSONAsync(data),
|
|
138
154
|
dependencies,
|
|
155
|
+
queries: bindQueryData(data, currentQueryEnvironment()?.store.dehydrate() ?? []).filter(
|
|
156
|
+
(seed) => (seed.bindings?.length ?? 0) > 0
|
|
157
|
+
),
|
|
139
158
|
} satisfies SegmentSnapshot);
|
|
140
159
|
}
|
|
141
160
|
|
|
@@ -184,6 +203,10 @@ async function commitSharedSegment(
|
|
|
184
203
|
cached: CachedSegment,
|
|
185
204
|
revalidate: number
|
|
186
205
|
): Promise<void> {
|
|
206
|
+
const identityTags = new Set(identity.tags);
|
|
207
|
+
if (capturedQueryTags().some((tag) => !identityTags.has(tag))) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
187
210
|
try {
|
|
188
211
|
await shared.commit({
|
|
189
212
|
entry: {
|
|
@@ -235,6 +258,7 @@ export async function cacheMixedPublicLoader(
|
|
|
235
258
|
run: () => Promise<Record<string, unknown>>
|
|
236
259
|
): Promise<Record<string, unknown>> {
|
|
237
260
|
const instance = currentInstance();
|
|
261
|
+
const declaredTags = route.tags ?? [];
|
|
238
262
|
const mode = segment.mode ?? route.mode;
|
|
239
263
|
const revalidate = mode === "isr" ? (segment.revalidate ?? 60) : Number.POSITIVE_INFINITY;
|
|
240
264
|
const requestUrl = new URL(ctx.request.url);
|
|
@@ -256,7 +280,12 @@ export async function cacheMixedPublicLoader(
|
|
|
256
280
|
mode: mode === "isr" ? ("isr" as const) : ("ssg" as const),
|
|
257
281
|
path,
|
|
258
282
|
scope: instance.prefix,
|
|
259
|
-
tags:
|
|
283
|
+
tags: [
|
|
284
|
+
...new Set([
|
|
285
|
+
...declaredTags,
|
|
286
|
+
...getAutoInvalidateRegistry().tagsForPath(`${path}${requestUrl.search}`),
|
|
287
|
+
]),
|
|
288
|
+
],
|
|
260
289
|
};
|
|
261
290
|
const stored =
|
|
262
291
|
shared === undefined
|
|
@@ -283,7 +312,7 @@ export async function cacheMixedPublicLoader(
|
|
|
283
312
|
generation,
|
|
284
313
|
key,
|
|
285
314
|
`${path}${requestUrl.search}`,
|
|
286
|
-
|
|
315
|
+
[...declaredTags, ...capturedQueryTags()],
|
|
287
316
|
cached
|
|
288
317
|
);
|
|
289
318
|
if (shared !== undefined && lease !== null) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createElement } from "react";
|
|
2
|
-
import { renderToReadableStream } from "react-dom/server";
|
|
3
2
|
import { type DocumentAssets, FurinDocumentFallback } from "../../client/document.tsx";
|
|
4
3
|
import { normalizeHref, toLogical } from "../../client/router/link-utils.ts";
|
|
5
4
|
import type { RouterContextValue } from "../../client/router/types.ts";
|
|
@@ -15,6 +14,7 @@ import { useRequestCspNonce } from "../security/csp.ts";
|
|
|
15
14
|
import { streamToString } from "./assemble.ts";
|
|
16
15
|
import { withDocumentState } from "./document.tsx";
|
|
17
16
|
import { buildNotFoundElement, wrapRootLayout } from "./element.tsx";
|
|
17
|
+
import { renderToReadableStream } from "./react-stream.ts";
|
|
18
18
|
import { generateIndexHtml } from "./shell.ts";
|
|
19
19
|
import { withSSRRouterContext } from "./ssr.ts";
|
|
20
20
|
import {
|
|
@@ -97,17 +97,14 @@ export async function renderRootNotFound(
|
|
|
97
97
|
},
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
const
|
|
100
|
+
const rootData = { params: {}, path: logicalPath, query };
|
|
101
|
+
const data = { ...rootData, __furinStatus: 404 };
|
|
101
102
|
let reactStream: Awaited<ReturnType<typeof renderToReadableStream>>;
|
|
102
103
|
try {
|
|
103
104
|
reactStream = await renderToReadableStream(
|
|
104
105
|
withDocumentState(
|
|
105
106
|
withSSRRouterContext(
|
|
106
|
-
wrapRootLayout(
|
|
107
|
-
buildNotFoundElement(root.notFound, notFoundError),
|
|
108
|
-
{ params: {}, path: logicalPath, query },
|
|
109
|
-
root.route
|
|
110
|
-
),
|
|
107
|
+
wrapRootLayout(buildNotFoundElement(root.notFound, notFoundError), rootData, root.route),
|
|
111
108
|
notFoundContext
|
|
112
109
|
),
|
|
113
110
|
assets,
|
|
@@ -5,6 +5,7 @@ import { computeErrorDigest } from "../../shared/digest.ts";
|
|
|
5
5
|
import { physicalPath } from "../../shared/prefix.ts";
|
|
6
6
|
import { parseRouteFrameLines, serializeRouteFrames } from "../../shared/route-frame.ts";
|
|
7
7
|
import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
8
|
+
import { queryTagsFromData } from "../../shared/sync-query.ts";
|
|
8
9
|
import { getLogger } from "../context-logger.ts";
|
|
9
10
|
import { currentInstance } from "../instance.ts";
|
|
10
11
|
import type { ResolvedRoute, RootLayout } from "../router/types.ts";
|
|
@@ -186,7 +187,7 @@ export async function prerenderPprDocument(
|
|
|
186
187
|
prefix,
|
|
187
188
|
version: 1,
|
|
188
189
|
},
|
|
189
|
-
tags: route.tags,
|
|
190
|
+
tags: [...(route.tags ?? []), ...queryTagsFromData(result.syncData)],
|
|
190
191
|
};
|
|
191
192
|
}
|
|
192
193
|
|