@solidjs/start 2.0.0-alpha.0 → 2.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/client/mount.d.ts +1 -7
- package/dist/client/mount.js +1 -99
- package/dist/config/constants.js +2 -2
- package/dist/config/dev-server.js +10 -0
- package/dist/config/fs-router.js +10 -22
- package/dist/config/fs-routes/fs-watcher.js +4 -4
- package/dist/config/fs-routes/index.js +4 -6
- package/dist/config/fs-routes/router.js +10 -11
- package/dist/config/fs-routes/tree-shake.js +12 -21
- package/dist/config/index.js +42 -42
- package/dist/config/lazy.js +42 -12
- package/dist/config/manifest.js +4 -3
- package/dist/config/vite-utils.d.ts +5 -0
- package/dist/config/vite-utils.js +7 -3
- package/dist/http/index.d.ts +1 -4
- package/dist/http/index.js +3 -5
- package/dist/index.d.ts +0 -1
- package/dist/middleware/index.d.ts +5 -2
- package/dist/middleware/index.js +6 -1
- package/dist/router.jsx +2 -2
- package/dist/server/StartServer.jsx +2 -0
- package/dist/server/assets/PatchVirtualDevStyles.d.ts +4 -0
- package/dist/server/assets/PatchVirtualDevStyles.jsx +28 -0
- package/dist/server/assets/index.js +1 -1
- package/dist/server/assets/render.jsx +2 -2
- package/dist/server/collect-styles.js +9 -21
- package/dist/server/fetchEvent.spec.js +1 -1
- package/dist/server/handler.js +30 -15
- package/dist/server/index.d.ts +1 -0
- package/dist/server/manifest/dev-client-manifest.js +1 -1
- package/dist/server/manifest/dev-ssr-manifest.js +1 -1
- package/dist/server/manifest/prod-ssr-manifest.js +7 -12
- package/dist/server/routes.js +3 -3
- package/dist/server/server-fns-runtime.js +2 -2
- package/dist/server/server-functions-handler.js +6 -11
- package/dist/server/server-runtime.js +8 -8
- package/dist/server/spa/StartServer.jsx +2 -0
- package/dist/shared/dev-overlay/CodeView.d.ts +1 -1
- package/dist/shared/dev-overlay/CodeView.jsx +23 -34
- package/dist/shared/dev-overlay/DevOverlayDialog.jsx +4 -4
- package/dist/shared/dev-overlay/get-source-map.d.ts +1 -1
- package/dist/shared/dev-overlay/get-source-map.js +5 -5
- package/dist/shared/dev-overlay/icons.d.ts +10 -10
- package/dist/shared/dev-overlay/icons.jsx +91 -91
- package/dist/shared/dev-overlay/index.jsx +1 -1
- package/dist/shared/lazy.js +4 -2
- package/env.d.ts +9 -0
- package/package.json +5 -4
- package/scripts/build.js +3 -3
- package/scripts/validate-imports.js +8 -8
- package/src/client/mount.ts +1 -114
- package/src/config/constants.ts +3 -3
- package/src/config/dev-server.ts +107 -99
- package/src/config/fs-router.ts +140 -155
- package/src/config/fs-routes/fs-watcher.ts +57 -61
- package/src/config/fs-routes/index.ts +117 -119
- package/src/config/fs-routes/router.ts +12 -13
- package/src/config/fs-routes/tree-shake.ts +342 -363
- package/src/config/index.ts +42 -43
- package/src/config/lazy.ts +47 -16
- package/src/config/manifest.ts +8 -7
- package/src/config/vite-utils.ts +9 -9
- package/src/env.d.ts +10 -28
- package/src/http/index.ts +105 -142
- package/src/index.tsx +0 -12
- package/src/internal.d.ts +1 -1
- package/src/middleware/index.ts +42 -49
- package/src/router.tsx +4 -3
- package/src/server/StartServer.tsx +3 -7
- package/src/server/assets/PatchVirtualDevStyles.tsx +31 -0
- package/src/server/assets/index.ts +1 -1
- package/src/server/assets/render.tsx +6 -2
- package/src/server/collect-styles.ts +49 -73
- package/src/server/fetchEvent.spec.ts +71 -75
- package/src/server/fetchEvent.ts +17 -17
- package/src/server/handler.ts +138 -129
- package/src/server/index.tsx +13 -0
- package/src/server/manifest/client-manifest.ts +1 -1
- package/src/server/manifest/dev-client-manifest.ts +7 -5
- package/src/server/manifest/dev-ssr-manifest.ts +8 -6
- package/src/server/manifest/prod-client-manifest.ts +7 -4
- package/src/server/manifest/prod-ssr-manifest.ts +78 -94
- package/src/server/manifest/ssr-manifest.ts +4 -2
- package/src/server/routes.ts +96 -108
- package/src/server/server-fns-runtime.ts +3 -3
- package/src/server/server-functions-handler.ts +294 -319
- package/src/server/server-runtime.ts +13 -13
- package/src/server/spa/StartServer.tsx +2 -0
- package/src/server/spa/handler.ts +12 -12
- package/src/server/types.ts +46 -46
- package/src/server/util.ts +4 -4
- package/src/shared/ErrorBoundary.tsx +1 -1
- package/src/shared/HttpHeader.tsx +20 -20
- package/src/shared/HttpStatusCode.ts +14 -14
- package/src/shared/clientOnly.ts +3 -3
- package/src/shared/dev-overlay/CodeView.tsx +43 -46
- package/src/shared/dev-overlay/DevOverlayDialog.tsx +4 -4
- package/src/shared/dev-overlay/createStackFrame.ts +59 -62
- package/src/shared/dev-overlay/env.d.ts +2 -2
- package/src/shared/dev-overlay/get-source-map.ts +5 -7
- package/src/shared/dev-overlay/icons.tsx +289 -121
- package/src/shared/dev-overlay/index.tsx +1 -1
- package/src/shared/lazy.ts +4 -3
- package/src/shared/serverFunction.ts +1 -1
- package/src/virtual.d.ts +10 -10
- package/tsconfig.json +2 -2
- package/vitest.config.ts +2 -2
package/dist/config/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { TanStackServerFnPlugin } from "@tanstack/server-functions-plugin";
|
|
2
2
|
import { defu } from "defu";
|
|
3
3
|
import { globSync } from "node:fs";
|
|
4
|
-
import { extname, isAbsolute, join
|
|
4
|
+
import { extname, isAbsolute, join } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { normalizePath } from "vite";
|
|
6
7
|
import solid from "vite-plugin-solid";
|
|
7
8
|
import { DEFAULT_EXTENSIONS, VIRTUAL_MODULES, VITE_ENVIRONMENTS } from "./constants.js";
|
|
8
9
|
import { devServer } from "./dev-server.js";
|
|
@@ -19,10 +20,10 @@ export function solidStart(options) {
|
|
|
19
20
|
ssr: true,
|
|
20
21
|
devOverlay: true,
|
|
21
22
|
experimental: {
|
|
22
|
-
islands: false
|
|
23
|
+
islands: false,
|
|
23
24
|
},
|
|
24
25
|
solid: {},
|
|
25
|
-
extensions: []
|
|
26
|
+
extensions: [],
|
|
26
27
|
});
|
|
27
28
|
const extensions = [...DEFAULT_EXTENSIONS, ...(start.extensions || [])];
|
|
28
29
|
const routeDir = join(start.appRoot, start.routeDir);
|
|
@@ -34,7 +35,7 @@ export function solidStart(options) {
|
|
|
34
35
|
const entryExtension = extname(appEntryPath);
|
|
35
36
|
const handlers = {
|
|
36
37
|
client: `${start.appRoot}/entry-client${entryExtension}`,
|
|
37
|
-
server: `${start.appRoot}/entry-server${entryExtension}
|
|
38
|
+
server: `${start.appRoot}/entry-server${entryExtension}`,
|
|
38
39
|
};
|
|
39
40
|
return [
|
|
40
41
|
{
|
|
@@ -42,13 +43,10 @@ export function solidStart(options) {
|
|
|
42
43
|
enforce: "pre",
|
|
43
44
|
configEnvironment(name) {
|
|
44
45
|
return {
|
|
45
|
-
define: {
|
|
46
|
-
"import.meta.env.SSR": JSON.stringify(name === VITE_ENVIRONMENTS.server)
|
|
47
|
-
},
|
|
48
46
|
resolve: {
|
|
49
47
|
// remove when https://github.com/solidjs/vite-plugin-solid/pull/228 is released
|
|
50
|
-
externalConditions: ["solid", "node"]
|
|
51
|
-
}
|
|
48
|
+
externalConditions: ["solid", "node"],
|
|
49
|
+
},
|
|
52
50
|
};
|
|
53
51
|
},
|
|
54
52
|
async config(_, env) {
|
|
@@ -79,9 +77,9 @@ export function solidStart(options) {
|
|
|
79
77
|
rollupOptions: {
|
|
80
78
|
input: clientInput,
|
|
81
79
|
treeshake: true,
|
|
82
|
-
preserveEntrySignatures: "exports-only"
|
|
83
|
-
}
|
|
84
|
-
}
|
|
80
|
+
preserveEntrySignatures: "exports-only",
|
|
81
|
+
},
|
|
82
|
+
},
|
|
85
83
|
},
|
|
86
84
|
[VITE_ENVIRONMENTS.server]: {
|
|
87
85
|
consumer: "server",
|
|
@@ -91,14 +89,14 @@ export function solidStart(options) {
|
|
|
91
89
|
manifest: true,
|
|
92
90
|
copyPublicDir: false,
|
|
93
91
|
rollupOptions: {
|
|
94
|
-
input: "~/entry-server.tsx"
|
|
92
|
+
input: "~/entry-server.tsx",
|
|
95
93
|
},
|
|
96
94
|
outDir: "dist/server",
|
|
97
95
|
commonjsOptions: {
|
|
98
|
-
include: [/node_modules/]
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
96
|
+
include: [/node_modules/],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
102
100
|
},
|
|
103
101
|
resolve: {
|
|
104
102
|
alias: {
|
|
@@ -107,17 +105,19 @@ export function solidStart(options) {
|
|
|
107
105
|
...(!start.ssr
|
|
108
106
|
? {
|
|
109
107
|
"@solidjs/start/server": "@solidjs/start/server/spa",
|
|
110
|
-
"@solidjs/start/client": "@solidjs/start/client/spa"
|
|
108
|
+
"@solidjs/start/client": "@solidjs/start/client/spa",
|
|
111
109
|
}
|
|
112
|
-
: {})
|
|
113
|
-
}
|
|
110
|
+
: {}),
|
|
111
|
+
},
|
|
114
112
|
},
|
|
115
113
|
define: {
|
|
116
114
|
"import.meta.env.MANIFEST": `globalThis.MANIFEST`,
|
|
117
115
|
"import.meta.env.START_SSR": JSON.stringify(start.ssr),
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
"import.meta.env.
|
|
116
|
+
// Use JSON.stringify so backslashes on Windows are escaped and
|
|
117
|
+
// esbuild receives a valid JS string literal for the define value
|
|
118
|
+
"import.meta.env.START_APP_ENTRY": JSON.stringify(appEntryPath),
|
|
119
|
+
"import.meta.env.START_CLIENT_ENTRY": JSON.stringify(handlers.client),
|
|
120
|
+
"import.meta.env.START_DEV_OVERLAY": JSON.stringify(start.devOverlay),
|
|
121
121
|
},
|
|
122
122
|
builder: {
|
|
123
123
|
sharedPlugins: true,
|
|
@@ -132,24 +132,24 @@ export function solidStart(options) {
|
|
|
132
132
|
await builder.build(client);
|
|
133
133
|
if (!server.isBuilt)
|
|
134
134
|
await builder.build(server);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
137
|
};
|
|
138
|
-
}
|
|
138
|
+
},
|
|
139
139
|
},
|
|
140
140
|
manifest(start),
|
|
141
141
|
fsRoutes({
|
|
142
142
|
routers: {
|
|
143
143
|
client: new SolidStartClientFileRouter({
|
|
144
144
|
dir: absolute(routeDir, root),
|
|
145
|
-
extensions
|
|
145
|
+
extensions,
|
|
146
146
|
}),
|
|
147
147
|
ssr: new SolidStartServerFileRouter({
|
|
148
148
|
dir: absolute(routeDir, root),
|
|
149
149
|
extensions,
|
|
150
|
-
dataOnly: !start.ssr
|
|
151
|
-
})
|
|
152
|
-
}
|
|
150
|
+
dataOnly: !start.ssr,
|
|
151
|
+
}),
|
|
152
|
+
},
|
|
153
153
|
}),
|
|
154
154
|
lazy(),
|
|
155
155
|
// Must be placed after fsRoutes, as treeShake will remove the
|
|
@@ -163,21 +163,21 @@ export function solidStart(options) {
|
|
|
163
163
|
{
|
|
164
164
|
envConsumer: "client",
|
|
165
165
|
envName: VITE_ENVIRONMENTS.client,
|
|
166
|
-
getRuntimeCode: () => `import { createServerReference } from "${
|
|
167
|
-
replacer: opts => `createServerReference('${opts.functionId}')
|
|
166
|
+
getRuntimeCode: () => `import { createServerReference } from "${normalizePath(fileURLToPath(new URL("../server/server-runtime", import.meta.url)))}"`,
|
|
167
|
+
replacer: opts => `createServerReference('${opts.functionId}')`,
|
|
168
168
|
},
|
|
169
169
|
{
|
|
170
170
|
envConsumer: "server",
|
|
171
171
|
envName: VITE_ENVIRONMENTS.server,
|
|
172
|
-
getRuntimeCode: () => `import { createServerReference } from '${
|
|
173
|
-
replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')
|
|
174
|
-
}
|
|
172
|
+
getRuntimeCode: () => `import { createServerReference } from '${normalizePath(fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)))}'`,
|
|
173
|
+
replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')`,
|
|
174
|
+
},
|
|
175
175
|
],
|
|
176
176
|
provider: {
|
|
177
177
|
envName: VITE_ENVIRONMENTS.server,
|
|
178
|
-
getRuntimeCode: () => `import { createServerReference } from '${
|
|
179
|
-
replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')
|
|
180
|
-
}
|
|
178
|
+
getRuntimeCode: () => `import { createServerReference } from '${normalizePath(fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)))}'`,
|
|
179
|
+
replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')`,
|
|
180
|
+
},
|
|
181
181
|
}),
|
|
182
182
|
{
|
|
183
183
|
name: "solid-start:virtual-modules",
|
|
@@ -198,20 +198,20 @@ export function solidStart(options) {
|
|
|
198
198
|
id += `?${query.toString()}`;
|
|
199
199
|
return id;
|
|
200
200
|
}
|
|
201
|
-
}
|
|
201
|
+
},
|
|
202
202
|
},
|
|
203
203
|
{
|
|
204
204
|
name: "solid-start:capture-client-bundle",
|
|
205
205
|
enforce: "post",
|
|
206
206
|
generateBundle(_options, bundle) {
|
|
207
207
|
globalThis.START_CLIENT_BUNDLE = bundle;
|
|
208
|
-
}
|
|
208
|
+
},
|
|
209
209
|
},
|
|
210
210
|
devServer(),
|
|
211
211
|
solid({
|
|
212
212
|
...start.solid,
|
|
213
213
|
ssr: true,
|
|
214
|
-
extensions: extensions.map(ext => `.${ext}`)
|
|
215
|
-
})
|
|
214
|
+
extensions: extensions.map(ext => `.${ext}`),
|
|
215
|
+
}),
|
|
216
216
|
];
|
|
217
217
|
}
|
package/dist/config/lazy.js
CHANGED
|
@@ -8,10 +8,10 @@ const idTransform = (id) => {
|
|
|
8
8
|
visitor: {
|
|
9
9
|
Program(path) {
|
|
10
10
|
path.node.body.unshift(t.exportNamedDeclaration(t.variableDeclaration("const", [
|
|
11
|
-
t.variableDeclarator(t.identifier("id$$"), t.stringLiteral(id))
|
|
11
|
+
t.variableDeclarator(t.identifier("id$$"), t.stringLiteral(id)),
|
|
12
12
|
])));
|
|
13
|
-
}
|
|
14
|
-
}
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
const importTransform = () => {
|
|
@@ -26,22 +26,51 @@ const importTransform = () => {
|
|
|
26
26
|
return;
|
|
27
27
|
subPath.remove();
|
|
28
28
|
path.insertAfter(t.importDeclaration([t.importSpecifier(t.identifier("lazy"), t.identifier("lazy"))], t.stringLiteral("@solidjs/start/server")));
|
|
29
|
-
}
|
|
29
|
+
},
|
|
30
30
|
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
const fileEndingRegex = /(ts|js)x(\?.*)?$/;
|
|
36
36
|
const lazy = () => {
|
|
37
37
|
const cwd = process.cwd().replaceAll(osSep, sep);
|
|
38
|
+
/**
|
|
39
|
+
* Maps module ids to their client-specific shared chunk names.
|
|
40
|
+
* Modules in shared chunks need to find their assets via the chunk name, instead of their module id.
|
|
41
|
+
*
|
|
42
|
+
* Vite includes assets of such modules in the manifest via the chunk name:
|
|
43
|
+
* https://github.com/vitejs/vite/blob/4be37a8389c67873880f826b01fe40137e1c29a7/packages/vite/src/node/plugins/manifest.ts#L179
|
|
44
|
+
* https://github.com/vitejs/vite/blob/4be37a8389c67873880f826b01fe40137e1c29a7/packages/vite/src/node/plugins/manifest.ts#L319
|
|
45
|
+
*
|
|
46
|
+
* Rollup occassionally creates shared chunks automatically,
|
|
47
|
+
* but they can also be manually created by the user via:
|
|
48
|
+
* https://rollupjs.org/configuration-options/#output-manualchunks
|
|
49
|
+
*
|
|
50
|
+
* More infos on Rollup's logic:
|
|
51
|
+
* https://github.com/rollup/rollup/issues/3772#issuecomment-689955168
|
|
52
|
+
*/
|
|
53
|
+
const sharedChunkNames = {};
|
|
38
54
|
return {
|
|
39
55
|
name: "solid-lazy-css",
|
|
40
56
|
enforce: "pre",
|
|
41
|
-
|
|
42
|
-
|
|
57
|
+
generateBundle(_, bundle) {
|
|
58
|
+
if (this.environment.name !== VITE_ENVIRONMENTS.client)
|
|
59
|
+
return;
|
|
60
|
+
for (const chunk of Object.values(bundle)) {
|
|
61
|
+
if (chunk.type !== "chunk" || !chunk.isDynamicEntry || chunk.facadeModuleId)
|
|
62
|
+
continue;
|
|
63
|
+
// Has to follow Vites implementation:
|
|
64
|
+
// https://github.com/vitejs/vite/blob/4be37a8389c67873880f826b01fe40137e1c29a7/packages/vite/src/node/plugins/manifest.ts#L179
|
|
65
|
+
const chunkName = `_${basename(chunk.fileName)}`;
|
|
66
|
+
for (const id of chunk.moduleIds) {
|
|
67
|
+
sharedChunkNames[id] = chunkName;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
43
70
|
},
|
|
44
71
|
async transform(src, id) {
|
|
72
|
+
if (this.environment.name !== VITE_ENVIRONMENTS.server)
|
|
73
|
+
return;
|
|
45
74
|
if (!id.match(fileEndingRegex))
|
|
46
75
|
return;
|
|
47
76
|
// The transformed files either import "lazy" or css files
|
|
@@ -52,7 +81,8 @@ const lazy = () => {
|
|
|
52
81
|
const hasDefaultExport = src.indexOf("export default") !== -1;
|
|
53
82
|
if (hasDefaultExport) {
|
|
54
83
|
const localId = relative(cwd, id);
|
|
55
|
-
|
|
84
|
+
const chunkName = sharedChunkNames[id];
|
|
85
|
+
plugins.push(idTransform(chunkName ?? localId));
|
|
56
86
|
}
|
|
57
87
|
const hasLazy = src.indexOf("lazy(") !== -1;
|
|
58
88
|
if (hasLazy)
|
|
@@ -63,20 +93,20 @@ const lazy = () => {
|
|
|
63
93
|
const transformed = await babel.transformAsync(src, {
|
|
64
94
|
plugins,
|
|
65
95
|
parserOpts: {
|
|
66
|
-
plugins: ["jsx", "typescript"]
|
|
96
|
+
plugins: ["jsx", "typescript"],
|
|
67
97
|
},
|
|
68
98
|
filename: basename(id),
|
|
69
99
|
ast: false,
|
|
70
100
|
sourceMaps: true,
|
|
71
101
|
configFile: false,
|
|
72
102
|
babelrc: false,
|
|
73
|
-
sourceFileName: id
|
|
103
|
+
sourceFileName: id,
|
|
74
104
|
});
|
|
75
105
|
if (!transformed?.code)
|
|
76
106
|
return;
|
|
77
107
|
const { code, map } = transformed;
|
|
78
108
|
return { code, map };
|
|
79
|
-
}
|
|
109
|
+
},
|
|
80
110
|
};
|
|
81
111
|
};
|
|
82
112
|
export default lazy;
|
package/dist/config/manifest.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { findStylesInModuleGraph } from "../server/collect-styles.js";
|
|
2
2
|
import { VIRTUAL_MODULES } from "./constants.js";
|
|
3
|
+
import { wrapId } from "./vite-utils.js";
|
|
3
4
|
export function manifest(start) {
|
|
4
5
|
let devServer = undefined;
|
|
5
6
|
return {
|
|
@@ -61,14 +62,14 @@ export function manifest(start) {
|
|
|
61
62
|
tag: "style",
|
|
62
63
|
attrs: {
|
|
63
64
|
type: "text/css",
|
|
64
|
-
"data-vite-dev-id": "${key}",
|
|
65
|
+
"data-vite-dev-id": "${wrapId(key)}",
|
|
65
66
|
"data-vite-ref": "0",
|
|
66
67
|
},
|
|
67
|
-
children: () => import("${value}?inline").then(mod => mod.default),
|
|
68
|
+
children: () => import("${wrapId(value)}?inline").then(mod => mod.default),
|
|
68
69
|
}`);
|
|
69
70
|
return `export default [${cssAssets.join(",")}]`;
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
|
-
}
|
|
73
|
+
},
|
|
73
74
|
};
|
|
74
75
|
}
|
|
@@ -4,6 +4,11 @@ export declare const FS_PREFIX = "/@fs/";
|
|
|
4
4
|
export declare const VALID_ID_PREFIX = "/@id/";
|
|
5
5
|
export declare const NULL_BYTE_PLACEHOLDER = "__x00__";
|
|
6
6
|
export declare function normalizeResolvedIdToUrl(environment: DevEnvironment, url: string, resolved: Rollup.PartialResolvedId): string;
|
|
7
|
+
/**
|
|
8
|
+
* Inspired by:
|
|
9
|
+
* https://github.com/withastro/astro/blob/fddde5fad81007795eb263c7fd0cea096b8e2cba/packages/astro/src/core/util.ts#L115
|
|
10
|
+
* https://github.com/vitejs/vite/blob/130e7181a55c524383c63bbfb1749d0ff7185cad/packages/vite/src/shared/utils.ts#L11
|
|
11
|
+
*/
|
|
7
12
|
export declare function wrapId(id: string): string;
|
|
8
13
|
export declare function unwrapId(id: string): string;
|
|
9
14
|
export declare function normalizeViteImportAnalysisUrl(environment: DevEnvironment, id: string): string;
|
|
@@ -7,6 +7,7 @@ export function cleanUrl(url) {
|
|
|
7
7
|
export const FS_PREFIX = `/@fs/`;
|
|
8
8
|
export const VALID_ID_PREFIX = `/@id/`;
|
|
9
9
|
export const NULL_BYTE_PLACEHOLDER = `__x00__`;
|
|
10
|
+
const NULL_BYTE_REGEX = /^\0/;
|
|
10
11
|
export function normalizeResolvedIdToUrl(environment, url, resolved) {
|
|
11
12
|
const root = environment.config.root;
|
|
12
13
|
const depsOptimizer = environment.depsOptimizer;
|
|
@@ -38,10 +39,13 @@ export function normalizeResolvedIdToUrl(environment, url, resolved) {
|
|
|
38
39
|
}
|
|
39
40
|
return url;
|
|
40
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Inspired by:
|
|
44
|
+
* https://github.com/withastro/astro/blob/fddde5fad81007795eb263c7fd0cea096b8e2cba/packages/astro/src/core/util.ts#L115
|
|
45
|
+
* https://github.com/vitejs/vite/blob/130e7181a55c524383c63bbfb1749d0ff7185cad/packages/vite/src/shared/utils.ts#L11
|
|
46
|
+
*/
|
|
41
47
|
export function wrapId(id) {
|
|
42
|
-
return id.
|
|
43
|
-
? id
|
|
44
|
-
: VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);
|
|
48
|
+
return id.replace(NULL_BYTE_REGEX, `${VALID_ID_PREFIX}${NULL_BYTE_PLACEHOLDER}`);
|
|
45
49
|
}
|
|
46
50
|
export function unwrapId(id) {
|
|
47
51
|
return id.startsWith(VALID_ID_PREFIX)
|
package/dist/http/index.d.ts
CHANGED
|
@@ -9,10 +9,7 @@ export declare function isEvent(obj: any): obj is h3.H3Event | {
|
|
|
9
9
|
};
|
|
10
10
|
type Tail<T> = T extends [any, ...infer U] ? U : never;
|
|
11
11
|
type PrependOverload<TOriginal extends (...args: Array<any>) => any, TOverload extends (...args: Array<any>) => any> = TOverload & TOriginal;
|
|
12
|
-
type WrapFunction<TFn extends (...args: Array<any>) => any> = PrependOverload<TFn, (...args: Parameters<TFn> extends [
|
|
13
|
-
h3.HTTPEvent<any> | h3.H3Event<any>,
|
|
14
|
-
...infer TArgs
|
|
15
|
-
] ? TArgs : Parameters<TFn>) => ReturnType<TFn>>;
|
|
12
|
+
type WrapFunction<TFn extends (...args: Array<any>) => any> = PrependOverload<TFn, (...args: Parameters<TFn> extends [h3.HTTPEvent<any> | h3.H3Event<any>, ...infer TArgs] ? TArgs : Parameters<TFn>) => ReturnType<TFn>>;
|
|
16
13
|
type WrappedReadBody = <T, TEventInput = InferEventInput<"body", H3Event, T>>(...args: Tail<Parameters<typeof h3.readBody<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.readBody<T, h3.H3Event, TEventInput>>;
|
|
17
14
|
export declare const readBody: PrependOverload<typeof h3.readBody, WrappedReadBody>;
|
|
18
15
|
type WrappedGetQuery = <T, TEventInput = Exclude<InferEventInput<"query", H3Event, T>, undefined>>(...args: Tail<Parameters<typeof h3.getQuery<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getQuery<T, H3Event, TEventInput>>;
|
package/dist/http/index.js
CHANGED
|
@@ -28,9 +28,7 @@ function createWrapperFunction(h3Function) {
|
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
30
|
args[0] =
|
|
31
|
-
event instanceof h3.H3Event || event.__is_event__
|
|
32
|
-
? event
|
|
33
|
-
: event[HTTPEventSymbol];
|
|
31
|
+
event instanceof h3.H3Event || event.__is_event__ ? event : event[HTTPEventSymbol];
|
|
34
32
|
}
|
|
35
33
|
return h3Function(...args);
|
|
36
34
|
});
|
|
@@ -69,7 +67,7 @@ export const setResponseHeaders = (values) => {
|
|
|
69
67
|
};
|
|
70
68
|
export const setResponseHeader = (name, value) => {
|
|
71
69
|
const headers = getEvent().res.headers;
|
|
72
|
-
(Array.isArray(value) ? value : [value]).forEach(
|
|
70
|
+
(Array.isArray(value) ? value : [value]).forEach(value => {
|
|
73
71
|
headers.set(name, value);
|
|
74
72
|
});
|
|
75
73
|
};
|
|
@@ -81,7 +79,7 @@ export const appendResponseHeaders = (values) => {
|
|
|
81
79
|
};
|
|
82
80
|
export const appendResponseHeader = (name, value) => {
|
|
83
81
|
const headers = getEvent().res.headers;
|
|
84
|
-
(Array.isArray(value) ? value : [value]).forEach(
|
|
82
|
+
(Array.isArray(value) ? value : [value]).forEach(value => {
|
|
85
83
|
headers.append(name, value);
|
|
86
84
|
});
|
|
87
85
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type { APIEvent, APIHandler, Asset, ContextMatches, DocumentComponentProps, FetchEvent, HandlerOptions, PageEvent, ResponseStub, ServerFunctionMeta } from "./server/types.ts";
|
|
2
1
|
export { default as clientOnly } from "./shared/clientOnly.ts";
|
|
3
2
|
export { GET } from "./shared/GET.ts";
|
|
4
3
|
export { HttpHeader } from "./shared/HttpHeader.tsx";
|
|
@@ -9,10 +9,13 @@ type ResponseMiddlewareResponseParam = {
|
|
|
9
9
|
body?: Awaited<EventHandlerResponse>;
|
|
10
10
|
};
|
|
11
11
|
export type ResponseMiddleware = (event: FetchEvent, response: ResponseMiddlewareResponseParam) => Response | Promise<Response> | void | Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Creates middleware for handling requests and responses.
|
|
14
|
+
*
|
|
15
|
+
* @see https://docs.solidjs.com/solid-start/reference/server/create-middleware
|
|
16
|
+
*/
|
|
12
17
|
export declare function createMiddleware(args: {
|
|
13
|
-
/** @deprecated Use H3 `Middleware` */
|
|
14
18
|
onRequest?: RequestMiddleware | RequestMiddleware[] | undefined;
|
|
15
|
-
/** @deprecated Use H3 `Middleware` */
|
|
16
19
|
onBeforeResponse?: ResponseMiddleware | ResponseMiddleware[] | undefined;
|
|
17
20
|
} | Middleware[]): Middleware[];
|
|
18
21
|
export {};
|
package/dist/middleware/index.js
CHANGED
|
@@ -13,12 +13,17 @@ function wrapResponseMiddleware(onBeforeResponse) {
|
|
|
13
13
|
const resp = await next();
|
|
14
14
|
const fetchEvent = getFetchEvent(h3Event);
|
|
15
15
|
const mwResponse = await onBeforeResponse(fetchEvent, {
|
|
16
|
-
body: resp
|
|
16
|
+
body: resp,
|
|
17
17
|
});
|
|
18
18
|
if (mwResponse)
|
|
19
19
|
return mwResponse;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates middleware for handling requests and responses.
|
|
24
|
+
*
|
|
25
|
+
* @see https://docs.solidjs.com/solid-start/reference/server/create-middleware
|
|
26
|
+
*/
|
|
22
27
|
export function createMiddleware(args) {
|
|
23
28
|
if (Array.isArray(args))
|
|
24
29
|
return args;
|
package/dist/router.jsx
CHANGED
|
@@ -10,10 +10,10 @@ export function createRoutes() {
|
|
|
10
10
|
...(route.$$route ? route.$$route.require().route : undefined),
|
|
11
11
|
info: {
|
|
12
12
|
...(route.$$route ? route.$$route.require().route.info : {}),
|
|
13
|
-
filesystem: true
|
|
13
|
+
filesystem: true,
|
|
14
14
|
},
|
|
15
15
|
component,
|
|
16
|
-
children: route.children ? route.children.map(createRoute) : undefined
|
|
16
|
+
children: route.children ? route.children.map(createRoute) : undefined,
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
const routes = routeConfigs.map(createRoute);
|
|
@@ -2,6 +2,7 @@ import { Hydration, HydrationScript, NoHydration, getRequestEvent, ssr } from "s
|
|
|
2
2
|
import App from "solid-start:app";
|
|
3
3
|
import { ErrorBoundary, TopErrorBoundary } from "../shared/ErrorBoundary.jsx";
|
|
4
4
|
import { useAssets } from "./assets/index.js";
|
|
5
|
+
import PatchVirtualDevStyles from "./assets/PatchVirtualDevStyles.jsx";
|
|
5
6
|
import { getSsrManifest } from "./manifest/ssr-manifest.js";
|
|
6
7
|
const docType = ssr("<!DOCTYPE html>");
|
|
7
8
|
/**
|
|
@@ -17,6 +18,7 @@ export function StartServer(props) {
|
|
|
17
18
|
{docType}
|
|
18
19
|
<TopErrorBoundary>
|
|
19
20
|
<props.document assets={<HydrationScript />} scripts={<>
|
|
21
|
+
<PatchVirtualDevStyles nonce={nonce}/>
|
|
20
22
|
<script type="module" nonce={nonce} async src={getSsrManifest("client").path(import.meta.env.START_CLIENT_ENTRY)}/>
|
|
21
23
|
</>}>
|
|
22
24
|
{!import.meta.env.START_ISLANDS ? (<Hydration>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Patches the data-vite-dev-id attribute for style tags of virtual modules
|
|
3
|
+
*
|
|
4
|
+
* Per Vite's convention, virtual module ids are prefixed with \0 (null byte):
|
|
5
|
+
* https://vite.dev/guide/api-plugin#virtual-modules-convention
|
|
6
|
+
*
|
|
7
|
+
* However this null byte cannot be server rendered properly.
|
|
8
|
+
* Vite client runtime then fails to find style's with wrong null bytes,
|
|
9
|
+
* and instead inserts duplicate style's.
|
|
10
|
+
*
|
|
11
|
+
* This patch replaces the serializable /@id/__x00__ with the proper null byte,
|
|
12
|
+
* and has to run before Vite's client runtime:
|
|
13
|
+
* https://github.com/vitejs/vite/blob/130e7181a55c524383c63bbfb1749d0ff7185cad/packages/vite/src/client/client.ts#L529
|
|
14
|
+
*
|
|
15
|
+
* TODO: This should be solved in Vite directly!
|
|
16
|
+
*/
|
|
17
|
+
const patch = function () {
|
|
18
|
+
document.querySelectorAll("style[data-vite-dev-id]").forEach(function (el) {
|
|
19
|
+
el.setAttribute("data-vite-dev-id", el.dataset.viteDevId.replace("/@id/__x00__", "\0"));
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const serializedPatch = `(${patch.toString()})();`;
|
|
23
|
+
const PatchVirtualDevStyles = (props) => {
|
|
24
|
+
if (!import.meta.env.PROD) {
|
|
25
|
+
return <script nonce={props.nonce} innerHTML={serializedPatch}/>;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export default PatchVirtualDevStyles;
|
|
@@ -6,9 +6,9 @@ const assetMap = {
|
|
|
6
6
|
{" "}
|
|
7
7
|
</script>) : null;
|
|
8
8
|
},
|
|
9
|
-
noscript: (props) => (<noscript {...props.attrs}>{props.children}</noscript>)
|
|
9
|
+
noscript: (props) => (<noscript {...props.attrs}>{props.children}</noscript>),
|
|
10
10
|
};
|
|
11
11
|
export function renderAsset(asset, nonce) {
|
|
12
|
-
let { tag, attrs: { key, ...attrs } = { key: undefined }, children } = asset;
|
|
12
|
+
let { tag, attrs: { key, ...attrs } = { key: undefined }, children, } = asset;
|
|
13
13
|
return assetMap[tag]({ attrs: { ...attrs, nonce }, key, children });
|
|
14
14
|
}
|
|
@@ -1,28 +1,16 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (!node) {
|
|
7
|
-
const resolvedId = await vite.pluginContainer.resolveId(file, undefined);
|
|
8
|
-
if (!resolvedId)
|
|
2
|
+
async function getViteModuleNode(vite, file, importer) {
|
|
3
|
+
try {
|
|
4
|
+
const res = await vite.fetchModule(file, importer);
|
|
5
|
+
if (!("id" in res))
|
|
9
6
|
return;
|
|
10
|
-
|
|
11
|
-
node = vite.moduleGraph.getModuleById(file);
|
|
12
|
-
}
|
|
13
|
-
if (!node) {
|
|
14
|
-
nodePath = resolve(nodePath);
|
|
15
|
-
node = await vite.moduleGraph.getModuleByUrl(file);
|
|
16
|
-
}
|
|
17
|
-
if (!node) {
|
|
18
|
-
await vite.moduleGraph.ensureEntryFromUrl(nodePath, false);
|
|
19
|
-
node = vite.moduleGraph.getModuleById(nodePath);
|
|
7
|
+
return vite.moduleGraph.getModuleById(res.id);
|
|
20
8
|
}
|
|
21
|
-
|
|
9
|
+
catch (err) { }
|
|
22
10
|
}
|
|
23
|
-
async function findModuleDependencies(vite, file, deps, crawledFiles = new Set()) {
|
|
11
|
+
async function findModuleDependencies(vite, file, deps, crawledFiles = new Set(), importer) {
|
|
24
12
|
crawledFiles.add(file);
|
|
25
|
-
const module = await getViteModuleNode(vite, file);
|
|
13
|
+
const module = await getViteModuleNode(vite, file, importer);
|
|
26
14
|
if (!module?.id || deps.has(module))
|
|
27
15
|
return;
|
|
28
16
|
deps.add(module);
|
|
@@ -40,7 +28,7 @@ async function findModuleDependencies(vite, file, deps, crawledFiles = new Set()
|
|
|
40
28
|
if (crawledFiles.has(dep)) {
|
|
41
29
|
continue;
|
|
42
30
|
}
|
|
43
|
-
await findModuleDependencies(vite, dep, deps, crawledFiles);
|
|
31
|
+
await findModuleDependencies(vite, dep, deps, crawledFiles, module.id);
|
|
44
32
|
}
|
|
45
33
|
}
|
|
46
34
|
// Vite doesn't expose these so we just copy the list for now
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as h3 from "h3";
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { createFetchEvent, getFetchEvent, mergeResponseHeaders
|
|
3
|
+
import { createFetchEvent, getFetchEvent, mergeResponseHeaders } from "./fetchEvent.js";
|
|
4
4
|
vi.mock(import("h3"), async (mod) => {
|
|
5
5
|
return {
|
|
6
6
|
...(await mod()),
|