@solidjs/start 1.0.8 → 1.0.10
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/config/fs-router.js +8 -1
- package/dist/middleware/index.d.ts +2 -2
- package/dist/router/routes.d.ts +1 -0
- package/dist/router/routes.js +2 -2
- package/dist/runtime/server-handler.js +20 -19
- package/dist/runtime/server-runtime.js +3 -3
- package/dist/server/handler.js +1 -1
- package/dist/server/pageEvent.js +23 -14
- package/dist/shared/clientOnly.d.ts +3 -1
- package/dist/shared/clientOnly.jsx +6 -2
- package/dist/shared/dev-overlay/DevOverlayDialog.jsx +14 -6
- package/dist/shared/dev-overlay/index.jsx +2 -2
- package/package.json +3 -3
package/config/fs-router.js
CHANGED
|
@@ -58,7 +58,7 @@ export class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const HTTP_METHODS = ["GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
61
|
+
const HTTP_METHODS = ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
62
62
|
function createHTTPHandlers(src, exports) {
|
|
63
63
|
const handlers = {};
|
|
64
64
|
for (const exp of exports) {
|
|
@@ -67,8 +67,15 @@ function createHTTPHandlers(src, exports) {
|
|
|
67
67
|
src: src,
|
|
68
68
|
pick: [exp.n]
|
|
69
69
|
};
|
|
70
|
+
if (exp.n === "GET" && !exports.find(exp => exp.n === "HEAD")) {
|
|
71
|
+
handlers.$HEAD = {
|
|
72
|
+
src: src,
|
|
73
|
+
pick: [exp.n]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
70
76
|
}
|
|
71
77
|
}
|
|
78
|
+
|
|
72
79
|
return handlers;
|
|
73
80
|
}
|
|
74
81
|
|
|
@@ -12,7 +12,7 @@ export declare function createMiddleware({ onRequest, onBeforeResponse }: {
|
|
|
12
12
|
onRequest?: RequestMiddleware | RequestMiddleware[] | undefined;
|
|
13
13
|
onBeforeResponse?: ResponseMiddleware | ResponseMiddleware[] | undefined;
|
|
14
14
|
}): {
|
|
15
|
-
onRequest?: import("h3")._RequestMiddleware
|
|
16
|
-
onBeforeResponse?: import("h3")._ResponseMiddleware
|
|
15
|
+
onRequest?: import("h3")._RequestMiddleware | import("h3")._RequestMiddleware[] | undefined;
|
|
16
|
+
onBeforeResponse?: import("h3")._ResponseMiddleware | import("h3")._ResponseMiddleware[] | undefined;
|
|
17
17
|
};
|
|
18
18
|
export {};
|
package/dist/router/routes.d.ts
CHANGED
package/dist/router/routes.js
CHANGED
|
@@ -22,7 +22,7 @@ function defineRoutes(fileRoutes) {
|
|
|
22
22
|
export function matchAPIRoute(path, method) {
|
|
23
23
|
const match = router.lookup(path);
|
|
24
24
|
if (match && match.route) {
|
|
25
|
-
const handler = match.route[`$${method}`];
|
|
25
|
+
const handler = method === "HEAD" ? match.route["$HEAD"] || match.route["$GET"] : match.route[`$${method}`];
|
|
26
26
|
if (handler === undefined)
|
|
27
27
|
return;
|
|
28
28
|
return {
|
|
@@ -32,7 +32,7 @@ export function matchAPIRoute(path, method) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
function containsHTTP(route) {
|
|
35
|
-
return route["$GET"] || route["$POST"] || route["$PUT"] || route["$PATCH"] || route["$DELETE"];
|
|
35
|
+
return route["$HEAD"] || route["$GET"] || route["$POST"] || route["$PUT"] || route["$PATCH"] || route["$DELETE"];
|
|
36
36
|
}
|
|
37
37
|
const router = createRouter({
|
|
38
38
|
routes: fileRoutes.reduce((memo, route) => {
|
|
@@ -207,28 +207,29 @@ async function handleServerFunction(h3Event) {
|
|
|
207
207
|
function handleNoJS(result, request, parsed, thrown) {
|
|
208
208
|
const url = new URL(request.url);
|
|
209
209
|
const isError = result instanceof Error;
|
|
210
|
-
let redirectUrl = new URL(request.headers.get("referer")).toString();
|
|
211
210
|
let statusCode = 302;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
211
|
+
let headers;
|
|
212
|
+
if (result instanceof Response) {
|
|
213
|
+
headers = new Headers(result.headers);
|
|
214
|
+
if (result.headers.has("Location")) {
|
|
215
|
+
headers.set(`Location`, new URL(result.headers.get("Location"), url.origin + import.meta.env.SERVER_BASE_URL).toString());
|
|
216
|
+
statusCode = getExpectedRedirectStatus(result);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else
|
|
220
|
+
headers = new Headers({ Location: new URL(request.headers.get("referer")).toString() });
|
|
221
|
+
if (result) {
|
|
222
|
+
headers.append("Set-Cookie", `flash=${encodeURIComponent(JSON.stringify({
|
|
223
|
+
url: url.pathname + url.search,
|
|
224
|
+
result: isError ? result.message : result,
|
|
225
|
+
thrown: thrown,
|
|
226
|
+
error: isError,
|
|
227
|
+
input: [...parsed.slice(0, -1), [...parsed[parsed.length - 1].entries()]]
|
|
228
|
+
}))}; Secure; HttpOnly;`);
|
|
215
229
|
}
|
|
216
230
|
return new Response(null, {
|
|
217
231
|
status: statusCode,
|
|
218
|
-
headers
|
|
219
|
-
Location: redirectUrl,
|
|
220
|
-
...(result
|
|
221
|
-
? {
|
|
222
|
-
"Set-Cookie": `flash=${JSON.stringify({
|
|
223
|
-
url: url.pathname + encodeURIComponent(url.search),
|
|
224
|
-
result: isError ? result.message : result,
|
|
225
|
-
thrown: thrown,
|
|
226
|
-
error: isError,
|
|
227
|
-
input: [...parsed.slice(0, -1), [...parsed[parsed.length - 1].entries()]]
|
|
228
|
-
})}; Secure; HttpOnly;`
|
|
229
|
-
}
|
|
230
|
-
: {})
|
|
231
|
-
}
|
|
232
|
+
headers
|
|
232
233
|
});
|
|
233
234
|
}
|
|
234
235
|
let App;
|
|
@@ -242,7 +243,7 @@ async function handleSingleFlight(sourceEvent, result) {
|
|
|
242
243
|
url = new URL(result.headers.get("Location"), new URL(sourceEvent.request.url).origin + import.meta.env.SERVER_BASE_URL).toString();
|
|
243
244
|
}
|
|
244
245
|
const event = cloneEvent(sourceEvent);
|
|
245
|
-
event.request = new Request(url);
|
|
246
|
+
event.request = new Request(url, { headers: sourceEvent.request.headers });
|
|
246
247
|
return await provideRequestEvent(event, async () => {
|
|
247
248
|
await createPageEvent(event);
|
|
248
249
|
/* @ts-ignore */
|
|
@@ -130,9 +130,9 @@ async function fetchServerFunction(base, id, options, args) {
|
|
|
130
130
|
body: JSON.stringify(await Promise.resolve(toJSONAsync(args, { plugins }))),
|
|
131
131
|
headers: { ...options.headers, "Content-Type": "application/json" }
|
|
132
132
|
}));
|
|
133
|
-
if (response.headers.
|
|
134
|
-
response.headers.
|
|
135
|
-
response.headers.
|
|
133
|
+
if (response.headers.has("Location") ||
|
|
134
|
+
response.headers.has("X-Revalidate") ||
|
|
135
|
+
response.headers.has("X-Single-Flight")) {
|
|
136
136
|
if (response.body) {
|
|
137
137
|
/* @ts-ignore-next-line */
|
|
138
138
|
response.customBody = () => {
|
package/dist/server/handler.js
CHANGED
|
@@ -26,7 +26,7 @@ export function createBaseHandler(fn, createPageEvent, options = {}) {
|
|
|
26
26
|
const match = matchAPIRoute(new URL(event.request.url).pathname, event.request.method);
|
|
27
27
|
if (match) {
|
|
28
28
|
const mod = await match.handler.import();
|
|
29
|
-
const fn = mod[event.request.method];
|
|
29
|
+
const fn = event.request.method === "HEAD" ? mod["HEAD"] || mod["GET"] : mod[event.request.method];
|
|
30
30
|
event.params = match.params || {};
|
|
31
31
|
// @ts-ignore
|
|
32
32
|
sharedConfig.context = { event };
|
package/dist/server/pageEvent.js
CHANGED
|
@@ -4,19 +4,26 @@ function initFromFlash(ctx) {
|
|
|
4
4
|
const flash = getCookie(ctx.nativeEvent, "flash");
|
|
5
5
|
if (!flash)
|
|
6
6
|
return;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
try {
|
|
8
|
+
let param = JSON.parse(flash);
|
|
9
|
+
if (!param || !param.result)
|
|
10
|
+
return;
|
|
11
|
+
const input = [...param.input.slice(0, -1), new Map(param.input[param.input.length - 1])];
|
|
12
|
+
const result = param.error ? new Error(param.result) : param.result;
|
|
13
|
+
return {
|
|
14
|
+
input,
|
|
15
|
+
url: param.url,
|
|
16
|
+
pending: false,
|
|
17
|
+
result: param.thrown ? undefined : result,
|
|
18
|
+
error: param.thrown ? result : undefined
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
console.error(e);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
setCookie(ctx.nativeEvent, "flash", "", { maxAge: 0 });
|
|
26
|
+
}
|
|
20
27
|
}
|
|
21
28
|
export async function createPageEvent(ctx) {
|
|
22
29
|
const clientManifest = import.meta.env.MANIFEST["client"];
|
|
@@ -28,7 +35,9 @@ export async function createPageEvent(ctx) {
|
|
|
28
35
|
manifest: await clientManifest.json(),
|
|
29
36
|
assets: [
|
|
30
37
|
...(await clientManifest.inputs[clientManifest.handler].assets()),
|
|
31
|
-
...(import.meta.env.DEV
|
|
38
|
+
...(import.meta.env.DEV
|
|
39
|
+
? await clientManifest.inputs[import.meta.env.START_APP].assets()
|
|
40
|
+
: []),
|
|
32
41
|
...(import.meta.env.START_ISLANDS
|
|
33
42
|
? (await serverManifest.inputs[serverManifest.handler].assets()).filter(s => s.attrs.rel !== "modulepreload")
|
|
34
43
|
: [])
|
|
@@ -5,6 +5,8 @@ import type { Component, ComponentProps, JSX } from "solid-js";
|
|
|
5
5
|
*/
|
|
6
6
|
export default function clientOnly<T extends Component<any>>(fn: () => Promise<{
|
|
7
7
|
default: T;
|
|
8
|
-
}
|
|
8
|
+
}>, options?: {
|
|
9
|
+
lazy?: boolean;
|
|
10
|
+
}): (props: ComponentProps<T> & {
|
|
9
11
|
fallback?: JSX.Element;
|
|
10
12
|
}) => any;
|
|
@@ -5,15 +5,16 @@ import { isServer } from "solid-js/web";
|
|
|
5
5
|
* Read more: https://docs.solidjs.com/solid-start/reference/client/client-only
|
|
6
6
|
*/
|
|
7
7
|
// not using Suspense
|
|
8
|
-
export default function clientOnly(fn) {
|
|
8
|
+
export default function clientOnly(fn, options = {}) {
|
|
9
9
|
if (isServer)
|
|
10
10
|
return (props) => props.fallback;
|
|
11
11
|
const [comp, setComp] = createSignal();
|
|
12
|
-
|
|
12
|
+
!options.lazy && load(fn, setComp);
|
|
13
13
|
return (props) => {
|
|
14
14
|
let Comp;
|
|
15
15
|
let m;
|
|
16
16
|
const [, rest] = splitProps(props, ["fallback"]);
|
|
17
|
+
options.lazy && load(fn, setComp);
|
|
17
18
|
if ((Comp = comp()) && !sharedConfig.context)
|
|
18
19
|
return Comp(rest);
|
|
19
20
|
const [mounted, setMounted] = createSignal(!sharedConfig.context);
|
|
@@ -21,3 +22,6 @@ export default function clientOnly(fn) {
|
|
|
21
22
|
return createMemo(() => ((Comp = comp()), (m = mounted()), untrack(() => (Comp && m ? Comp(rest) : props.fallback))));
|
|
22
23
|
};
|
|
23
24
|
}
|
|
25
|
+
function load(fn, setComp) {
|
|
26
|
+
fn().then(m => setComp(() => m.default));
|
|
27
|
+
}
|
|
@@ -14,12 +14,20 @@ export function classNames(...classes) {
|
|
|
14
14
|
return classes.filter(Boolean).join(' ');
|
|
15
15
|
}
|
|
16
16
|
function ErrorInfo(props) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
const error = createMemo(() => {
|
|
18
|
+
const e = props.error;
|
|
19
|
+
if (e instanceof Error) {
|
|
20
|
+
return { name: e.name, message: e.message };
|
|
21
|
+
}
|
|
22
|
+
if (e instanceof ErrorEvent) {
|
|
23
|
+
return { message: e.message };
|
|
24
|
+
}
|
|
25
|
+
return { message: e.toString() };
|
|
26
|
+
});
|
|
27
|
+
return (<span class="dev-overlay-error-info">
|
|
28
|
+
<span class="dev-overlay-error-info-name">{error().name}</span>
|
|
29
|
+
<span class="dev-overlay-error-info-message">{error().message}</span>
|
|
30
|
+
</span>);
|
|
23
31
|
}
|
|
24
32
|
function getFileName(source) {
|
|
25
33
|
try {
|
|
@@ -7,7 +7,7 @@ const DevOverlayDialog =
|
|
|
7
7
|
? () => {
|
|
8
8
|
return <></>;
|
|
9
9
|
}
|
|
10
|
-
: /* #__PURE__ */ clientOnly(() => import("./DevOverlayDialog"));
|
|
10
|
+
: /* #__PURE__ */ clientOnly(() => import("./DevOverlayDialog"), { lazy: true });
|
|
11
11
|
export function DevOverlay(props) {
|
|
12
12
|
const [errors, setErrors] = createSignal([]);
|
|
13
13
|
function resetError() {
|
|
@@ -20,7 +20,7 @@ export function DevOverlay(props) {
|
|
|
20
20
|
}
|
|
21
21
|
createEffect(() => {
|
|
22
22
|
const onErrorEvent = (error) => {
|
|
23
|
-
pushError(error.error);
|
|
23
|
+
pushError(error.error ?? error);
|
|
24
24
|
};
|
|
25
25
|
window.addEventListener("error", onErrorEvent);
|
|
26
26
|
onCleanup(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/start",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"solid-js": "^1.9.
|
|
58
|
+
"solid-js": "^1.9.2",
|
|
59
59
|
"vinxi": "^0.4.3",
|
|
60
60
|
"typescript": "^5.4.2"
|
|
61
61
|
},
|
|
@@ -65,7 +65,6 @@
|
|
|
65
65
|
"@vinxi/server-functions": "^0.4.3",
|
|
66
66
|
"defu": "^6.1.2",
|
|
67
67
|
"error-stack-parser": "^2.1.4",
|
|
68
|
-
"glob": "^10.3.10",
|
|
69
68
|
"html-to-image": "^1.11.11",
|
|
70
69
|
"radix3": "^1.1.0",
|
|
71
70
|
"seroval": "^1.0.2",
|
|
@@ -73,6 +72,7 @@
|
|
|
73
72
|
"shikiji": "^0.9.12",
|
|
74
73
|
"source-map-js": "^1.0.2",
|
|
75
74
|
"terracotta": "^1.0.4",
|
|
75
|
+
"tinyglobby": "^0.2.2",
|
|
76
76
|
"vite-plugin-solid": "^2.10.2"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|