vinext 0.0.0 → 0.0.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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/build/static-export.d.ts +78 -0
- package/dist/build/static-export.d.ts.map +1 -0
- package/dist/build/static-export.js +553 -0
- package/dist/build/static-export.js.map +1 -0
- package/dist/check.d.ts +52 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +483 -0
- package/dist/check.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +565 -0
- package/dist/cli.js.map +1 -0
- package/dist/client/entry.d.ts +2 -0
- package/dist/client/entry.d.ts.map +1 -0
- package/dist/client/entry.js +85 -0
- package/dist/client/entry.js.map +1 -0
- package/dist/cloudflare/index.d.ts +8 -0
- package/dist/cloudflare/index.d.ts.map +1 -0
- package/dist/cloudflare/index.js +8 -0
- package/dist/cloudflare/index.js.map +1 -0
- package/dist/cloudflare/kv-cache-handler.d.ts +68 -0
- package/dist/cloudflare/kv-cache-handler.d.ts.map +1 -0
- package/dist/cloudflare/kv-cache-handler.js +304 -0
- package/dist/cloudflare/kv-cache-handler.js.map +1 -0
- package/dist/cloudflare/tpr.d.ts +78 -0
- package/dist/cloudflare/tpr.d.ts.map +1 -0
- package/dist/cloudflare/tpr.js +672 -0
- package/dist/cloudflare/tpr.js.map +1 -0
- package/dist/config/config-matchers.d.ts +106 -0
- package/dist/config/config-matchers.d.ts.map +1 -0
- package/dist/config/config-matchers.js +499 -0
- package/dist/config/config-matchers.js.map +1 -0
- package/dist/config/next-config.d.ts +153 -0
- package/dist/config/next-config.d.ts.map +1 -0
- package/dist/config/next-config.js +274 -0
- package/dist/config/next-config.js.map +1 -0
- package/dist/deploy.d.ts +87 -0
- package/dist/deploy.d.ts.map +1 -0
- package/dist/deploy.js +644 -0
- package/dist/deploy.js.map +1 -0
- package/dist/index.d.ts +156 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3287 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +55 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +201 -0
- package/dist/init.js.map +1 -0
- package/dist/routing/app-router.d.ts +96 -0
- package/dist/routing/app-router.d.ts.map +1 -0
- package/dist/routing/app-router.js +815 -0
- package/dist/routing/app-router.js.map +1 -0
- package/dist/routing/pages-router.d.ts +52 -0
- package/dist/routing/pages-router.d.ts.map +1 -0
- package/dist/routing/pages-router.js +239 -0
- package/dist/routing/pages-router.js.map +1 -0
- package/dist/server/api-handler.d.ts +18 -0
- package/dist/server/api-handler.d.ts.map +1 -0
- package/dist/server/api-handler.js +169 -0
- package/dist/server/api-handler.js.map +1 -0
- package/dist/server/app-dev-server.d.ts +42 -0
- package/dist/server/app-dev-server.d.ts.map +1 -0
- package/dist/server/app-dev-server.js +2718 -0
- package/dist/server/app-dev-server.js.map +1 -0
- package/dist/server/app-router-entry.d.ts +18 -0
- package/dist/server/app-router-entry.d.ts.map +1 -0
- package/dist/server/app-router-entry.js +34 -0
- package/dist/server/app-router-entry.js.map +1 -0
- package/dist/server/dev-server.d.ts +40 -0
- package/dist/server/dev-server.d.ts.map +1 -0
- package/dist/server/dev-server.js +758 -0
- package/dist/server/dev-server.js.map +1 -0
- package/dist/server/html.d.ts +22 -0
- package/dist/server/html.d.ts.map +1 -0
- package/dist/server/html.js +29 -0
- package/dist/server/html.js.map +1 -0
- package/dist/server/image-optimization.d.ts +56 -0
- package/dist/server/image-optimization.d.ts.map +1 -0
- package/dist/server/image-optimization.js +103 -0
- package/dist/server/image-optimization.js.map +1 -0
- package/dist/server/instrumentation.d.ts +68 -0
- package/dist/server/instrumentation.d.ts.map +1 -0
- package/dist/server/instrumentation.js +90 -0
- package/dist/server/instrumentation.js.map +1 -0
- package/dist/server/isr-cache.d.ts +61 -0
- package/dist/server/isr-cache.d.ts.map +1 -0
- package/dist/server/isr-cache.js +134 -0
- package/dist/server/isr-cache.js.map +1 -0
- package/dist/server/metadata-routes.d.ts +103 -0
- package/dist/server/metadata-routes.d.ts.map +1 -0
- package/dist/server/metadata-routes.js +270 -0
- package/dist/server/metadata-routes.js.map +1 -0
- package/dist/server/middleware.d.ts +77 -0
- package/dist/server/middleware.d.ts.map +1 -0
- package/dist/server/middleware.js +228 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/prod-server.d.ts +78 -0
- package/dist/server/prod-server.d.ts.map +1 -0
- package/dist/server/prod-server.js +712 -0
- package/dist/server/prod-server.js.map +1 -0
- package/dist/shims/amp.d.ts +17 -0
- package/dist/shims/amp.d.ts.map +1 -0
- package/dist/shims/amp.js +21 -0
- package/dist/shims/amp.js.map +1 -0
- package/dist/shims/app.d.ts +12 -0
- package/dist/shims/app.d.ts.map +1 -0
- package/dist/shims/app.js +2 -0
- package/dist/shims/app.js.map +1 -0
- package/dist/shims/cache-runtime.d.ts +68 -0
- package/dist/shims/cache-runtime.d.ts.map +1 -0
- package/dist/shims/cache-runtime.js +437 -0
- package/dist/shims/cache-runtime.js.map +1 -0
- package/dist/shims/cache.d.ts +243 -0
- package/dist/shims/cache.d.ts.map +1 -0
- package/dist/shims/cache.js +415 -0
- package/dist/shims/cache.js.map +1 -0
- package/dist/shims/client-only.d.ts +18 -0
- package/dist/shims/client-only.d.ts.map +1 -0
- package/dist/shims/client-only.js +18 -0
- package/dist/shims/client-only.js.map +1 -0
- package/dist/shims/config.d.ts +27 -0
- package/dist/shims/config.d.ts.map +1 -0
- package/dist/shims/config.js +30 -0
- package/dist/shims/config.js.map +1 -0
- package/dist/shims/constants.d.ts +13 -0
- package/dist/shims/constants.d.ts.map +1 -0
- package/dist/shims/constants.js +13 -0
- package/dist/shims/constants.js.map +1 -0
- package/dist/shims/document.d.ts +33 -0
- package/dist/shims/document.d.ts.map +1 -0
- package/dist/shims/document.js +32 -0
- package/dist/shims/document.js.map +1 -0
- package/dist/shims/dynamic.d.ts +33 -0
- package/dist/shims/dynamic.d.ts.map +1 -0
- package/dist/shims/dynamic.js +148 -0
- package/dist/shims/dynamic.js.map +1 -0
- package/dist/shims/error-boundary.d.ts +33 -0
- package/dist/shims/error-boundary.d.ts.map +1 -0
- package/dist/shims/error-boundary.js +88 -0
- package/dist/shims/error-boundary.js.map +1 -0
- package/dist/shims/error.d.ts +16 -0
- package/dist/shims/error.d.ts.map +1 -0
- package/dist/shims/error.js +45 -0
- package/dist/shims/error.js.map +1 -0
- package/dist/shims/fetch-cache.d.ts +61 -0
- package/dist/shims/fetch-cache.d.ts.map +1 -0
- package/dist/shims/fetch-cache.js +307 -0
- package/dist/shims/fetch-cache.js.map +1 -0
- package/dist/shims/font-google.d.ts +122 -0
- package/dist/shims/font-google.d.ts.map +1 -0
- package/dist/shims/font-google.js +387 -0
- package/dist/shims/font-google.js.map +1 -0
- package/dist/shims/font-local.d.ts +61 -0
- package/dist/shims/font-local.d.ts.map +1 -0
- package/dist/shims/font-local.js +303 -0
- package/dist/shims/font-local.js.map +1 -0
- package/dist/shims/form.d.ts +30 -0
- package/dist/shims/form.d.ts.map +1 -0
- package/dist/shims/form.js +78 -0
- package/dist/shims/form.js.map +1 -0
- package/dist/shims/head-state.d.ts +11 -0
- package/dist/shims/head-state.d.ts.map +1 -0
- package/dist/shims/head-state.js +47 -0
- package/dist/shims/head-state.js.map +1 -0
- package/dist/shims/head.d.ts +28 -0
- package/dist/shims/head.d.ts.map +1 -0
- package/dist/shims/head.js +148 -0
- package/dist/shims/head.js.map +1 -0
- package/dist/shims/headers.d.ts +150 -0
- package/dist/shims/headers.d.ts.map +1 -0
- package/dist/shims/headers.js +412 -0
- package/dist/shims/headers.js.map +1 -0
- package/dist/shims/image-config.d.ts +30 -0
- package/dist/shims/image-config.d.ts.map +1 -0
- package/dist/shims/image-config.js +91 -0
- package/dist/shims/image-config.js.map +1 -0
- package/dist/shims/image.d.ts +63 -0
- package/dist/shims/image.d.ts.map +1 -0
- package/dist/shims/image.js +284 -0
- package/dist/shims/image.js.map +1 -0
- package/dist/shims/internal/api-utils.d.ts +12 -0
- package/dist/shims/internal/api-utils.d.ts.map +1 -0
- package/dist/shims/internal/api-utils.js +7 -0
- package/dist/shims/internal/api-utils.js.map +1 -0
- package/dist/shims/internal/app-router-context.d.ts +21 -0
- package/dist/shims/internal/app-router-context.d.ts.map +1 -0
- package/dist/shims/internal/app-router-context.js +15 -0
- package/dist/shims/internal/app-router-context.js.map +1 -0
- package/dist/shims/internal/cookies.d.ts +9 -0
- package/dist/shims/internal/cookies.d.ts.map +1 -0
- package/dist/shims/internal/cookies.js +9 -0
- package/dist/shims/internal/cookies.js.map +1 -0
- package/dist/shims/internal/router-context.d.ts +2 -0
- package/dist/shims/internal/router-context.d.ts.map +1 -0
- package/dist/shims/internal/router-context.js +9 -0
- package/dist/shims/internal/router-context.js.map +1 -0
- package/dist/shims/internal/utils.d.ts +48 -0
- package/dist/shims/internal/utils.d.ts.map +1 -0
- package/dist/shims/internal/utils.js +35 -0
- package/dist/shims/internal/utils.js.map +1 -0
- package/dist/shims/internal/work-unit-async-storage.d.ts +12 -0
- package/dist/shims/internal/work-unit-async-storage.d.ts.map +1 -0
- package/dist/shims/internal/work-unit-async-storage.js +13 -0
- package/dist/shims/internal/work-unit-async-storage.js.map +1 -0
- package/dist/shims/layout-segment-context.d.ts +21 -0
- package/dist/shims/layout-segment-context.d.ts.map +1 -0
- package/dist/shims/layout-segment-context.js +27 -0
- package/dist/shims/layout-segment-context.js.map +1 -0
- package/dist/shims/legacy-image.d.ts +52 -0
- package/dist/shims/legacy-image.d.ts.map +1 -0
- package/dist/shims/legacy-image.js +46 -0
- package/dist/shims/legacy-image.js.map +1 -0
- package/dist/shims/link.d.ts +48 -0
- package/dist/shims/link.d.ts.map +1 -0
- package/dist/shims/link.js +395 -0
- package/dist/shims/link.js.map +1 -0
- package/dist/shims/metadata.d.ts +184 -0
- package/dist/shims/metadata.d.ts.map +1 -0
- package/dist/shims/metadata.js +472 -0
- package/dist/shims/metadata.js.map +1 -0
- package/dist/shims/navigation-state.d.ts +14 -0
- package/dist/shims/navigation-state.d.ts.map +1 -0
- package/dist/shims/navigation-state.js +77 -0
- package/dist/shims/navigation-state.js.map +1 -0
- package/dist/shims/navigation.d.ts +201 -0
- package/dist/shims/navigation.d.ts.map +1 -0
- package/dist/shims/navigation.js +672 -0
- package/dist/shims/navigation.js.map +1 -0
- package/dist/shims/og.d.ts +20 -0
- package/dist/shims/og.d.ts.map +1 -0
- package/dist/shims/og.js +19 -0
- package/dist/shims/og.js.map +1 -0
- package/dist/shims/router-state.d.ts +11 -0
- package/dist/shims/router-state.d.ts.map +1 -0
- package/dist/shims/router-state.js +56 -0
- package/dist/shims/router-state.js.map +1 -0
- package/dist/shims/router.d.ts +103 -0
- package/dist/shims/router.d.ts.map +1 -0
- package/dist/shims/router.js +536 -0
- package/dist/shims/router.js.map +1 -0
- package/dist/shims/script.d.ts +58 -0
- package/dist/shims/script.d.ts.map +1 -0
- package/dist/shims/script.js +163 -0
- package/dist/shims/script.js.map +1 -0
- package/dist/shims/server-only.d.ts +19 -0
- package/dist/shims/server-only.d.ts.map +1 -0
- package/dist/shims/server-only.js +19 -0
- package/dist/shims/server-only.js.map +1 -0
- package/dist/shims/server.d.ts +178 -0
- package/dist/shims/server.d.ts.map +1 -0
- package/dist/shims/server.js +377 -0
- package/dist/shims/server.js.map +1 -0
- package/dist/shims/web-vitals.d.ts +24 -0
- package/dist/shims/web-vitals.d.ts.map +1 -0
- package/dist/shims/web-vitals.js +17 -0
- package/dist/shims/web-vitals.js.map +1 -0
- package/dist/utils/hash.d.ts +6 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +20 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/project.d.ts +36 -0
- package/dist/utils/project.d.ts.map +1 -0
- package/dist/utils/project.js +112 -0
- package/dist/utils/project.js.map +1 -0
- package/dist/utils/query.d.ts +10 -0
- package/dist/utils/query.d.ts.map +1 -0
- package/dist/utils/query.js +27 -0
- package/dist/utils/query.js.map +1 -0
- package/package.json +65 -7
- package/index.js +0 -1
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extended fetch() with Next.js caching semantics.
|
|
3
|
+
*
|
|
4
|
+
* Patches `globalThis.fetch` during server rendering to support:
|
|
5
|
+
*
|
|
6
|
+
* fetch(url, { next: { revalidate: 60, tags: ['posts'] } })
|
|
7
|
+
* fetch(url, { cache: 'force-cache' })
|
|
8
|
+
* fetch(url, { cache: 'no-store' })
|
|
9
|
+
*
|
|
10
|
+
* Cached responses are stored via the pluggable CacheHandler, so
|
|
11
|
+
* revalidateTag() and revalidatePath() invalidate fetch-level caches.
|
|
12
|
+
*
|
|
13
|
+
* Usage (in server entry):
|
|
14
|
+
* import { withFetchCache, cleanupFetchCache } from './fetch-cache';
|
|
15
|
+
* const cleanup = withFetchCache();
|
|
16
|
+
* try { ... render ... } finally { cleanup(); }
|
|
17
|
+
*
|
|
18
|
+
* Or use the async helper:
|
|
19
|
+
* await runWithFetchCache(async () => { ... render ... });
|
|
20
|
+
*/
|
|
21
|
+
import { getCacheHandler, } from "./cache.js";
|
|
22
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Cache key generation
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
/**
|
|
27
|
+
* Generate a deterministic cache key from a fetch request.
|
|
28
|
+
*
|
|
29
|
+
* Key = "fetch:" + URL + "|" + sorted relevant options.
|
|
30
|
+
* We exclude headers that are request-specific (cookie, authorization)
|
|
31
|
+
* unless the user explicitly opts in via `next.tags`.
|
|
32
|
+
*/
|
|
33
|
+
function buildFetchCacheKey(input, init) {
|
|
34
|
+
let url;
|
|
35
|
+
let method = "GET";
|
|
36
|
+
let body;
|
|
37
|
+
if (typeof input === "string") {
|
|
38
|
+
url = input;
|
|
39
|
+
}
|
|
40
|
+
else if (input instanceof URL) {
|
|
41
|
+
url = input.toString();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// Request object
|
|
45
|
+
url = input.url;
|
|
46
|
+
method = input.method || "GET";
|
|
47
|
+
}
|
|
48
|
+
if (init?.method)
|
|
49
|
+
method = init.method;
|
|
50
|
+
if (init?.body && typeof init.body === "string")
|
|
51
|
+
body = init.body;
|
|
52
|
+
// Build a stable key from URL + method + body
|
|
53
|
+
const parts = [`fetch:${method}:${url}`];
|
|
54
|
+
if (body)
|
|
55
|
+
parts.push(body);
|
|
56
|
+
return parts.join("|");
|
|
57
|
+
}
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// Patching
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// Capture the real (unpatched) fetch once, shared across Vite's
|
|
62
|
+
// multi-environment module instances via Symbol.for().
|
|
63
|
+
const _ORIG_FETCH_KEY = Symbol.for("vinext.fetchCache.originalFetch");
|
|
64
|
+
const _gFetch = globalThis;
|
|
65
|
+
const originalFetch = (_gFetch[_ORIG_FETCH_KEY] ??= globalThis.fetch);
|
|
66
|
+
const _ALS_KEY = Symbol.for("vinext.fetchCache.als");
|
|
67
|
+
const _FALLBACK_KEY = Symbol.for("vinext.fetchCache.fallback");
|
|
68
|
+
const _g = globalThis;
|
|
69
|
+
const _als = (_g[_ALS_KEY] ??= new AsyncLocalStorage());
|
|
70
|
+
const _fallbackState = (_g[_FALLBACK_KEY] ??= {
|
|
71
|
+
currentRequestTags: [],
|
|
72
|
+
});
|
|
73
|
+
function _getState() {
|
|
74
|
+
return _als.getStore() ?? _fallbackState;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Reset the fallback state for a new request. Used by `withFetchCache()`
|
|
78
|
+
* in single-threaded contexts where ALS.run() isn't used.
|
|
79
|
+
*/
|
|
80
|
+
function _resetFallbackState() {
|
|
81
|
+
_fallbackState.currentRequestTags = [];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get tags collected during the current render pass.
|
|
85
|
+
* Useful for associating page-level cache entries with all the
|
|
86
|
+
* fetch tags used during rendering.
|
|
87
|
+
*/
|
|
88
|
+
export function getCollectedFetchTags() {
|
|
89
|
+
return [..._getState().currentRequestTags];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Create a patched fetch function with Next.js caching semantics.
|
|
93
|
+
*
|
|
94
|
+
* The patched fetch:
|
|
95
|
+
* 1. Checks `cache` and `next` options to determine caching behavior
|
|
96
|
+
* 2. On cache hit, returns the cached response without hitting the network
|
|
97
|
+
* 3. On cache miss, fetches from network, stores in cache, returns response
|
|
98
|
+
* 4. Respects `next.revalidate` for TTL-based revalidation
|
|
99
|
+
* 5. Respects `next.tags` for tag-based invalidation via revalidateTag()
|
|
100
|
+
*/
|
|
101
|
+
function createPatchedFetch() {
|
|
102
|
+
return async function patchedFetch(input, init) {
|
|
103
|
+
const nextOpts = init?.next;
|
|
104
|
+
const cacheDirective = init?.cache;
|
|
105
|
+
// Determine caching behavior:
|
|
106
|
+
// - cache: 'no-store' → skip cache entirely
|
|
107
|
+
// - cache: 'force-cache' → cache indefinitely (revalidate = Infinity)
|
|
108
|
+
// - next.revalidate: false → same as 'no-store'
|
|
109
|
+
// - next.revalidate: 0 → same as 'no-store'
|
|
110
|
+
// - next.revalidate: N → cache for N seconds
|
|
111
|
+
// - No cache/next options → default behavior (no caching, pass-through)
|
|
112
|
+
// If no caching options at all, just pass through to original fetch
|
|
113
|
+
if (!nextOpts && !cacheDirective) {
|
|
114
|
+
return originalFetch(input, init);
|
|
115
|
+
}
|
|
116
|
+
// Explicit no-store
|
|
117
|
+
if (cacheDirective === "no-store" || nextOpts?.revalidate === false || nextOpts?.revalidate === 0) {
|
|
118
|
+
// Strip the `next` property before passing to real fetch
|
|
119
|
+
const cleanInit = stripNextFromInit(init);
|
|
120
|
+
return originalFetch(input, cleanInit);
|
|
121
|
+
}
|
|
122
|
+
// Determine revalidation period
|
|
123
|
+
let revalidateSeconds;
|
|
124
|
+
if (cacheDirective === "force-cache") {
|
|
125
|
+
// force-cache means cache indefinitely (we use a very large number)
|
|
126
|
+
revalidateSeconds = nextOpts?.revalidate && typeof nextOpts.revalidate === "number"
|
|
127
|
+
? nextOpts.revalidate
|
|
128
|
+
: 31536000; // 1 year
|
|
129
|
+
}
|
|
130
|
+
else if (typeof nextOpts?.revalidate === "number" && nextOpts.revalidate > 0) {
|
|
131
|
+
revalidateSeconds = nextOpts.revalidate;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// Has `next` options but no explicit revalidate — Next.js defaults to
|
|
135
|
+
// caching when `next` is present (force-cache behavior).
|
|
136
|
+
// If only tags are specified, cache indefinitely.
|
|
137
|
+
if (nextOpts?.tags && nextOpts.tags.length > 0) {
|
|
138
|
+
revalidateSeconds = 31536000;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
// next: {} with no revalidate or tags — pass through
|
|
142
|
+
const cleanInit = stripNextFromInit(init);
|
|
143
|
+
return originalFetch(input, cleanInit);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const tags = nextOpts?.tags ?? [];
|
|
147
|
+
const cacheKey = buildFetchCacheKey(input, init);
|
|
148
|
+
const handler = getCacheHandler();
|
|
149
|
+
// Collect tags for this render pass
|
|
150
|
+
const reqTags = _getState().currentRequestTags;
|
|
151
|
+
if (tags.length > 0) {
|
|
152
|
+
for (const tag of tags) {
|
|
153
|
+
if (!reqTags.includes(tag)) {
|
|
154
|
+
reqTags.push(tag);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Try cache first
|
|
159
|
+
try {
|
|
160
|
+
const cached = await handler.get(cacheKey, { kind: "FETCH", tags });
|
|
161
|
+
if (cached?.value && cached.value.kind === "FETCH" && cached.cacheState !== "stale") {
|
|
162
|
+
const cachedData = cached.value.data;
|
|
163
|
+
// Reconstruct a Response from the cached data
|
|
164
|
+
return new Response(cachedData.body, {
|
|
165
|
+
status: cachedData.status ?? 200,
|
|
166
|
+
headers: cachedData.headers,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
// Stale entry — we could do stale-while-revalidate here, but for fetch()
|
|
170
|
+
// the simpler approach is to just re-fetch (the page-level ISR handles SWR).
|
|
171
|
+
// However, if we have a stale entry, return it and trigger background refetch.
|
|
172
|
+
if (cached?.value && cached.value.kind === "FETCH" && cached.cacheState === "stale") {
|
|
173
|
+
const staleData = cached.value.data;
|
|
174
|
+
// Background refetch
|
|
175
|
+
const cleanInit = stripNextFromInit(init);
|
|
176
|
+
originalFetch(input, cleanInit).then(async (freshResp) => {
|
|
177
|
+
const freshBody = await freshResp.text();
|
|
178
|
+
const freshHeaders = {};
|
|
179
|
+
freshResp.headers.forEach((v, k) => { freshHeaders[k] = v; });
|
|
180
|
+
const freshValue = {
|
|
181
|
+
kind: "FETCH",
|
|
182
|
+
data: {
|
|
183
|
+
headers: freshHeaders,
|
|
184
|
+
body: freshBody,
|
|
185
|
+
url: typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url,
|
|
186
|
+
status: freshResp.status,
|
|
187
|
+
},
|
|
188
|
+
tags,
|
|
189
|
+
revalidate: revalidateSeconds,
|
|
190
|
+
};
|
|
191
|
+
await handler.set(cacheKey, freshValue, {
|
|
192
|
+
fetchCache: true,
|
|
193
|
+
tags,
|
|
194
|
+
revalidate: revalidateSeconds,
|
|
195
|
+
});
|
|
196
|
+
}).catch((err) => {
|
|
197
|
+
console.error("[vinext] fetch cache background revalidation failed:", err);
|
|
198
|
+
});
|
|
199
|
+
// Return stale data immediately
|
|
200
|
+
return new Response(staleData.body, {
|
|
201
|
+
status: staleData.status ?? 200,
|
|
202
|
+
headers: staleData.headers,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (cacheErr) {
|
|
207
|
+
// Cache read failed — fall through to network
|
|
208
|
+
console.error("[vinext] fetch cache read error:", cacheErr);
|
|
209
|
+
}
|
|
210
|
+
// Cache miss — fetch from network
|
|
211
|
+
const cleanInit = stripNextFromInit(init);
|
|
212
|
+
const response = await originalFetch(input, cleanInit);
|
|
213
|
+
// Only cache successful responses (2xx)
|
|
214
|
+
if (response.ok) {
|
|
215
|
+
// Clone before reading body
|
|
216
|
+
const cloned = response.clone();
|
|
217
|
+
const body = await cloned.text();
|
|
218
|
+
const headers = {};
|
|
219
|
+
cloned.headers.forEach((v, k) => { headers[k] = v; });
|
|
220
|
+
const cacheValue = {
|
|
221
|
+
kind: "FETCH",
|
|
222
|
+
data: {
|
|
223
|
+
headers,
|
|
224
|
+
body,
|
|
225
|
+
url: typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url,
|
|
226
|
+
status: cloned.status,
|
|
227
|
+
},
|
|
228
|
+
tags,
|
|
229
|
+
revalidate: revalidateSeconds,
|
|
230
|
+
};
|
|
231
|
+
// Store in cache (fire-and-forget)
|
|
232
|
+
handler.set(cacheKey, cacheValue, {
|
|
233
|
+
fetchCache: true,
|
|
234
|
+
tags,
|
|
235
|
+
revalidate: revalidateSeconds,
|
|
236
|
+
}).catch((err) => {
|
|
237
|
+
console.error("[vinext] fetch cache write error:", err);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
return response;
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Strip the `next` property from RequestInit before passing to real fetch.
|
|
245
|
+
* The `next` property is not a standard fetch option and would cause warnings
|
|
246
|
+
* in some environments.
|
|
247
|
+
*/
|
|
248
|
+
function stripNextFromInit(init) {
|
|
249
|
+
if (!init)
|
|
250
|
+
return init;
|
|
251
|
+
if (!("next" in init))
|
|
252
|
+
return init;
|
|
253
|
+
const { next: _next, ...rest } = init;
|
|
254
|
+
return Object.keys(rest).length > 0 ? rest : undefined;
|
|
255
|
+
}
|
|
256
|
+
// ---------------------------------------------------------------------------
|
|
257
|
+
// Public API
|
|
258
|
+
// ---------------------------------------------------------------------------
|
|
259
|
+
// ---------------------------------------------------------------------------
|
|
260
|
+
// Fetch patching — install once, not per-request.
|
|
261
|
+
// The patched fetch uses _getState() internally, which reads from ALS
|
|
262
|
+
// (concurrent) or _fallbackState (single-threaded), so per-request
|
|
263
|
+
// isolation is handled at the state level, not by swapping globalThis.fetch.
|
|
264
|
+
// ---------------------------------------------------------------------------
|
|
265
|
+
const _PATCH_KEY = Symbol.for("vinext.fetchCache.patchInstalled");
|
|
266
|
+
function _ensurePatchInstalled() {
|
|
267
|
+
if (_g[_PATCH_KEY])
|
|
268
|
+
return;
|
|
269
|
+
_g[_PATCH_KEY] = true;
|
|
270
|
+
globalThis.fetch = createPatchedFetch();
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Install the patched fetch and reset per-request tag state.
|
|
274
|
+
* Returns a cleanup function that clears tags.
|
|
275
|
+
*
|
|
276
|
+
* In single-threaded contexts (dev server, tests) this is safe because
|
|
277
|
+
* requests are sequential. For concurrent environments, prefer
|
|
278
|
+
* `runWithFetchCache()` which uses `AsyncLocalStorage.run()`.
|
|
279
|
+
*
|
|
280
|
+
* Usage:
|
|
281
|
+
* const cleanup = withFetchCache();
|
|
282
|
+
* try { await render(); } finally { cleanup(); }
|
|
283
|
+
*/
|
|
284
|
+
export function withFetchCache() {
|
|
285
|
+
_ensurePatchInstalled();
|
|
286
|
+
_resetFallbackState();
|
|
287
|
+
return () => {
|
|
288
|
+
_resetFallbackState();
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Run an async function with patched fetch caching enabled.
|
|
293
|
+
* Uses `AsyncLocalStorage.run()` for proper per-request isolation
|
|
294
|
+
* of collected fetch tags in concurrent server environments.
|
|
295
|
+
*/
|
|
296
|
+
export async function runWithFetchCache(fn) {
|
|
297
|
+
_ensurePatchInstalled();
|
|
298
|
+
return _als.run({ currentRequestTags: [] }, fn);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Get the original (unpatched) fetch function.
|
|
302
|
+
* Useful for internal code that should bypass caching.
|
|
303
|
+
*/
|
|
304
|
+
export function getOriginalFetch() {
|
|
305
|
+
return originalFetch;
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=fetch-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-cache.js","sourceRoot":"","sources":["../../src/shims/fetch-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,eAAe,GAEhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,8EAA8E;AAC9E,uBAAuB;AACvB,8EAA8E;AAE9E;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,KAA6B,EAAE,IAAgD;IACzG,IAAI,GAAW,CAAC;IAChB,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,IAAwB,CAAC;IAE7B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,GAAG,GAAG,KAAK,CAAC;IACd,CAAC;SAAM,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;QAChC,GAAG,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,iBAAiB;QACjB,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;QAChB,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC;IACjC,CAAC;IAED,IAAI,IAAI,EAAE,MAAM;QAAE,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACvC,IAAI,IAAI,EAAE,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IAElE,8CAA8C;IAC9C,MAAM,KAAK,GAAG,CAAC,SAAS,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC;IACzC,IAAI,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE3B,OAAO,KAAK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AC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAI,EAAoB;IAC7D,qBAAqB,EAAE,CAAC;IACxB,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,kBAAkB,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAClD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* next/font/google shim
|
|
3
|
+
*
|
|
4
|
+
* Provides a compatible shim for Next.js Google Fonts.
|
|
5
|
+
*
|
|
6
|
+
* Two modes:
|
|
7
|
+
* 1. **Dev / CDN mode** (default): Loads fonts from Google Fonts CDN via <link> tags.
|
|
8
|
+
* 2. **Self-hosted mode** (production build): The vinext:google-fonts Vite plugin
|
|
9
|
+
* fetches font CSS + .woff2 files at build time, caches them locally, and injects
|
|
10
|
+
* @font-face CSS pointing at local assets. No requests to Google at runtime.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* import { Inter } from 'next/font/google';
|
|
14
|
+
* const inter = Inter({ subsets: ['latin'], weight: ['400', '700'] });
|
|
15
|
+
* // inter.className -> unique CSS class
|
|
16
|
+
* // inter.style -> { fontFamily: "'Inter', sans-serif" }
|
|
17
|
+
* // inter.variable -> CSS variable name like '--font-inter'
|
|
18
|
+
*/
|
|
19
|
+
interface FontOptions {
|
|
20
|
+
weight?: string | string[];
|
|
21
|
+
style?: string | string[];
|
|
22
|
+
subsets?: string[];
|
|
23
|
+
display?: string;
|
|
24
|
+
preload?: boolean;
|
|
25
|
+
fallback?: string[];
|
|
26
|
+
adjustFontFallback?: boolean | string;
|
|
27
|
+
variable?: string;
|
|
28
|
+
axes?: string[];
|
|
29
|
+
}
|
|
30
|
+
interface FontResult {
|
|
31
|
+
className: string;
|
|
32
|
+
style: {
|
|
33
|
+
fontFamily: string;
|
|
34
|
+
};
|
|
35
|
+
variable?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build a Google Fonts CSS URL.
|
|
39
|
+
*/
|
|
40
|
+
declare function buildGoogleFontsUrl(family: string, options: FontOptions): string;
|
|
41
|
+
/**
|
|
42
|
+
* Get collected SSR font class styles (used by the renderer).
|
|
43
|
+
* Note: We don't clear the arrays because fonts are loaded at module import
|
|
44
|
+
* time and need to persist across all requests in the Workers environment.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getSSRFontStyles(): string[];
|
|
47
|
+
/**
|
|
48
|
+
* Get collected SSR font URLs (used by the renderer).
|
|
49
|
+
* Note: We don't clear the arrays because fonts are loaded at module import
|
|
50
|
+
* time and need to persist across all requests in the Workers environment.
|
|
51
|
+
*/
|
|
52
|
+
export declare function getSSRFontLinks(): string[];
|
|
53
|
+
/**
|
|
54
|
+
* Get collected SSR font preload data (used by the renderer).
|
|
55
|
+
* Returns an array of { href, type } objects for emitting
|
|
56
|
+
* <link rel="preload" as="font" ...> tags.
|
|
57
|
+
*/
|
|
58
|
+
export declare function getSSRFontPreloads(): Array<{
|
|
59
|
+
href: string;
|
|
60
|
+
type: string;
|
|
61
|
+
}>;
|
|
62
|
+
export { buildGoogleFontsUrl };
|
|
63
|
+
declare const googleFonts: Record<string, (options?: FontOptions) => FontResult>;
|
|
64
|
+
export default googleFonts;
|
|
65
|
+
export declare const Inter: (options?: FontOptions & {
|
|
66
|
+
_selfHostedCSS?: string;
|
|
67
|
+
}) => FontResult;
|
|
68
|
+
export declare const Roboto: (options?: FontOptions & {
|
|
69
|
+
_selfHostedCSS?: string;
|
|
70
|
+
}) => FontResult;
|
|
71
|
+
export declare const Roboto_Mono: (options?: FontOptions & {
|
|
72
|
+
_selfHostedCSS?: string;
|
|
73
|
+
}) => FontResult;
|
|
74
|
+
export declare const Open_Sans: (options?: FontOptions & {
|
|
75
|
+
_selfHostedCSS?: string;
|
|
76
|
+
}) => FontResult;
|
|
77
|
+
export declare const Lato: (options?: FontOptions & {
|
|
78
|
+
_selfHostedCSS?: string;
|
|
79
|
+
}) => FontResult;
|
|
80
|
+
export declare const Poppins: (options?: FontOptions & {
|
|
81
|
+
_selfHostedCSS?: string;
|
|
82
|
+
}) => FontResult;
|
|
83
|
+
export declare const Montserrat: (options?: FontOptions & {
|
|
84
|
+
_selfHostedCSS?: string;
|
|
85
|
+
}) => FontResult;
|
|
86
|
+
export declare const Source_Code_Pro: (options?: FontOptions & {
|
|
87
|
+
_selfHostedCSS?: string;
|
|
88
|
+
}) => FontResult;
|
|
89
|
+
export declare const Noto_Sans: (options?: FontOptions & {
|
|
90
|
+
_selfHostedCSS?: string;
|
|
91
|
+
}) => FontResult;
|
|
92
|
+
export declare const Raleway: (options?: FontOptions & {
|
|
93
|
+
_selfHostedCSS?: string;
|
|
94
|
+
}) => FontResult;
|
|
95
|
+
export declare const Ubuntu: (options?: FontOptions & {
|
|
96
|
+
_selfHostedCSS?: string;
|
|
97
|
+
}) => FontResult;
|
|
98
|
+
export declare const Nunito: (options?: FontOptions & {
|
|
99
|
+
_selfHostedCSS?: string;
|
|
100
|
+
}) => FontResult;
|
|
101
|
+
export declare const Playfair_Display: (options?: FontOptions & {
|
|
102
|
+
_selfHostedCSS?: string;
|
|
103
|
+
}) => FontResult;
|
|
104
|
+
export declare const Merriweather: (options?: FontOptions & {
|
|
105
|
+
_selfHostedCSS?: string;
|
|
106
|
+
}) => FontResult;
|
|
107
|
+
export declare const PT_Sans: (options?: FontOptions & {
|
|
108
|
+
_selfHostedCSS?: string;
|
|
109
|
+
}) => FontResult;
|
|
110
|
+
export declare const Fira_Code: (options?: FontOptions & {
|
|
111
|
+
_selfHostedCSS?: string;
|
|
112
|
+
}) => FontResult;
|
|
113
|
+
export declare const JetBrains_Mono: (options?: FontOptions & {
|
|
114
|
+
_selfHostedCSS?: string;
|
|
115
|
+
}) => FontResult;
|
|
116
|
+
export declare const Geist: (options?: FontOptions & {
|
|
117
|
+
_selfHostedCSS?: string;
|
|
118
|
+
}) => FontResult;
|
|
119
|
+
export declare const Geist_Mono: (options?: FontOptions & {
|
|
120
|
+
_selfHostedCSS?: string;
|
|
121
|
+
}) => FontResult;
|
|
122
|
+
//# sourceMappingURL=font-google.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"font-google.d.ts","sourceRoot":"","sources":["../../src/shims/font-google.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAwDH,UAAU,WAAW;IACnB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,UAAU,UAAU;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAUD;;GAEG;AACH,iBAAS,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CA8CzE;AAyGD;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAE3C;AAKD;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,MAAM,EAAE,CAE1C;AAMD;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CA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