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
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import rawPostcss from "#postcss";
|
|
4
|
+
import rawPostcssImport from "#postcss-import";
|
|
5
|
+
import rawTailwindcss from "#tailwindcss/postcss";
|
|
6
|
+
import rawAutoprefixer from "#autoprefixer";
|
|
7
|
+
import rawPostCssModules from "#postcss-modules";
|
|
8
|
+
import createScopedName from "./createScopedName.js";
|
|
9
|
+
import { getAssetFileName } from "./asset-extensions.js";
|
|
10
|
+
import { getAbsPathWithExt, resolveCssImportSpecifier } from "./get-abs-path-with-ext.js";
|
|
11
|
+
|
|
12
|
+
const unwrap = (mod) => (typeof mod === "function" ? mod : mod?.default || mod);
|
|
13
|
+
|
|
14
|
+
export const postcss = unwrap(rawPostcss);
|
|
15
|
+
export const postcssImport = unwrap(rawPostcssImport);
|
|
16
|
+
export const tailwindcss = unwrap(rawTailwindcss);
|
|
17
|
+
export const autoprefixer = unwrap(rawAutoprefixer);
|
|
18
|
+
export const postCssModules = unwrap(rawPostCssModules);
|
|
19
|
+
|
|
20
|
+
const URL_FUNCTION_REGEX = /url\(\s*(?:"([^"]+)"|'([^']+)'|([^)"'\s]+))\s*\)/gi;
|
|
21
|
+
|
|
22
|
+
function isExternalOrPublicCssUrl(rawUrl) {
|
|
23
|
+
if (!rawUrl) return true;
|
|
24
|
+
const trimmed = rawUrl.trim();
|
|
25
|
+
if (
|
|
26
|
+
!trimmed ||
|
|
27
|
+
trimmed.startsWith("/") ||
|
|
28
|
+
trimmed.startsWith("#") ||
|
|
29
|
+
trimmed.startsWith("data:") ||
|
|
30
|
+
trimmed.startsWith("blob:") ||
|
|
31
|
+
trimmed.startsWith("http:") ||
|
|
32
|
+
trimmed.startsWith("https:") ||
|
|
33
|
+
trimmed.startsWith("//")
|
|
34
|
+
) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function resolveCssAssetUrlPath(cleanUrlPath, declDir) {
|
|
41
|
+
const viaAliasOrRel = getAbsPathWithExt(cleanUrlPath, { parentDir: declDir });
|
|
42
|
+
if (viaAliasOrRel && fs.existsSync(viaAliasOrRel) && fs.statSync(viaAliasOrRel).isFile()) {
|
|
43
|
+
return viaAliasOrRel;
|
|
44
|
+
}
|
|
45
|
+
const candidate = path.resolve(declDir, cleanUrlPath);
|
|
46
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
|
|
47
|
+
return candidate;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function getRegisteredCssUrlAssets() {
|
|
53
|
+
if (typeof globalThis === "undefined") return new Map();
|
|
54
|
+
if (!globalThis.__DINOU_CSS_URL_ASSETS__) {
|
|
55
|
+
globalThis.__DINOU_CSS_URL_ASSETS__ = new Map();
|
|
56
|
+
}
|
|
57
|
+
return globalThis.__DINOU_CSS_URL_ASSETS__;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function createHoistCssImportsPlugin() {
|
|
61
|
+
return {
|
|
62
|
+
postcssPlugin: "dinou-hoist-css-imports",
|
|
63
|
+
Once(root) {
|
|
64
|
+
if (!root?.nodes || root.nodes.length < 2) return;
|
|
65
|
+
const tailwindHeaderAtRules = new Set([
|
|
66
|
+
"reference",
|
|
67
|
+
"config",
|
|
68
|
+
"plugin",
|
|
69
|
+
"source",
|
|
70
|
+
]);
|
|
71
|
+
let seenTailwindHeader = false;
|
|
72
|
+
const importsToHoist = [];
|
|
73
|
+
let firstTailwindHeaderNode = null;
|
|
74
|
+
|
|
75
|
+
for (const node of root.nodes) {
|
|
76
|
+
if (node.type === "comment") continue;
|
|
77
|
+
if (node.type === "atrule") {
|
|
78
|
+
const name = node.name.toLowerCase();
|
|
79
|
+
if (name === "charset") continue;
|
|
80
|
+
if (name === "layer" && (!node.nodes || node.nodes.length === 0)) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (tailwindHeaderAtRules.has(name)) {
|
|
84
|
+
if (!firstTailwindHeaderNode) firstTailwindHeaderNode = node;
|
|
85
|
+
seenTailwindHeader = true;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (name === "import") {
|
|
89
|
+
if (seenTailwindHeader) {
|
|
90
|
+
importsToHoist.push(node);
|
|
91
|
+
}
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (firstTailwindHeaderNode && importsToHoist.length > 0) {
|
|
99
|
+
for (const impNode of importsToHoist) {
|
|
100
|
+
impNode.remove();
|
|
101
|
+
root.insertBefore(firstTailwindHeaderNode, impNode);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
createHoistCssImportsPlugin.postcss = true;
|
|
108
|
+
|
|
109
|
+
function rewriteCssUrlAssets(root, result, { onAsset } = {}) {
|
|
110
|
+
const fallbackFrom = result?.opts?.from
|
|
111
|
+
? path.resolve(result.opts.from)
|
|
112
|
+
: path.join(process.cwd(), "src", "__styles__.css");
|
|
113
|
+
|
|
114
|
+
root.walkDecls((decl) => {
|
|
115
|
+
if (!decl.value || !decl.value.includes("url(")) return;
|
|
116
|
+
|
|
117
|
+
const declFile = decl.source?.input?.file
|
|
118
|
+
? path.resolve(decl.source.input.file)
|
|
119
|
+
: fallbackFrom;
|
|
120
|
+
const declDir = path.dirname(declFile);
|
|
121
|
+
|
|
122
|
+
URL_FUNCTION_REGEX.lastIndex = 0;
|
|
123
|
+
const nextValue = decl.value.replace(
|
|
124
|
+
URL_FUNCTION_REGEX,
|
|
125
|
+
(fullMatch, dqUrl, sqUrl, bareUrl) => {
|
|
126
|
+
const rawUrl = dqUrl ?? sqUrl ?? bareUrl ?? "";
|
|
127
|
+
if (isExternalOrPublicCssUrl(rawUrl)) {
|
|
128
|
+
return fullMatch;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const hashIdx = rawUrl.indexOf("#");
|
|
132
|
+
const hashPart = hashIdx === -1 ? "" : rawUrl.slice(hashIdx);
|
|
133
|
+
const withoutHash = hashIdx === -1 ? rawUrl : rawUrl.slice(0, hashIdx);
|
|
134
|
+
const queryIdx = withoutHash.indexOf("?");
|
|
135
|
+
const cleanUrlPath =
|
|
136
|
+
queryIdx === -1 ? withoutHash : withoutHash.slice(0, queryIdx);
|
|
137
|
+
|
|
138
|
+
if (!cleanUrlPath) return fullMatch;
|
|
139
|
+
|
|
140
|
+
const resolvedPath = resolveCssAssetUrlPath(cleanUrlPath, declDir);
|
|
141
|
+
if (!resolvedPath) {
|
|
142
|
+
return fullMatch;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const assetFileName = getAssetFileName(resolvedPath, process.cwd());
|
|
146
|
+
const assetBaseName = path.basename(assetFileName);
|
|
147
|
+
|
|
148
|
+
const registry = getRegisteredCssUrlAssets();
|
|
149
|
+
registry.set(assetFileName, resolvedPath);
|
|
150
|
+
|
|
151
|
+
if (typeof onAsset === "function") {
|
|
152
|
+
onAsset(resolvedPath, assetFileName);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (
|
|
156
|
+
typeof globalThis !== "undefined" &&
|
|
157
|
+
process.env.NODE_ENV !== "production"
|
|
158
|
+
) {
|
|
159
|
+
try {
|
|
160
|
+
const buf = fs.readFileSync(resolvedPath);
|
|
161
|
+
if (!globalThis.__DINOU_MEM_FILES__) {
|
|
162
|
+
globalThis.__DINOU_MEM_FILES__ = new Map();
|
|
163
|
+
}
|
|
164
|
+
globalThis.__DINOU_MEM_FILES__.set(assetFileName, buf);
|
|
165
|
+
globalThis.__DINOU_MEM_FILES__.set("/" + assetFileName, buf);
|
|
166
|
+
globalThis.__DINOU_MEM_FILES__.set(assetBaseName, buf);
|
|
167
|
+
} catch (e) {}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (result && Array.isArray(result.messages)) {
|
|
171
|
+
result.messages.push({
|
|
172
|
+
type: "dependency",
|
|
173
|
+
plugin: "dinou-postcss-url-assets",
|
|
174
|
+
file: resolvedPath,
|
|
175
|
+
parent: declFile,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return `url("/${assetFileName}${hashPart}")`;
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
if (nextValue !== decl.value) {
|
|
184
|
+
decl.value = nextValue;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function createPostCssUrlAssetsPlugin({
|
|
190
|
+
onAsset,
|
|
191
|
+
stage = "exit",
|
|
192
|
+
} = {}) {
|
|
193
|
+
const hookName = stage === "once" ? "Once" : "OnceExit";
|
|
194
|
+
return {
|
|
195
|
+
postcssPlugin:
|
|
196
|
+
stage === "once"
|
|
197
|
+
? "dinou-postcss-url-assets-pre"
|
|
198
|
+
: "dinou-postcss-url-assets",
|
|
199
|
+
[hookName](root, { result }) {
|
|
200
|
+
rewriteCssUrlAssets(root, result, { onAsset });
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
createPostCssUrlAssetsPlugin.postcss = true;
|
|
205
|
+
|
|
206
|
+
export function createBasePostCssPlugins({ onAsset } = {}) {
|
|
207
|
+
return [
|
|
208
|
+
createHoistCssImportsPlugin(),
|
|
209
|
+
postcssImport({
|
|
210
|
+
resolve: (id, basedir) => resolveCssImportSpecifier(id, basedir),
|
|
211
|
+
}),
|
|
212
|
+
createPostCssUrlAssetsPlugin({ onAsset, stage: "once" }),
|
|
213
|
+
tailwindcss(),
|
|
214
|
+
autoprefixer(),
|
|
215
|
+
createPostCssUrlAssetsPlugin({ onAsset, stage: "exit" }),
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function isTailwindStylesheetSource(source) {
|
|
220
|
+
if (typeof source !== "string") return false;
|
|
221
|
+
return /@import\s+["']tailwindcss(?:\/|["'])|@tailwind\b/.test(source);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export default {
|
|
225
|
+
postcss,
|
|
226
|
+
postcssImport,
|
|
227
|
+
tailwindcss,
|
|
228
|
+
autoprefixer,
|
|
229
|
+
postCssModules,
|
|
230
|
+
createHoistCssImportsPlugin,
|
|
231
|
+
createPostCssUrlAssetsPlugin,
|
|
232
|
+
createBasePostCssPlugins,
|
|
233
|
+
getRegisteredCssUrlAssets,
|
|
234
|
+
isTailwindStylesheetSource,
|
|
235
|
+
};
|
|
236
|
+
|
|
@@ -3,19 +3,65 @@
|
|
|
3
3
|
|
|
4
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
6
|
+
const PPR_STORAGE_KEY = Symbol.for("dinou.ppr.storage");
|
|
7
|
+
const PAGE_SEGMENT_STORAGE_KEY = Symbol.for("dinou.page.segment.storage");
|
|
8
|
+
const LAYOUT_SEGMENT_STORAGE_KEY = Symbol.for("dinou.layout.segment.storage");
|
|
9
|
+
const CACHED_SLOT_STORAGE_KEY = Symbol.for("dinou.cached.slot.storage");
|
|
10
|
+
const SLOT_DISCOVERY_STORAGE_KEY = Symbol.for("dinou.slot.discovery.storage");
|
|
11
|
+
const RUNTIME_STATIC_SUSPENSE_STORAGE_KEY = Symbol.for(
|
|
12
|
+
"dinou.runtime.static.suspense.storage"
|
|
13
|
+
);
|
|
14
|
+
const PAGE_ROOT_ELEMENTS_KEY = Symbol.for("dinou.page.root.elements");
|
|
15
|
+
const LAYOUT_ROOT_ELEMENTS_KEY = Symbol.for("dinou.layout.root.elements");
|
|
16
|
+
const LAYOUT_CHILDREN_PLACEHOLDERS_KEY = Symbol.for(
|
|
17
|
+
"dinou.layout.children.placeholders"
|
|
18
|
+
);
|
|
19
|
+
const NO_DYNAMIC_STATE_KEY = Symbol.for("dinou.ppr.noDynamic.state");
|
|
20
|
+
|
|
21
|
+
if (!globalThis[PPR_STORAGE_KEY]) {
|
|
22
|
+
globalThis[PPR_STORAGE_KEY] = new AsyncLocalStorage();
|
|
23
|
+
}
|
|
24
|
+
if (!globalThis[PAGE_SEGMENT_STORAGE_KEY]) {
|
|
25
|
+
globalThis[PAGE_SEGMENT_STORAGE_KEY] = new AsyncLocalStorage();
|
|
26
|
+
}
|
|
27
|
+
if (!globalThis[LAYOUT_SEGMENT_STORAGE_KEY]) {
|
|
28
|
+
globalThis[LAYOUT_SEGMENT_STORAGE_KEY] = new AsyncLocalStorage();
|
|
29
|
+
}
|
|
30
|
+
if (!globalThis[CACHED_SLOT_STORAGE_KEY]) {
|
|
31
|
+
globalThis[CACHED_SLOT_STORAGE_KEY] = new AsyncLocalStorage();
|
|
32
|
+
}
|
|
33
|
+
if (!globalThis[SLOT_DISCOVERY_STORAGE_KEY]) {
|
|
34
|
+
globalThis[SLOT_DISCOVERY_STORAGE_KEY] = new AsyncLocalStorage();
|
|
35
|
+
}
|
|
36
|
+
if (!globalThis[RUNTIME_STATIC_SUSPENSE_STORAGE_KEY]) {
|
|
37
|
+
globalThis[RUNTIME_STATIC_SUSPENSE_STORAGE_KEY] = new AsyncLocalStorage();
|
|
38
|
+
}
|
|
39
|
+
if (!globalThis[PAGE_ROOT_ELEMENTS_KEY]) {
|
|
40
|
+
globalThis[PAGE_ROOT_ELEMENTS_KEY] = new WeakMap();
|
|
41
|
+
}
|
|
42
|
+
if (!globalThis[LAYOUT_ROOT_ELEMENTS_KEY]) {
|
|
43
|
+
globalThis[LAYOUT_ROOT_ELEMENTS_KEY] = new WeakMap();
|
|
44
|
+
}
|
|
45
|
+
if (!globalThis[LAYOUT_CHILDREN_PLACEHOLDERS_KEY]) {
|
|
46
|
+
globalThis[LAYOUT_CHILDREN_PLACEHOLDERS_KEY] = new WeakSet();
|
|
47
|
+
}
|
|
48
|
+
if (!globalThis[NO_DYNAMIC_STATE_KEY]) {
|
|
49
|
+
globalThis[NO_DYNAMIC_STATE_KEY] = { currentComponentNoDynamic: false };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const pprStorage = globalThis[PPR_STORAGE_KEY];
|
|
53
|
+
const pageSegmentStorage = globalThis[PAGE_SEGMENT_STORAGE_KEY];
|
|
54
|
+
const layoutSegmentStorage = globalThis[LAYOUT_SEGMENT_STORAGE_KEY];
|
|
55
|
+
const cachedSlotStorage = globalThis[CACHED_SLOT_STORAGE_KEY];
|
|
56
|
+
const slotDiscoveryStorage = globalThis[SLOT_DISCOVERY_STORAGE_KEY];
|
|
57
|
+
const runtimeStaticSuspenseStorage = globalThis[RUNTIME_STATIC_SUSPENSE_STORAGE_KEY];
|
|
58
|
+
const pageRootElements = globalThis[PAGE_ROOT_ELEMENTS_KEY];
|
|
59
|
+
const layoutRootElements = globalThis[LAYOUT_ROOT_ELEMENTS_KEY];
|
|
60
|
+
const layoutChildrenPlaceholders = globalThis[LAYOUT_CHILDREN_PLACEHOLDERS_KEY];
|
|
15
61
|
|
|
16
62
|
const NO_DYNAMIC_HOOK_KEY = Symbol.for("dinou.ppr.noDynamic.hook");
|
|
17
63
|
export const SKIP_STATIC_SUSPENSE_SYMBOL = Symbol.for("dinou.ppr.skipStatic");
|
|
18
|
-
|
|
64
|
+
const noDynamicState = globalThis[NO_DYNAMIC_STATE_KEY];
|
|
19
65
|
|
|
20
66
|
export function runInRuntimeStaticSuspense(callback) {
|
|
21
67
|
const prev = runtimeStaticSuspenseStorage.getStore();
|
|
@@ -72,7 +118,7 @@ export function noDynamic() {
|
|
|
72
118
|
err.$$typeof = SKIP_STATIC_SUSPENSE_SYMBOL;
|
|
73
119
|
throw err;
|
|
74
120
|
}
|
|
75
|
-
currentComponentNoDynamic = true;
|
|
121
|
+
noDynamicState.currentComponentNoDynamic = true;
|
|
76
122
|
const store = pprStorage.getStore();
|
|
77
123
|
if (store && store.suspenseDepth > 0) {
|
|
78
124
|
store.noDynamic = true;
|
|
@@ -84,17 +130,17 @@ if (typeof globalThis !== "undefined") {
|
|
|
84
130
|
}
|
|
85
131
|
|
|
86
132
|
export function resetComponentNoDynamicFlag() {
|
|
87
|
-
currentComponentNoDynamic = false;
|
|
133
|
+
noDynamicState.currentComponentNoDynamic = false;
|
|
88
134
|
}
|
|
89
135
|
|
|
90
136
|
export function consumeComponentNoDynamicFlag() {
|
|
91
|
-
const val = currentComponentNoDynamic;
|
|
92
|
-
currentComponentNoDynamic = false;
|
|
137
|
+
const val = noDynamicState.currentComponentNoDynamic;
|
|
138
|
+
noDynamicState.currentComponentNoDynamic = false;
|
|
93
139
|
return val;
|
|
94
140
|
}
|
|
95
141
|
|
|
96
142
|
export function isNoDynamicActive() {
|
|
97
|
-
if (currentComponentNoDynamic) return true;
|
|
143
|
+
if (noDynamicState.currentComponentNoDynamic) return true;
|
|
98
144
|
const store = pprStorage.getStore();
|
|
99
145
|
return Boolean(store && store.noDynamic);
|
|
100
146
|
}
|
|
@@ -132,9 +178,11 @@ export function isSlotDiscoveryActive() {
|
|
|
132
178
|
return Boolean(slotDiscoveryStorage.getStore()?.active);
|
|
133
179
|
}
|
|
134
180
|
|
|
135
|
-
export function markPageRootElement(el) {
|
|
181
|
+
export function markPageRootElement(el, segmentPpr = null) {
|
|
136
182
|
if (el && typeof el === "object") {
|
|
137
|
-
pageRootElements.
|
|
183
|
+
pageRootElements.set(el, {
|
|
184
|
+
isPpr: typeof segmentPpr === "boolean" ? segmentPpr : null,
|
|
185
|
+
});
|
|
138
186
|
}
|
|
139
187
|
return el;
|
|
140
188
|
}
|
|
@@ -143,9 +191,18 @@ export function isPageRootElement(el) {
|
|
|
143
191
|
return Boolean(el && typeof el === "object" && pageRootElements.has(el));
|
|
144
192
|
}
|
|
145
193
|
|
|
146
|
-
export function
|
|
194
|
+
export function getPageRootPpr(el) {
|
|
195
|
+
if (el && typeof el === "object" && pageRootElements.has(el)) {
|
|
196
|
+
return pageRootElements.get(el)?.isPpr ?? null;
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function markLayoutRootElement(el, segmentPpr = null) {
|
|
147
202
|
if (el && typeof el === "object") {
|
|
148
|
-
layoutRootElements.
|
|
203
|
+
layoutRootElements.set(el, {
|
|
204
|
+
isPpr: typeof segmentPpr === "boolean" ? segmentPpr : null,
|
|
205
|
+
});
|
|
149
206
|
}
|
|
150
207
|
return el;
|
|
151
208
|
}
|
|
@@ -154,6 +211,34 @@ export function isLayoutRootElement(el) {
|
|
|
154
211
|
return Boolean(el && typeof el === "object" && layoutRootElements.has(el));
|
|
155
212
|
}
|
|
156
213
|
|
|
214
|
+
export function getLayoutRootPpr(el) {
|
|
215
|
+
if (el && typeof el === "object" && layoutRootElements.has(el)) {
|
|
216
|
+
return layoutRootElements.get(el)?.isPpr ?? null;
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function runWithSegmentPpr(segmentPpr, callback) {
|
|
222
|
+
const runClearedRuntimeHole = () =>
|
|
223
|
+
runtimeStaticSuspenseStorage.run(null, callback);
|
|
224
|
+
const store = getPprStore();
|
|
225
|
+
if (!store) {
|
|
226
|
+
return runClearedRuntimeHole();
|
|
227
|
+
}
|
|
228
|
+
const nextStore = {
|
|
229
|
+
...store,
|
|
230
|
+
isPpr: typeof segmentPpr === "boolean" ? segmentPpr : store.isPpr,
|
|
231
|
+
suspenseDepth: 0,
|
|
232
|
+
currentHoleId: null,
|
|
233
|
+
holeStack: [],
|
|
234
|
+
noDynamic: false,
|
|
235
|
+
hasOuterSuspenseOutsideSlot: false,
|
|
236
|
+
pendingEffects: null,
|
|
237
|
+
parentPendingEffects: null,
|
|
238
|
+
};
|
|
239
|
+
return pprStorage.run(nextStore, runClearedRuntimeHole);
|
|
240
|
+
}
|
|
241
|
+
|
|
157
242
|
export function createLayoutChildrenPlaceholder() {
|
|
158
243
|
const placeholder = {
|
|
159
244
|
$$typeof: Symbol.for("react.transitional.element"),
|
|
@@ -179,7 +264,9 @@ export function runInPageSegment(callback, storeOverride = null) {
|
|
|
179
264
|
const prev = pageSegmentStorage.getStore();
|
|
180
265
|
const store =
|
|
181
266
|
storeOverride || prev || { active: true, idCount: 0, holeCount: 0 };
|
|
182
|
-
return
|
|
267
|
+
return layoutSegmentStorage.run(null, () =>
|
|
268
|
+
pageSegmentStorage.run(store, callback)
|
|
269
|
+
);
|
|
183
270
|
}
|
|
184
271
|
|
|
185
272
|
export function getActivePageSegmentStore() {
|
|
@@ -194,7 +281,9 @@ export function runInLayoutSegment(callback, storeOverride = null) {
|
|
|
194
281
|
const prev = layoutSegmentStorage.getStore();
|
|
195
282
|
const store =
|
|
196
283
|
storeOverride || prev || { active: true, idCount: 0, holeCount: 0 };
|
|
197
|
-
return
|
|
284
|
+
return pageSegmentStorage.run(null, () =>
|
|
285
|
+
layoutSegmentStorage.run(store, callback)
|
|
286
|
+
);
|
|
198
287
|
}
|
|
199
288
|
|
|
200
289
|
export function getActiveLayoutSegmentStore() {
|
|
@@ -304,7 +393,7 @@ export function getPprHoleCounter() {
|
|
|
304
393
|
|
|
305
394
|
export function runInSuspense(callback, explicitHoleId = null) {
|
|
306
395
|
const store = getPprStore();
|
|
307
|
-
if (!store) {
|
|
396
|
+
if (!store || !store.isPpr) {
|
|
308
397
|
let holeId = explicitHoleId;
|
|
309
398
|
if (!holeId) {
|
|
310
399
|
const holeStore = getActiveRuntimeDynamicHoleStore();
|
|
@@ -488,8 +577,11 @@ export default {
|
|
|
488
577
|
isSlotDiscoveryActive,
|
|
489
578
|
markPageRootElement,
|
|
490
579
|
isPageRootElement,
|
|
580
|
+
getPageRootPpr,
|
|
491
581
|
markLayoutRootElement,
|
|
492
582
|
isLayoutRootElement,
|
|
583
|
+
getLayoutRootPpr,
|
|
584
|
+
runWithSegmentPpr,
|
|
493
585
|
createLayoutChildrenPlaceholder,
|
|
494
586
|
isLayoutChildrenPlaceholder,
|
|
495
587
|
runInPageSegment,
|