@decocms/start 0.27.2 → 0.28.0
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/package.json +7 -4
- package/src/hooks/DecoPageRenderer.tsx +4 -1
- package/src/vite/plugin.ts +95 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/start",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deco framework for TanStack Start - CMS bridge, admin protocol, hooks, schema generation",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"./routes": "./src/routes/index.ts",
|
|
43
43
|
"./scripts/generate-blocks": "./scripts/generate-blocks.ts",
|
|
44
44
|
"./scripts/generate-schema": "./scripts/generate-schema.ts",
|
|
45
|
-
"./scripts/generate-invoke": "./scripts/generate-invoke.ts"
|
|
45
|
+
"./scripts/generate-invoke": "./scripts/generate-invoke.ts",
|
|
46
|
+
"./vite": "./src/vite/plugin.ts"
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
49
|
"build": "tsc",
|
|
@@ -74,7 +75,8 @@
|
|
|
74
75
|
"@tanstack/react-start": ">=1.0.0",
|
|
75
76
|
"@tanstack/store": ">=0.7.0",
|
|
76
77
|
"react": "^19.0.0",
|
|
77
|
-
"react-dom": "^19.0.0"
|
|
78
|
+
"react-dom": "^19.0.0",
|
|
79
|
+
"vite": ">=6.0.0 || >=7.0.0 || >=8.0.0"
|
|
78
80
|
},
|
|
79
81
|
"devDependencies": {
|
|
80
82
|
"@biomejs/biome": "^2.4.6",
|
|
@@ -85,6 +87,7 @@
|
|
|
85
87
|
"@types/react-dom": "^19.0.0",
|
|
86
88
|
"knip": "^5.86.0",
|
|
87
89
|
"ts-morph": "^27.0.0",
|
|
88
|
-
"typescript": "^5.9.0"
|
|
90
|
+
"typescript": "^5.9.0",
|
|
91
|
+
"vite": ">=6.0.0"
|
|
89
92
|
}
|
|
90
93
|
}
|
|
@@ -240,8 +240,11 @@ function DeferredSectionWrapper({
|
|
|
240
240
|
getSectionOptions(deferred.component),
|
|
241
241
|
);
|
|
242
242
|
const isSSR = typeof document === "undefined";
|
|
243
|
+
// Allow SSR to render the loadingFallback when registered sync via
|
|
244
|
+
// registerSection(). Previous `isSSR ? false` always returned null,
|
|
245
|
+
// hiding the skeleton from the HTML stream.
|
|
243
246
|
const [optionsReady, setOptionsReady] = useState(() =>
|
|
244
|
-
|
|
247
|
+
!!getSectionOptions(deferred.component),
|
|
245
248
|
);
|
|
246
249
|
const ref = useRef<HTMLDivElement>(null);
|
|
247
250
|
const triggered = useRef(false);
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deco Vite plugin — server-only stubs for TanStack Start storefronts.
|
|
3
|
+
*
|
|
4
|
+
* Replaces server-only modules with lightweight client stubs so they
|
|
5
|
+
* are eliminated from the browser bundle. This consolidates stubs that
|
|
6
|
+
* every Deco site previously had to copy into its own vite.config.ts.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { decoVitePlugin } from "@decocms/start/vite";
|
|
11
|
+
* export default defineConfig({ plugins: [decoVitePlugin(), ...] });
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { Plugin, PluginOption } from "vite";
|
|
16
|
+
|
|
17
|
+
// Bare-specifier stubs resolved by ID before Vite touches them.
|
|
18
|
+
const CLIENT_STUBS: Record<string, string> = {
|
|
19
|
+
"react-dom/server": "\0stub:react-dom-server",
|
|
20
|
+
"react-dom/server.browser": "\0stub:react-dom-server",
|
|
21
|
+
"node:stream": "\0stub:node-stream",
|
|
22
|
+
"node:stream/web": "\0stub:node-stream-web",
|
|
23
|
+
"node:async_hooks": "\0stub:node-async-hooks",
|
|
24
|
+
"tanstack-start-injected-head-scripts:v": "\0stub:tanstack-head-scripts",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Minimal stub source for each virtual module.
|
|
28
|
+
const STUB_SOURCE: Record<string, string> = {
|
|
29
|
+
"\0stub:react-dom-server": [
|
|
30
|
+
"const noop = () => '';",
|
|
31
|
+
"export const renderToString = noop;",
|
|
32
|
+
"export const renderToStaticMarkup = noop;",
|
|
33
|
+
"export const renderToReadableStream = noop;",
|
|
34
|
+
"export const resume = noop;",
|
|
35
|
+
"export const version = '19.0.0';",
|
|
36
|
+
"export default { renderToString: noop, renderToStaticMarkup: noop, renderToReadableStream: noop, resume: noop, version: '19.0.0' };",
|
|
37
|
+
].join("\n"),
|
|
38
|
+
|
|
39
|
+
"\0stub:node-stream":
|
|
40
|
+
"export class PassThrough {}; export class Readable {}; export class Writable {}; export default { PassThrough, Readable, Writable };",
|
|
41
|
+
|
|
42
|
+
"\0stub:node-stream-web":
|
|
43
|
+
"export const ReadableStream = globalThis.ReadableStream; export const WritableStream = globalThis.WritableStream; export const TransformStream = globalThis.TransformStream; export default { ReadableStream, WritableStream, TransformStream };",
|
|
44
|
+
|
|
45
|
+
"\0stub:node-async-hooks": [
|
|
46
|
+
"class _ALS { getStore() { return undefined; } run(_store, fn, ...args) { return fn(...args); } enterWith() {} disable() {} }",
|
|
47
|
+
"export const AsyncLocalStorage = _ALS;",
|
|
48
|
+
"export const AsyncResource = class {};",
|
|
49
|
+
"export function executionAsyncId() { return 0; }",
|
|
50
|
+
"export function createHook() { return { enable() {}, disable() {} }; }",
|
|
51
|
+
"export default { AsyncLocalStorage: _ALS, AsyncResource, executionAsyncId, createHook };",
|
|
52
|
+
].join("\n"),
|
|
53
|
+
|
|
54
|
+
"\0stub:tanstack-head-scripts":
|
|
55
|
+
"export const injectedHeadScripts = undefined;",
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export function decoVitePlugin(): PluginOption {
|
|
59
|
+
const plugin: Plugin = {
|
|
60
|
+
name: "deco-server-only-stubs",
|
|
61
|
+
enforce: "pre",
|
|
62
|
+
|
|
63
|
+
resolveId(id, _importer, options) {
|
|
64
|
+
// Server builds keep the real modules.
|
|
65
|
+
if (options?.ssr) return undefined;
|
|
66
|
+
return CLIENT_STUBS[id];
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
load(id, options) {
|
|
70
|
+
// ------------------------------------------------------------------
|
|
71
|
+
// blocks.gen.ts — the CMS block registry (often 500KB+ compiled).
|
|
72
|
+
// Only the server needs it; the client receives pre-resolved sections.
|
|
73
|
+
// Match on resolved file path (relative imports resolve to absolute).
|
|
74
|
+
// ------------------------------------------------------------------
|
|
75
|
+
if (!options?.ssr && id.endsWith("blocks.gen.ts")) {
|
|
76
|
+
return "export const blocks = {};";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Virtual module stubs.
|
|
80
|
+
return STUB_SOURCE[id];
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
configEnvironment(name: string, env: any) {
|
|
84
|
+
if (name === "ssr" || name === "client") {
|
|
85
|
+
env.optimizeDeps = env.optimizeDeps || {};
|
|
86
|
+
env.optimizeDeps.esbuildOptions =
|
|
87
|
+
env.optimizeDeps.esbuildOptions || {};
|
|
88
|
+
env.optimizeDeps.esbuildOptions.jsx = "automatic";
|
|
89
|
+
env.optimizeDeps.esbuildOptions.jsxImportSource = "react";
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return plugin;
|
|
95
|
+
}
|