@solidjs/start 0.4.0-alpha.6 → 0.4.0-alpha.8
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/server-runtime.jsx +1 -1
- package/package.json +2 -2
- package/server/StartServer.tsx +34 -1
- package/shared/FileRoutes.tsx +2 -1
- package/shared/lazyRoute.tsx +2 -1
- package/shared/routes.ts +6 -8
|
@@ -69,7 +69,7 @@ async function fetchServerFunction(base, id, args) {
|
|
|
69
69
|
const instance = `server-fn:${INSTANCE++}`;
|
|
70
70
|
const response = await (args.length === 1 && args[0] instanceof FormData
|
|
71
71
|
? createRequest(base, id, instance, args[0])
|
|
72
|
-
: createRequest(base, id, instance, JSON.stringify(await toJSONAsync(args)), "application/json"));
|
|
72
|
+
: createRequest(base, id, instance, JSON.stringify(await Promise.resolve(toJSONAsync(args))), "application/json"));
|
|
73
73
|
|
|
74
74
|
if (response.headers.get("Location")) throw response;
|
|
75
75
|
if (response.headers.get("X-Revalidate")) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/start",
|
|
3
|
-
"version": "0.4.0-alpha.
|
|
3
|
+
"version": "0.4.0-alpha.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"publishConfig": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"solid-js": "^1.8.7",
|
|
42
|
-
"vinxi": "0.0.
|
|
42
|
+
"vinxi": "0.0.52"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@vinxi/plugin-directives": "0.0.44",
|
package/server/StartServer.tsx
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
import App from "#start/app";
|
|
3
3
|
import type { Component } from "solid-js";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Hydration,
|
|
6
|
+
HydrationScript,
|
|
7
|
+
NoHydration,
|
|
8
|
+
getRequestEvent,
|
|
9
|
+
ssr,
|
|
10
|
+
useAssets
|
|
11
|
+
} from "solid-js/web";
|
|
5
12
|
import { ErrorBoundary } from "../shared/ErrorBoundary";
|
|
6
13
|
import { renderAsset } from "./renderAsset";
|
|
7
14
|
import type { DocumentComponentProps } from "./types";
|
|
@@ -10,6 +17,32 @@ const docType = ssr("<!DOCTYPE html>");
|
|
|
10
17
|
|
|
11
18
|
export function StartServer(props: { document: Component<DocumentComponentProps> }) {
|
|
12
19
|
const context = getRequestEvent() as any;
|
|
20
|
+
|
|
21
|
+
let assets = [];
|
|
22
|
+
Promise.resolve().then(async () => {
|
|
23
|
+
let current = context.routes;
|
|
24
|
+
if (context.routerMatches && context.routerMatches[0]) {
|
|
25
|
+
for (let i = 0; i < context.routerMatches[0].length; i++) {
|
|
26
|
+
const match = context.routerMatches[0][i];
|
|
27
|
+
if (match.metadata && match.metadata.filesystem) {
|
|
28
|
+
const segment = current.find(r => r.path === match.path);
|
|
29
|
+
const part = import.meta.env.MANIFEST["client"].inputs[segment["$component"].src];
|
|
30
|
+
const asset = await part.assets();
|
|
31
|
+
assets.push.apply(assets, asset);
|
|
32
|
+
current = segment.children;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// dedupe assets
|
|
37
|
+
assets = [...new Map(assets.map(item => [item.attrs.key, item])).values()].filter(
|
|
38
|
+
asset =>
|
|
39
|
+
asset.attrs.rel === "modulepreload" &&
|
|
40
|
+
!context.assets.find(a => a.attrs.key === asset.attrs.key)
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
useAssets(() => assets.length ? assets.map(m => renderAsset(m)) : undefined);
|
|
45
|
+
|
|
13
46
|
return (
|
|
14
47
|
<NoHydration>
|
|
15
48
|
{docType as unknown as any}
|
package/shared/FileRoutes.tsx
CHANGED
|
@@ -10,6 +10,7 @@ export function createRoutes() {
|
|
|
10
10
|
return {
|
|
11
11
|
...route,
|
|
12
12
|
...(route.$$route ? route.$$route.require().route : undefined),
|
|
13
|
+
metadata: { ...(route.$$route ? route.$$route.require().route.metadata : {}), filesystem: true },
|
|
13
14
|
component: lazyRoute(
|
|
14
15
|
route.$component,
|
|
15
16
|
import.meta.env.START_ISLANDS
|
|
@@ -26,5 +27,5 @@ export function createRoutes() {
|
|
|
26
27
|
|
|
27
28
|
let routes;
|
|
28
29
|
export const FileRoutes = () => {
|
|
29
|
-
return isServer ? (getRequestEvent() as PageEvent).routes :
|
|
30
|
+
return isServer ? (getRequestEvent() as PageEvent).routes : routes || (routes = createRoutes());
|
|
30
31
|
};
|
package/shared/lazyRoute.tsx
CHANGED
|
@@ -47,9 +47,10 @@ export default function lazyRoute(
|
|
|
47
47
|
const mod = await component.import();
|
|
48
48
|
const Component = mod[exported];
|
|
49
49
|
let assets = await clientManifest.inputs?.[component.src].assets();
|
|
50
|
+
const styles = assets.filter((asset) => asset.tag === "style" || asset.attrs.rel === "stylesheet");
|
|
50
51
|
const Comp = (props) => {
|
|
51
52
|
return [
|
|
52
|
-
...
|
|
53
|
+
...styles.map((asset) => renderAsset(asset)),
|
|
53
54
|
createComponent(Component, props),
|
|
54
55
|
];
|
|
55
56
|
};
|
package/shared/routes.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { HTTPMethod } from "vinxi/server";
|
|
|
3
3
|
|
|
4
4
|
interface Route {
|
|
5
5
|
path: string;
|
|
6
|
+
id: string;
|
|
6
7
|
type: "api" | "page";
|
|
7
8
|
children?: Route[];
|
|
8
9
|
}
|
|
@@ -29,7 +30,7 @@ declare module "vinxi/routes" {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
export const pageRoutes = defineRoutes((fileRoutes as unknown as Route[]).filter(o => o.type === "page"));
|
|
32
|
-
|
|
33
|
+
const apiRoutes = defineAPIRoutes((fileRoutes as unknown as Route[]).filter(o => o.type === "api"));
|
|
33
34
|
|
|
34
35
|
export function matchAPIRoute(path: string, method: HTTPMethod) {
|
|
35
36
|
const segments = path.split("/").filter(Boolean);
|
|
@@ -76,20 +77,17 @@ export function matchAPIRoute(path: string, method: HTTPMethod) {
|
|
|
76
77
|
function defineRoutes(fileRoutes: Route[]) {
|
|
77
78
|
function processRoute(routes: Route[], route: Route, id: string, full: string) {
|
|
78
79
|
const parentRoute = Object.values(routes).find(o => {
|
|
79
|
-
|
|
80
|
-
// return false;
|
|
81
|
-
// }
|
|
82
|
-
return id.startsWith(o.path + "/");
|
|
80
|
+
return id.startsWith(o.id + "/");
|
|
83
81
|
});
|
|
84
82
|
|
|
85
83
|
if (!parentRoute) {
|
|
86
|
-
routes.push({ ...route, path: id });
|
|
84
|
+
routes.push({ ...route, id, path: id.replace(/\/\([^)/]+\)/g, "") });
|
|
87
85
|
return routes;
|
|
88
86
|
}
|
|
89
87
|
processRoute(
|
|
90
88
|
parentRoute.children || (parentRoute.children = []),
|
|
91
89
|
route,
|
|
92
|
-
id.slice(parentRoute.
|
|
90
|
+
id.slice(parentRoute.id.length),
|
|
93
91
|
full
|
|
94
92
|
);
|
|
95
93
|
|
|
@@ -101,7 +99,7 @@ function defineRoutes(fileRoutes: Route[]) {
|
|
|
101
99
|
.reduce((prevRoutes, route) => {
|
|
102
100
|
return processRoute(prevRoutes, route, route.path, route.path);
|
|
103
101
|
}, []);
|
|
104
|
-
}
|
|
102
|
+
}
|
|
105
103
|
|
|
106
104
|
function defineAPIRoutes(routes: Route[]) {
|
|
107
105
|
return routes
|