dinou 9.3.0 → 10.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/CHANGELOG.md +196 -0
- package/README.md +157 -132
- package/dinou/adapters/bun.js +34 -5
- package/dinou/adapters/cloudflare.js +110 -17
- package/dinou/adapters/deno.js +46 -8
- package/dinou/adapters/netlify.js +86 -50
- package/dinou/adapters/node.js +8 -0
- package/dinou/assets.d.ts +32 -5
- package/dinou/bun/build.js +190 -106
- package/dinou/cli.js +992 -532
- package/dinou/cloudflare/build.js +187 -106
- package/dinou/compiled/autoprefixer/index.js +509 -517
- package/dinou/compiled/babel-core/index.js +738 -716
- package/dinou/compiled/babel-generator/index.js +341 -299
- package/dinou/compiled/babel-loader/index.js +766 -744
- package/dinou/compiled/babel-parser/index.js +2 -2
- package/dinou/compiled/babel-plugin-react-compiler/index.js +178 -178
- package/dinou/compiled/babel-plugin-syntax-import-meta/index.js +4 -4
- package/dinou/compiled/babel-preset-react/index.js +752 -730
- package/dinou/compiled/babel-preset-typescript/index.js +738 -716
- package/dinou/compiled/babel-traverse/index.js +463 -433
- package/dinou/compiled/babel-types/index.js +176 -176
- package/dinou/compiled/chokidar/index.js +4 -4
- package/dinou/compiled/commander/index.js +15 -15
- package/dinou/compiled/copy-webpack-plugin/index.js +433 -425
- package/dinou/compiled/css-loader/index.js +289 -289
- package/dinou/compiled/css-loader/runtime/api.js +85 -0
- package/dinou/compiled/css-loader/runtime/getUrl.js +26 -0
- package/dinou/compiled/css-loader/runtime/noSourceMaps.js +5 -0
- package/dinou/compiled/css-loader/runtime/package.json +3 -0
- package/dinou/compiled/css-loader/runtime/sourceMaps.js +16 -0
- package/dinou/compiled/fast-glob/index.js +5810 -0
- package/dinou/compiled/generic-names/index.js +16 -16
- package/dinou/compiled/mini-css-extract-plugin/{chunk-YYEJWYXE.js → chunk-R6DP5ZYM.js} +36 -36
- package/dinou/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +253 -0
- package/dinou/compiled/mini-css-extract-plugin/hmr/normalize-url.js +39 -0
- package/dinou/compiled/mini-css-extract-plugin/hmr/package.json +3 -0
- package/dinou/compiled/mini-css-extract-plugin/index.js +1 -1
- package/dinou/compiled/mini-css-extract-plugin/loader.js +5 -5
- package/dinou/compiled/postcss/index.js +83 -83
- package/dinou/compiled/postcss-import/index.js +147 -117
- package/dinou/compiled/postcss-modules/index.js +216 -216
- package/dinou/compiled/resolve/index.js +1224 -0
- package/dinou/compiled/rollup-plugin-babel/index.js +753 -731
- package/dinou/compiled/rollup-plugin-commonjs/index.js +43 -38
- package/dinou/compiled/rollup-plugin-delete/index.js +615 -253
- package/dinou/compiled/rollup-plugin-json/index.js +22 -18
- package/dinou/compiled/rollup-plugin-node-resolve/index.js +130 -100
- package/dinou/compiled/rollup-plugin-postcss/index.js +3299 -3277
- package/dinou/compiled/rollup-plugin-replace/index.js +34 -29
- package/dinou/compiled/tailwindcss-postcss/index.js +214 -211
- package/dinou/compiled/vendors-manifest.json +59 -83
- package/dinou/core/asset-extensions.js +482 -33
- package/dinou/core/bailout-proxy.js +21 -2
- package/dinou/core/build-static-pages.js +523 -371
- package/dinou/core/builtin-asset-extensions.js +63 -0
- package/dinou/core/cache-revalidate.js +449 -256
- package/dinou/core/cache-slot.js +289 -79
- package/dinou/core/client-webpack.jsx +470 -39
- package/dinou/core/client.jsx +402 -39
- package/dinou/core/config.js +3 -0
- package/dinou/core/copy-static-dirs.js +98 -0
- package/dinou/core/createScopedName.js +22 -4
- package/dinou/core/dinou-paths.js +1 -1
- package/dinou/core/discover-layouts.js +200 -0
- package/dinou/core/edge-ssr.js +1 -1
- package/dinou/core/ensure-vendor-mode.js +78 -19
- package/dinou/core/env.js +544 -0
- package/dinou/core/export-static.js +41 -9
- package/dinou/core/generate-route-types.js +989 -95
- package/dinou/core/generate-static-rsc.js +5 -6
- package/dinou/core/generate-static.js +45 -6
- package/dinou/core/get-abs-path-with-ext.js +217 -75
- package/dinou/core/get-asset-from-manifest.js +19 -8
- package/dinou/core/get-error-jsx.js +4 -5
- package/dinou/core/get-file-path-and-dynamic-params.js +561 -338
- package/dinou/core/get-jsx.js +220 -53
- package/dinou/core/handler.js +1647 -466
- package/dinou/core/import-module.js +7 -0
- package/dinou/core/layout-functions.js +72 -13
- package/dinou/core/link.jsx +34 -6
- package/dinou/core/load-dinou-config.js +520 -89
- package/dinou/core/manifest-provider.js +4 -14
- package/dinou/core/navigation-utils.js +141 -3
- package/dinou/core/navigation.js +134 -50
- package/dinou/core/node-middleware-runner.js +165 -0
- package/dinou/core/postcss-pipeline.js +236 -0
- package/dinou/core/ppr-context.js +114 -22
- package/dinou/core/ppr-runtime.js +391 -127
- package/dinou/core/redirect.jsx +1 -1
- package/dinou/core/render-jsx-to-client-jsx.js +216 -48
- package/dinou/core/request-context.js +59 -3
- package/dinou/core/resolve-contextual-dinou.js +523 -0
- package/dinou/core/resolve-setup-files.js +85 -27
- package/dinou/core/revalidating.js +10 -2
- package/dinou/core/route-generator.js +6 -2
- package/dinou/core/rsc-renderer.js +4 -1
- package/dinou/core/run-ssg.js +6 -0
- package/dinou/core/runtime-env.js +265 -0
- package/dinou/core/server-css-modules-plugin.js +155 -0
- package/dinou/core/server-function-proxy-webpack.js +27 -2
- package/dinou/core/server-function-proxy.js +27 -2
- package/dinou/core/slot.js +47 -2
- package/dinou/core/static-assets.js +503 -0
- package/dinou/core/storage-adapter.js +452 -24
- package/dinou/core/transform-server-functions.js +272 -24
- package/dinou/core/tsconfig-aliases.js +964 -0
- package/dinou/core/uneject.js +640 -0
- package/dinou/core/url-resolver.js +1 -1
- package/dinou/core/vfs.js +11 -2
- package/dinou/css.d.ts +4 -1
- package/dinou/deno/build.js +205 -153
- package/dinou/deno/seed-kv.js +4 -0
- package/dinou/env.d.ts +22 -2
- package/dinou/esbuild/build.js +40 -50
- package/dinou/esbuild/dev.js +33 -7
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.js +41 -16
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild.js +51 -49
- package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.js +73 -60
- package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +35 -16
- package/dinou/esbuild/helpers-esbuild/write.js +13 -3
- package/dinou/esbuild/plugins-esbuild/assets-plugin.js +100 -238
- package/dinou/esbuild/plugins-esbuild/babel-react-compiler-plugin.js +73 -29
- package/dinou/esbuild/plugins-esbuild/css-processor-plugin.js +283 -91
- package/dinou/esbuild/plugins-esbuild/manifest-generator-plugin.js +3 -5
- package/dinou/esbuild/plugins-esbuild/react-client-manifest-plugin.js +9 -3
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +4 -3
- package/dinou/esbuild/plugins-esbuild/stable-chunk-names-and-maps-plugin.js +10 -1
- package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +84 -21
- package/dinou/esbuild/react-refresh/esm-hmr/client.js +31 -10
- package/dinou/esbuild/react-refresh/esm-hmr-plugin.js +48 -18
- package/dinou/esbuild/react-refresh/is-react-refresh-boundary.js +9 -1
- package/dinou/esbuild/react-refresh/react-refresh-runtime.js +13 -7
- package/dinou/index.d.ts +1028 -88
- package/dinou/node/build.js +138 -74
- package/dinou/node/bundle-dual-engine.js +393 -131
- package/dinou/node/dev.js +1005 -275
- package/dinou/package.json +11 -34
- package/dinou/rollup/postcss.config.js +3 -4
- package/dinou/rollup/react-refresh/esm-hmr/client.js +31 -10
- package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +16 -13
- package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +53 -7
- package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +58 -20
- package/dinou/rollup/rollup-plugins/manifest-generator-plugin.js +16 -7
- package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +118 -42
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +48 -36
- package/dinou/rollup/rollup.config.js +174 -101
- package/dinou/scripts/build-vendors.js +123 -33
- package/dinou/server.d.ts +126 -15
- package/dinou/webpack/helpers/get-webpack-entries.js +87 -41
- package/dinou/webpack/helpers/patch-webpack-internals.js +93 -1
- package/dinou/webpack/loaders/server-functions-loader.js +1 -1
- package/dinou/webpack/plugins/manifest-generator-plugin.js +27 -7
- package/dinou/webpack/plugins/server-functions-plugin.js +39 -12
- package/dinou/webpack/plugins/webpack-memory-plugin.js +25 -12
- package/dinou/webpack/postcss.config.js +3 -4
- package/dinou/webpack/webpack.config.js +408 -132
- package/eject.js +6 -224
- package/package.json +7 -9
- package/dinou/compiled/cross-env/index.js +0 -661
- package/dinou/compiled/dotenv/index.js +0 -375
- package/dinou/compiled/esbuild-copy-static-files/index.js +0 -63
- package/dinou/compiled/esbuild-tsconfig-paths/index.js +0 -1314
- package/dinou/compiled/rollup-plugin-copy/index.js +0 -12066
- package/dinou/compiled/rollup-plugin-tsconfig-paths/index.js +0 -569
- package/dinou/compiled/tsconfig-paths-webpack-plugin/index.js +0 -3956
package/dinou/core/cache-slot.js
CHANGED
|
@@ -5,10 +5,15 @@
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
7
7
|
import React from "react";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
getStorageAdapter,
|
|
10
|
+
FileSystemStorage,
|
|
11
|
+
readDist2Fallback,
|
|
12
|
+
} from "./storage-adapter.js";
|
|
9
13
|
import { asyncRenderJSXToClientJSX } from "./render-jsx-to-client-jsx.js";
|
|
10
14
|
import { DinouCacheSlotBoundary as RawDinouCacheSlotBoundary } from "./slot.js";
|
|
11
|
-
import { getContext } from "./request-context.js";
|
|
15
|
+
import { getContext, requestStorage } from "./request-context.js";
|
|
16
|
+
import { createBailoutProxy, unwrapBailoutProxy } from "./bailout-proxy.js";
|
|
12
17
|
import { getJSX } from "./get-jsx.js";
|
|
13
18
|
import {
|
|
14
19
|
isPprBuildActive,
|
|
@@ -25,9 +30,14 @@ import {
|
|
|
25
30
|
isSlotDiscoveryActive,
|
|
26
31
|
} from "./ppr-context.js";
|
|
27
32
|
import { createRequire } from "node:module";
|
|
33
|
+
import { fetchCloudflareDist2Asset } from "./static-assets.js";
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
let require = null;
|
|
36
|
+
let currentDir = ".";
|
|
37
|
+
try {
|
|
38
|
+
require = createRequire(import.meta.url);
|
|
39
|
+
currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
40
|
+
} catch (e) {}
|
|
31
41
|
|
|
32
42
|
const INFLIGHT_KEY = Symbol.for("dinou.slot.inflight.renders");
|
|
33
43
|
if (!globalThis[INFLIGHT_KEY]) {
|
|
@@ -76,6 +86,87 @@ if (!globalThis[PRE_EVAL_ROUTES_KEY] || !(globalThis[PRE_EVAL_ROUTES_KEY] instan
|
|
|
76
86
|
}
|
|
77
87
|
const preEvaluatingRoutes = globalThis[PRE_EVAL_ROUTES_KEY];
|
|
78
88
|
|
|
89
|
+
function normalizeSlotRouteKey(rawPath) {
|
|
90
|
+
if (typeof rawPath !== "string" || rawPath.trim() === "") return null;
|
|
91
|
+
const clean = rawPath.split("?")[0].split("#")[0].replace(/\\/g, "/");
|
|
92
|
+
if (
|
|
93
|
+
clean.includes("____rsc_") ||
|
|
94
|
+
clean.includes("____server_function____")
|
|
95
|
+
) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return clean.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function doesSlotEntryMatchRoute(entry, targetRouteKey) {
|
|
102
|
+
if (targetRouteKey === null || targetRouteKey === undefined) return true;
|
|
103
|
+
const keys = entry?.routeKeys;
|
|
104
|
+
if (!(keys instanceof Set) || keys.size === 0) return true;
|
|
105
|
+
if (targetRouteKey === "") return true;
|
|
106
|
+
for (const k of keys) {
|
|
107
|
+
if (
|
|
108
|
+
k === "" ||
|
|
109
|
+
k === targetRouteKey ||
|
|
110
|
+
targetRouteKey.startsWith(k + "/") ||
|
|
111
|
+
k.startsWith(targetRouteKey + "/")
|
|
112
|
+
) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function createDiscoveryContext(currentPath) {
|
|
120
|
+
const outerCtx = getContext();
|
|
121
|
+
const rawQuery = unwrapBailoutProxy(outerCtx?.req?.query);
|
|
122
|
+
const rawCookies = unwrapBailoutProxy(outerCtx?.req?.cookies);
|
|
123
|
+
const rawHeaders = unwrapBailoutProxy(outerCtx?.req?.headers);
|
|
124
|
+
const activeEnv =
|
|
125
|
+
outerCtx?.env ||
|
|
126
|
+
outerCtx?.platformContext?.env ||
|
|
127
|
+
outerCtx?.req?.env ||
|
|
128
|
+
(typeof globalThis !== "undefined" ? globalThis.__DINOU_ENV__ : undefined) ||
|
|
129
|
+
{};
|
|
130
|
+
let reqPath =
|
|
131
|
+
typeof currentPath === "string" && currentPath
|
|
132
|
+
? currentPath.split("?")[0]
|
|
133
|
+
: outerCtx?.req?.path || "/";
|
|
134
|
+
if (!reqPath.startsWith("/")) reqPath = "/" + reqPath;
|
|
135
|
+
return {
|
|
136
|
+
req: {
|
|
137
|
+
query: createBailoutProxy(
|
|
138
|
+
rawQuery && typeof rawQuery === "object" ? { ...rawQuery } : {},
|
|
139
|
+
"req.query"
|
|
140
|
+
),
|
|
141
|
+
cookies: createBailoutProxy(
|
|
142
|
+
rawCookies && typeof rawCookies === "object" ? { ...rawCookies } : {},
|
|
143
|
+
"req.cookies"
|
|
144
|
+
),
|
|
145
|
+
headers: createBailoutProxy(
|
|
146
|
+
rawHeaders && typeof rawHeaders === "object" ? { ...rawHeaders } : {},
|
|
147
|
+
"req.headers"
|
|
148
|
+
),
|
|
149
|
+
path: reqPath,
|
|
150
|
+
url: reqPath,
|
|
151
|
+
method: "GET",
|
|
152
|
+
env: activeEnv,
|
|
153
|
+
},
|
|
154
|
+
res: {
|
|
155
|
+
status() {},
|
|
156
|
+
setHeader() {},
|
|
157
|
+
cookie() {},
|
|
158
|
+
clearCookie() {},
|
|
159
|
+
redirect() {},
|
|
160
|
+
},
|
|
161
|
+
env: activeEnv,
|
|
162
|
+
platformContext: outerCtx?.platformContext
|
|
163
|
+
? { ...outerCtx.platformContext, isSSG: false }
|
|
164
|
+
: { env: activeEnv },
|
|
165
|
+
_isStaticHtmlRender: Boolean(outerCtx?._isStaticHtmlRender),
|
|
166
|
+
_isSlotDiscovery: true,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
79
170
|
let _registerServerRefFn = null;
|
|
80
171
|
function getRegisterServerReference() {
|
|
81
172
|
if (_registerServerRefFn) return _registerServerRefFn;
|
|
@@ -95,7 +186,7 @@ function getRegisterServerReference() {
|
|
|
95
186
|
}
|
|
96
187
|
} catch (e) {}
|
|
97
188
|
try {
|
|
98
|
-
const pkg = require("@roggc/react-server-dom-esm/server.node
|
|
189
|
+
const pkg = require("@roggc/react-server-dom-esm/server.node");
|
|
99
190
|
if (typeof pkg.registerServerReference === "function") {
|
|
100
191
|
_registerServerRefFn = pkg.registerServerReference;
|
|
101
192
|
return _registerServerRefFn;
|
|
@@ -130,7 +221,7 @@ function getCacheSlotBoundary() {
|
|
|
130
221
|
}
|
|
131
222
|
if (!regFn) {
|
|
132
223
|
try {
|
|
133
|
-
const pkg = require("@roggc/react-server-dom-esm/server.node
|
|
224
|
+
const pkg = require("@roggc/react-server-dom-esm/server.node");
|
|
134
225
|
regFn = pkg.registerClientReference;
|
|
135
226
|
} catch (e) {}
|
|
136
227
|
}
|
|
@@ -341,11 +432,18 @@ async function getSlotFromStorage(storage, storageKey, knownTags = []) {
|
|
|
341
432
|
}
|
|
342
433
|
|
|
343
434
|
const isDeleted =
|
|
344
|
-
typeof storage.
|
|
435
|
+
typeof storage.isKeyDeleted === "function"
|
|
436
|
+
? await storage.isKeyDeleted(storageKey)
|
|
437
|
+
: typeof storage.isDeleted === "function" && storage.isDeleted(storageKey);
|
|
345
438
|
if (isDeleted) {
|
|
346
439
|
return null;
|
|
347
440
|
}
|
|
348
441
|
|
|
442
|
+
const cleanKeyForSlotId = String(storageKey || "")
|
|
443
|
+
.replace(/\\/g, "/")
|
|
444
|
+
.replace(/^\/+/, "");
|
|
445
|
+
const slotIdFromKey = cleanKeyForSlotId.match(/^slots\/([^/]+)\//)?.[1];
|
|
446
|
+
|
|
349
447
|
try {
|
|
350
448
|
const reqContext = getContext();
|
|
351
449
|
const assets =
|
|
@@ -354,13 +452,13 @@ async function getSlotFromStorage(storage, storageKey, knownTags = []) {
|
|
|
354
452
|
reqContext?.req?.env?.ASSETS ||
|
|
355
453
|
(typeof globalThis !== "undefined" ? globalThis.__DINOU_ENV__?.ASSETS : null);
|
|
356
454
|
if (assets && typeof assets.fetch === "function") {
|
|
357
|
-
const cleanKey =
|
|
455
|
+
const cleanKey = cleanKeyForSlotId;
|
|
358
456
|
const metaKey = cleanKey.endsWith("/slot.json")
|
|
359
457
|
? cleanKey.slice(0, -"/slot.json".length) + "/slot.metadata.json"
|
|
360
458
|
: `${cleanKey}.metadata.json`;
|
|
361
459
|
const [slotRes, metaRes] = await Promise.all([
|
|
362
|
-
assets
|
|
363
|
-
assets
|
|
460
|
+
fetchCloudflareDist2Asset(assets, cleanKey),
|
|
461
|
+
fetchCloudflareDist2Asset(assets, metaKey),
|
|
364
462
|
]);
|
|
365
463
|
if (slotRes && slotRes.status === 200) {
|
|
366
464
|
const ct = slotRes.headers?.get?.("content-type") || "";
|
|
@@ -375,14 +473,19 @@ async function getSlotFromStorage(storage, storageKey, knownTags = []) {
|
|
|
375
473
|
const generatedAt = metadata?.generatedAt || 0;
|
|
376
474
|
const combinedTags = new Set([
|
|
377
475
|
...(Array.isArray(metadata?.tags) ? metadata.tags : []),
|
|
476
|
+
...(metadata?.slotId ? [metadata.slotId] : []),
|
|
477
|
+
...(slotIdFromKey ? [slotIdFromKey] : []),
|
|
378
478
|
...(Array.isArray(knownTags) ? knownTags : []),
|
|
379
479
|
]);
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
480
|
+
for (const t of combinedTags) {
|
|
481
|
+
const invAt =
|
|
482
|
+
typeof storage.getTagInvalidatedAtAsync === "function"
|
|
483
|
+
? await storage.getTagInvalidatedAtAsync(t)
|
|
484
|
+
: typeof storage.getTagInvalidatedAt === "function"
|
|
485
|
+
? storage.getTagInvalidatedAt(t)
|
|
486
|
+
: 0;
|
|
487
|
+
if (invAt > 0 && invAt >= generatedAt) {
|
|
488
|
+
return null;
|
|
386
489
|
}
|
|
387
490
|
}
|
|
388
491
|
cached = { content, metadata };
|
|
@@ -393,6 +496,19 @@ async function getSlotFromStorage(storage, storageKey, knownTags = []) {
|
|
|
393
496
|
}
|
|
394
497
|
} catch (e) {}
|
|
395
498
|
|
|
499
|
+
const fallbackKnownTags = slotIdFromKey
|
|
500
|
+
? Array.from(
|
|
501
|
+
new Set([
|
|
502
|
+
...(Array.isArray(knownTags) ? knownTags : []),
|
|
503
|
+
slotIdFromKey,
|
|
504
|
+
])
|
|
505
|
+
)
|
|
506
|
+
: knownTags;
|
|
507
|
+
const dist2Item = await readDist2Fallback(storage, storageKey, fallbackKnownTags);
|
|
508
|
+
if (dist2Item && dist2Item.content) {
|
|
509
|
+
return dist2Item;
|
|
510
|
+
}
|
|
511
|
+
|
|
396
512
|
return cached;
|
|
397
513
|
}
|
|
398
514
|
|
|
@@ -403,7 +519,11 @@ async function readMetaFromStorageOrAssets(storage, key) {
|
|
|
403
519
|
if (item?.metadata && typeof item.metadata === "object") return item.metadata;
|
|
404
520
|
if (item?.content) return JSON.parse(item.content);
|
|
405
521
|
} catch (e) {}
|
|
406
|
-
|
|
522
|
+
const isDeleted =
|
|
523
|
+
typeof storage.isKeyDeleted === "function"
|
|
524
|
+
? await storage.isKeyDeleted(key)
|
|
525
|
+
: typeof storage.isDeleted === "function" && storage.isDeleted(key);
|
|
526
|
+
if (isDeleted) return null;
|
|
407
527
|
try {
|
|
408
528
|
const reqContext = getContext();
|
|
409
529
|
const assets =
|
|
@@ -413,7 +533,7 @@ async function readMetaFromStorageOrAssets(storage, key) {
|
|
|
413
533
|
(typeof globalThis !== "undefined" ? globalThis.__DINOU_ENV__?.ASSETS : null);
|
|
414
534
|
if (assets && typeof assets.fetch === "function") {
|
|
415
535
|
const cleanKey = String(key).replace(/^\/+/, "");
|
|
416
|
-
const res = await assets
|
|
536
|
+
const res = await fetchCloudflareDist2Asset(assets, cleanKey);
|
|
417
537
|
if (res && res.status === 200) {
|
|
418
538
|
const text = await res.text();
|
|
419
539
|
if (text && text.trimStart().startsWith("{")) {
|
|
@@ -424,6 +544,17 @@ async function readMetaFromStorageOrAssets(storage, key) {
|
|
|
424
544
|
}
|
|
425
545
|
}
|
|
426
546
|
} catch (e) {}
|
|
547
|
+
const dist2Item = await readDist2Fallback(storage, key);
|
|
548
|
+
if (dist2Item) {
|
|
549
|
+
if (dist2Item.metadata && typeof dist2Item.metadata === "object") {
|
|
550
|
+
return dist2Item.metadata;
|
|
551
|
+
}
|
|
552
|
+
if (dist2Item.content && dist2Item.content.trimStart().startsWith("{")) {
|
|
553
|
+
try {
|
|
554
|
+
return JSON.parse(dist2Item.content);
|
|
555
|
+
} catch (e) {}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
427
558
|
return null;
|
|
428
559
|
}
|
|
429
560
|
|
|
@@ -527,6 +658,7 @@ async function DinouCacheSlot(props) {
|
|
|
527
658
|
const { id, tag, tags, revalidate, children } = props || {};
|
|
528
659
|
const isNoCache = typeof revalidate === "number" && revalidate < 1;
|
|
529
660
|
const reqCtxInitial = getContext();
|
|
661
|
+
const rawQueryInitial = unwrapBailoutProxy(reqCtxInitial?.req?.query);
|
|
530
662
|
const shouldStreamSlotInSuspense =
|
|
531
663
|
isInsideRuntimeSuspenseOutsideSlot() &&
|
|
532
664
|
!isPprBuildActive() &&
|
|
@@ -536,7 +668,7 @@ async function DinouCacheSlot(props) {
|
|
|
536
668
|
!reqCtxInitial?._isPprRuntimeResume &&
|
|
537
669
|
(Boolean(reqCtxInitial?._dynamicState?.value) ||
|
|
538
670
|
isNoCache ||
|
|
539
|
-
Object.keys(
|
|
671
|
+
Object.keys(rawQueryInitial || {}).length > 0 ||
|
|
540
672
|
process.env.DINOU_DEV === "true" ||
|
|
541
673
|
process.env.NODE_ENV !== "production");
|
|
542
674
|
|
|
@@ -565,11 +697,13 @@ async function DinouCacheSlot(props) {
|
|
|
565
697
|
return await computeAnon();
|
|
566
698
|
}
|
|
567
699
|
|
|
568
|
-
const allTags = Array.
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
700
|
+
const allTags = Array.from(
|
|
701
|
+
new Set(
|
|
702
|
+
[...(tag ? [tag] : []), ...(Array.isArray(tags) ? tags : [])].filter(
|
|
703
|
+
Boolean
|
|
704
|
+
)
|
|
705
|
+
)
|
|
706
|
+
);
|
|
573
707
|
const slotTagsToCommit = Array.from(new Set([slotId, ...allTags].filter(Boolean)));
|
|
574
708
|
|
|
575
709
|
const storageKey = `slots/${slotId}/slot.json`;
|
|
@@ -602,6 +736,15 @@ async function DinouCacheSlot(props) {
|
|
|
602
736
|
}
|
|
603
737
|
|
|
604
738
|
// Register in slotRegistry for on-demand endpoint re-rendering and nested slot discovery
|
|
739
|
+
const prevSlotEntry = slotRegistry.get(slotId);
|
|
740
|
+
const slotRouteKeys =
|
|
741
|
+
prevSlotEntry?.routeKeys instanceof Set
|
|
742
|
+
? prevSlotEntry.routeKeys
|
|
743
|
+
: new Set();
|
|
744
|
+
const currentSlotRouteKey = normalizeSlotRouteKey(reqCtxInitial?.req?.path);
|
|
745
|
+
if (currentSlotRouteKey !== null) {
|
|
746
|
+
slotRouteKeys.add(currentSlotRouteKey);
|
|
747
|
+
}
|
|
605
748
|
slotRegistry.set(slotId, {
|
|
606
749
|
render: async () => {
|
|
607
750
|
return await runSlotScope(async () => {
|
|
@@ -609,16 +752,31 @@ async function DinouCacheSlot(props) {
|
|
|
609
752
|
return await asyncRenderJSXToClientJSX(childElement);
|
|
610
753
|
});
|
|
611
754
|
},
|
|
612
|
-
discover: async () => {
|
|
755
|
+
discover: async (discoverPath) => {
|
|
613
756
|
if (discoveringSlots.has(slotId)) return;
|
|
614
757
|
discoveringSlots.add(slotId);
|
|
615
758
|
try {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
759
|
+
const fallbackRoute =
|
|
760
|
+
discoverPath ||
|
|
761
|
+
(slotRouteKeys.size > 0
|
|
762
|
+
? "/" + Array.from(slotRouteKeys)[0]
|
|
763
|
+
: undefined);
|
|
764
|
+
await requestStorage.run(
|
|
765
|
+
createDiscoveryContext(fallbackRoute),
|
|
766
|
+
async () => {
|
|
767
|
+
await runWithPprContext({ isPpr: true }, async () => {
|
|
768
|
+
await runInSlotDiscovery(async () => {
|
|
769
|
+
await runSlotScope(async () => {
|
|
770
|
+
const childElement =
|
|
771
|
+
typeof children === "function"
|
|
772
|
+
? await children()
|
|
773
|
+
: children;
|
|
774
|
+
await asyncRenderJSXToClientJSX(childElement);
|
|
775
|
+
});
|
|
776
|
+
});
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
);
|
|
622
780
|
} catch (e) {
|
|
623
781
|
} finally {
|
|
624
782
|
discoveringSlots.delete(slotId);
|
|
@@ -626,6 +784,7 @@ async function DinouCacheSlot(props) {
|
|
|
626
784
|
},
|
|
627
785
|
tags: allTags,
|
|
628
786
|
revalidate: typeof revalidate === "number" ? revalidate : undefined,
|
|
787
|
+
routeKeys: slotRouteKeys,
|
|
629
788
|
});
|
|
630
789
|
|
|
631
790
|
// When running inside a nested slot discovery pass, recursively discover any child slots
|
|
@@ -674,7 +833,7 @@ async function DinouCacheSlot(props) {
|
|
|
674
833
|
}
|
|
675
834
|
|
|
676
835
|
// 1. Check if cached in storage
|
|
677
|
-
let cached = await getSlotFromStorage(storage, storageKey,
|
|
836
|
+
let cached = await getSlotFromStorage(storage, storageKey, slotTagsToCommit);
|
|
678
837
|
|
|
679
838
|
// During a PPR static shell build, if a slot is inside a <Suspense> boundary
|
|
680
839
|
// and was only cached at runtime (not part of the static shell), do not short-circuit
|
|
@@ -890,23 +1049,34 @@ async function resolveCanonicalSlotId(slotIdOrTag, storage) {
|
|
|
890
1049
|
if (direct && direct.content) {
|
|
891
1050
|
return slotIdOrTag;
|
|
892
1051
|
}
|
|
1052
|
+
const candidateKeySet = new Set();
|
|
893
1053
|
if (typeof storage.keys === "function") {
|
|
894
1054
|
const keys = await storage.keys("slots/");
|
|
895
|
-
for (const
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1055
|
+
for (const k of keys) candidateKeySet.add(String(k || "").replace(/\\/g, "/"));
|
|
1056
|
+
}
|
|
1057
|
+
if (!storage.baseDir && storage.hydrateFromDisk !== false) {
|
|
1058
|
+
try {
|
|
1059
|
+
const dist2SlotsFs = new FileSystemStorage();
|
|
1060
|
+
const diskSlotKeys = await dist2SlotsFs.keys("slots/");
|
|
1061
|
+
for (const k of diskSlotKeys) {
|
|
1062
|
+
candidateKeySet.add(String(k || "").replace(/\\/g, "/"));
|
|
1063
|
+
}
|
|
1064
|
+
} catch (e) {}
|
|
1065
|
+
}
|
|
1066
|
+
for (const key of candidateKeySet) {
|
|
1067
|
+
if (key.endsWith("/slot.json") || key.endsWith("/slot.metadata.json")) {
|
|
1068
|
+
const item =
|
|
1069
|
+
(await storage.get(key)) || (await readDist2Fallback(storage, key));
|
|
1070
|
+
let meta = item?.metadata;
|
|
1071
|
+
if (!meta && key.endsWith("/slot.metadata.json") && item?.content) {
|
|
1072
|
+
try {
|
|
1073
|
+
meta = JSON.parse(item.content);
|
|
1074
|
+
} catch (e) {}
|
|
1075
|
+
}
|
|
1076
|
+
if (meta && Array.isArray(meta.tags) && meta.tags.includes(slotIdOrTag)) {
|
|
1077
|
+
if (meta.slotId) return meta.slotId;
|
|
1078
|
+
const match = key.match(/^slots\/([^/]+)\//);
|
|
1079
|
+
if (match) return match[1];
|
|
910
1080
|
}
|
|
911
1081
|
}
|
|
912
1082
|
}
|
|
@@ -947,7 +1117,7 @@ async function getSlotJSX(slotId, options = {}) {
|
|
|
947
1117
|
}
|
|
948
1118
|
|
|
949
1119
|
// 1. Check storage cache
|
|
950
|
-
let cached = await getSlotFromStorage(storage, storageKey);
|
|
1120
|
+
let cached = await getSlotFromStorage(storage, storageKey, [targetId]);
|
|
951
1121
|
|
|
952
1122
|
const regEntryInitial = slotRegistry.get(targetId);
|
|
953
1123
|
const now = Date.now();
|
|
@@ -961,11 +1131,11 @@ async function getSlotJSX(slotId, options = {}) {
|
|
|
961
1131
|
? meta.revalidate
|
|
962
1132
|
: undefined;
|
|
963
1133
|
|
|
964
|
-
const isNoCache = revalidateSeconds ===
|
|
1134
|
+
const isNoCache = typeof revalidateSeconds === "number" && revalidateSeconds < 1;
|
|
965
1135
|
const isExpired =
|
|
966
1136
|
isNoCache ||
|
|
967
1137
|
(typeof revalidateSeconds === "number" &&
|
|
968
|
-
revalidateSeconds
|
|
1138
|
+
revalidateSeconds >= 1 &&
|
|
969
1139
|
now > generatedAt + revalidateSeconds * 1000);
|
|
970
1140
|
|
|
971
1141
|
const serveStaleWhileRevalidate =
|
|
@@ -986,17 +1156,24 @@ async function getSlotJSX(slotId, options = {}) {
|
|
|
986
1156
|
}
|
|
987
1157
|
}
|
|
988
1158
|
|
|
989
|
-
|
|
990
|
-
|
|
1159
|
+
const attemptedDiscoveryKeys = new Set();
|
|
1160
|
+
async function discoverFromRegisteredSlots(filterRouteKey = undefined) {
|
|
991
1161
|
let progressed = true;
|
|
992
1162
|
while (!slotRegistry.has(targetId) && progressed) {
|
|
993
1163
|
progressed = false;
|
|
994
1164
|
for (const [regKey, entry] of Array.from(slotRegistry.entries())) {
|
|
995
|
-
if (
|
|
996
|
-
|
|
1165
|
+
if (attemptedDiscoveryKeys.has(regKey)) continue;
|
|
1166
|
+
if (
|
|
1167
|
+
filterRouteKey !== undefined &&
|
|
1168
|
+
filterRouteKey !== null &&
|
|
1169
|
+
!doesSlotEntryMatchRoute(entry, filterRouteKey)
|
|
1170
|
+
) {
|
|
1171
|
+
continue;
|
|
1172
|
+
}
|
|
1173
|
+
attemptedDiscoveryKeys.add(regKey);
|
|
997
1174
|
progressed = true;
|
|
998
1175
|
if (typeof entry.discover === "function") {
|
|
999
|
-
await entry.discover();
|
|
1176
|
+
await entry.discover(options.currentPath);
|
|
1000
1177
|
targetId = await resolveCanonicalSlotId(slotId, storage);
|
|
1001
1178
|
if (slotRegistry.has(targetId)) return;
|
|
1002
1179
|
}
|
|
@@ -1004,9 +1181,13 @@ async function getSlotJSX(slotId, options = {}) {
|
|
|
1004
1181
|
}
|
|
1005
1182
|
}
|
|
1006
1183
|
|
|
1007
|
-
|
|
1184
|
+
const cleanCurrentRouteKey = options.currentPath
|
|
1185
|
+
? normalizeSlotRouteKey(options.currentPath)
|
|
1186
|
+
: null;
|
|
1187
|
+
|
|
1188
|
+
// 2. First try discovering nested slots from already-registered outer slots matching this route
|
|
1008
1189
|
if (!slotRegistry.has(targetId)) {
|
|
1009
|
-
await discoverFromRegisteredSlots();
|
|
1190
|
+
await discoverFromRegisteredSlots(cleanCurrentRouteKey);
|
|
1010
1191
|
}
|
|
1011
1192
|
|
|
1012
1193
|
// 3. If still not in slotRegistry (e.g., cold server start), pre-evaluate the route once
|
|
@@ -1020,24 +1201,45 @@ async function getSlotJSX(slotId, options = {}) {
|
|
|
1020
1201
|
const preEvalPromise = (async () => {
|
|
1021
1202
|
try {
|
|
1022
1203
|
const isNotFound = { value: false };
|
|
1023
|
-
await
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1204
|
+
await requestStorage.run(
|
|
1205
|
+
createDiscoveryContext(options.currentPath),
|
|
1206
|
+
async () => {
|
|
1207
|
+
await runWithPprContext({ isPpr: true }, async () => {
|
|
1208
|
+
await runInSlotDiscovery(async () => {
|
|
1209
|
+
const pageJsx = await getJSX(
|
|
1210
|
+
options.currentPath,
|
|
1211
|
+
{},
|
|
1212
|
+
isNotFound,
|
|
1213
|
+
false,
|
|
1214
|
+
false,
|
|
1215
|
+
{
|
|
1216
|
+
segment: "page",
|
|
1217
|
+
}
|
|
1218
|
+
);
|
|
1219
|
+
if (pageJsx) {
|
|
1220
|
+
await asyncRenderJSXToClientJSX(pageJsx);
|
|
1221
|
+
}
|
|
1222
|
+
const resolvedId = await resolveCanonicalSlotId(
|
|
1223
|
+
slotId,
|
|
1224
|
+
storage
|
|
1225
|
+
);
|
|
1226
|
+
|
|
1227
|
+
if (!slotRegistry.has(resolvedId)) {
|
|
1228
|
+
const fullJsx = await getJSX(
|
|
1229
|
+
options.currentPath,
|
|
1230
|
+
{},
|
|
1231
|
+
isNotFound,
|
|
1232
|
+
false,
|
|
1233
|
+
false
|
|
1234
|
+
);
|
|
1235
|
+
if (fullJsx) {
|
|
1236
|
+
await asyncRenderJSXToClientJSX(fullJsx);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1027
1240
|
});
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
}
|
|
1031
|
-
const resolvedId = await resolveCanonicalSlotId(slotId, storage);
|
|
1032
|
-
|
|
1033
|
-
if (!slotRegistry.has(resolvedId)) {
|
|
1034
|
-
const fullJsx = await getJSX(options.currentPath, {}, isNotFound, false, false);
|
|
1035
|
-
if (fullJsx) {
|
|
1036
|
-
await asyncRenderJSXToClientJSX(fullJsx);
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
});
|
|
1040
|
-
});
|
|
1241
|
+
}
|
|
1242
|
+
);
|
|
1041
1243
|
} catch (e) {
|
|
1042
1244
|
console.warn(
|
|
1043
1245
|
`[getSlotJSX] Could not pre-evaluate route "${options.currentPath}" to register slot "${slotId}":`,
|
|
@@ -1053,10 +1255,15 @@ async function getSlotJSX(slotId, options = {}) {
|
|
|
1053
1255
|
}
|
|
1054
1256
|
|
|
1055
1257
|
if (!slotRegistry.has(targetId)) {
|
|
1056
|
-
await discoverFromRegisteredSlots();
|
|
1258
|
+
await discoverFromRegisteredSlots(cleanCurrentRouteKey);
|
|
1057
1259
|
}
|
|
1058
1260
|
}
|
|
1059
1261
|
|
|
1262
|
+
// 4. Final global fallback across any remaining registered slots if route-scoped lookup missed
|
|
1263
|
+
if (!slotRegistry.has(targetId)) {
|
|
1264
|
+
await discoverFromRegisteredSlots(null);
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1060
1267
|
storageKey = `slots/${targetId}/slot.json`;
|
|
1061
1268
|
|
|
1062
1269
|
if (slotRegistry.has(targetId)) {
|
|
@@ -1086,6 +1293,9 @@ async function getSlotJSX(slotId, options = {}) {
|
|
|
1086
1293
|
slotRenderGenerations.set(storageKey, renderGen);
|
|
1087
1294
|
const isLatestGen = () => slotRenderGenerations.get(storageKey) === renderGen;
|
|
1088
1295
|
|
|
1296
|
+
const isEntryNoCache =
|
|
1297
|
+
typeof entry.revalidate === "number" && entry.revalidate < 1;
|
|
1298
|
+
|
|
1089
1299
|
const renderPromise = (async () => {
|
|
1090
1300
|
const resolved = await entry.render();
|
|
1091
1301
|
const serialized = serializeJSX(resolved);
|
|
@@ -1095,7 +1305,7 @@ async function getSlotJSX(slotId, options = {}) {
|
|
|
1095
1305
|
serialized,
|
|
1096
1306
|
});
|
|
1097
1307
|
}
|
|
1098
|
-
if (storage &&
|
|
1308
|
+
if (storage && !isEntryNoCache && isLatestGen()) {
|
|
1099
1309
|
await storage.set(storageKey, serialized, {
|
|
1100
1310
|
tags: entry.tags,
|
|
1101
1311
|
revalidate: entry.revalidate,
|
|
@@ -1124,7 +1334,7 @@ async function getSlotJSX(slotId, options = {}) {
|
|
|
1124
1334
|
|
|
1125
1335
|
if (
|
|
1126
1336
|
storage &&
|
|
1127
|
-
|
|
1337
|
+
!isEntryNoCache &&
|
|
1128
1338
|
!options.skipHostRevalidate &&
|
|
1129
1339
|
options.currentPath &&
|
|
1130
1340
|
isLatestGen()
|
|
@@ -1200,7 +1410,7 @@ async function hasExpiredSlots(slotTags) {
|
|
|
1200
1410
|
if (checkedIds.has(targetId)) continue;
|
|
1201
1411
|
checkedIds.add(targetId);
|
|
1202
1412
|
const storageKey = `slots/${targetId}/slot.json`;
|
|
1203
|
-
const cached = await getSlotFromStorage(storage, storageKey);
|
|
1413
|
+
const cached = await getSlotFromStorage(storage, storageKey, [targetId]);
|
|
1204
1414
|
if (!cached || !cached.content) continue;
|
|
1205
1415
|
const meta = cached.metadata || {};
|
|
1206
1416
|
const regEntry = slotRegistry.get(targetId);
|
|
@@ -1212,7 +1422,7 @@ async function hasExpiredSlots(slotTags) {
|
|
|
1212
1422
|
: undefined;
|
|
1213
1423
|
if (
|
|
1214
1424
|
typeof revalidateSeconds === "number" &&
|
|
1215
|
-
revalidateSeconds
|
|
1425
|
+
revalidateSeconds >= 1 &&
|
|
1216
1426
|
now > (meta.generatedAt || 0) + revalidateSeconds * 1000
|
|
1217
1427
|
) {
|
|
1218
1428
|
return true;
|