@solidjs/start 0.4.5 → 0.4.6
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/index.js
CHANGED
|
@@ -170,6 +170,7 @@ export function defineConfig(baseConfig = {}) {
|
|
|
170
170
|
"import.meta.env.START_ISLANDS": JSON.stringify(start.islands),
|
|
171
171
|
"import.meta.env.SSR": JSON.stringify(false),
|
|
172
172
|
"import.meta.env.START_SSR": JSON.stringify(start.ssr),
|
|
173
|
+
"import.meta.env.SERVER_BASE_URL": JSON.stringify(server?.baseURL ?? ""),
|
|
173
174
|
...userConfig.define
|
|
174
175
|
}
|
|
175
176
|
})
|
|
@@ -3,10 +3,11 @@ import { provideRequestEvent } from "solid-js/web/storage";
|
|
|
3
3
|
import { cloneEvent } from "../server/middleware";
|
|
4
4
|
|
|
5
5
|
export function createServerReference(fn, id, name) {
|
|
6
|
+
const baseURL = import.meta.env.SERVER_BASE_URL;
|
|
6
7
|
return new Proxy(fn, {
|
|
7
8
|
get(target, prop, receiver) {
|
|
8
9
|
if (prop === "url") {
|
|
9
|
-
return
|
|
10
|
+
return `${baseURL}/_server?id=${encodeURIComponent(id)}&name=${encodeURIComponent(name)}`;
|
|
10
11
|
}
|
|
11
12
|
},
|
|
12
13
|
apply(target, thisArg, args) {
|
|
@@ -120,14 +120,15 @@ async function fetchServerFunction(base, id, args) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
export function createServerReference(fn, id, name) {
|
|
123
|
+
const baseURL = import.meta.env.SERVER_BASE_URL;
|
|
123
124
|
return new Proxy(fn, {
|
|
124
125
|
get(target, prop, receiver) {
|
|
125
126
|
if (prop === "url") {
|
|
126
|
-
return
|
|
127
|
+
return `${baseURL}/_server?id=${encodeURIComponent(id)}&name=${encodeURIComponent(name)}`;
|
|
127
128
|
}
|
|
128
129
|
},
|
|
129
130
|
apply(target, thisArg, args) {
|
|
130
|
-
return fetchServerFunction(
|
|
131
|
+
return fetchServerFunction(`${baseURL}/_server`, `${id}#${name}`, args);
|
|
131
132
|
}
|
|
132
133
|
});
|
|
133
134
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/start",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"publishConfig": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"solid-js": "^1.8.
|
|
41
|
+
"solid-js": "^1.8.10",
|
|
42
42
|
"vinxi": "0.1.1"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
package/server/StartServer.tsx
CHANGED
|
@@ -15,24 +15,40 @@ import type { DocumentComponentProps } from "./types";
|
|
|
15
15
|
|
|
16
16
|
const docType = ssr("<!DOCTYPE html>");
|
|
17
17
|
|
|
18
|
+
function matchRoute(matches, routes, matched = []) {
|
|
19
|
+
for (let i = 0; i < routes.length; i++) {
|
|
20
|
+
const segment = routes[i];
|
|
21
|
+
if (segment.path !== matches[0].path) continue;
|
|
22
|
+
let next = [...matched, segment];
|
|
23
|
+
if (segment.children) {
|
|
24
|
+
const nextMatches = matches.slice(1);
|
|
25
|
+
if (nextMatches.length === 0) continue;
|
|
26
|
+
next = matchRoute(nextMatches, segment.children, next);
|
|
27
|
+
if (!next) continue;
|
|
28
|
+
}
|
|
29
|
+
return next;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
18
33
|
export function StartServer(props: { document: Component<DocumentComponentProps> }) {
|
|
19
34
|
const context = getRequestEvent() as any;
|
|
20
35
|
|
|
21
36
|
let assets = [];
|
|
22
37
|
Promise.resolve().then(async () => {
|
|
23
|
-
let current = context.routes;
|
|
24
38
|
if (context.routerMatches && context.routerMatches[0]) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
const matches = [...context.routerMatches[0]];
|
|
40
|
+
while (matches.length && (!matches[0].metadata || !matches[0].metadata.filesystem))
|
|
41
|
+
matches.shift();
|
|
42
|
+
const matched = matches.length && matchRoute(matches, context.routes);
|
|
43
|
+
if (matched) {
|
|
44
|
+
for (let i = 0; i < matched.length; i++) {
|
|
45
|
+
const segment = matched[i];
|
|
29
46
|
const part = import.meta.env.MANIFEST[import.meta.env.START_ISLANDS ? "ssr" : "client"]
|
|
30
47
|
.inputs[segment["$component"].src];
|
|
31
48
|
const asset = await part.assets();
|
|
32
49
|
assets.push.apply(assets, asset);
|
|
33
|
-
current = segment.children;
|
|
34
50
|
}
|
|
35
|
-
}
|
|
51
|
+
} else console.warn("No route matched for preloading js assets");
|
|
36
52
|
}
|
|
37
53
|
// dedupe assets
|
|
38
54
|
assets = [...new Map(assets.map(item => [item.attrs.key, item])).values()].filter(asset =>
|