@solidjs/start 2.0.0-beta.0 → 2.0.0-beta.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.
Files changed (91) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/config/dev-server.js +3 -1
  3. package/dist/config/fs-router.d.ts +1 -1
  4. package/dist/http/index.d.ts +4 -4
  5. package/package.json +11 -5
  6. package/scripts/build.js +0 -15
  7. package/scripts/validate-imports.js +0 -316
  8. package/src/client/StartClient.tsx +0 -34
  9. package/src/client/index.tsx +0 -2
  10. package/src/client/mount.ts +0 -1
  11. package/src/client/spa/index.tsx +0 -9
  12. package/src/config/constants.ts +0 -19
  13. package/src/config/dev-server.ts +0 -157
  14. package/src/config/env.ts +0 -105
  15. package/src/config/fs-router.ts +0 -162
  16. package/src/config/fs-routes/fs-watcher.ts +0 -66
  17. package/src/config/fs-routes/index.ts +0 -136
  18. package/src/config/fs-routes/router.ts +0 -184
  19. package/src/config/fs-routes/tree-shake.ts +0 -324
  20. package/src/config/index.ts +0 -239
  21. package/src/config/lazy.ts +0 -132
  22. package/src/config/manifest.ts +0 -120
  23. package/src/config/utils.ts +0 -5
  24. package/src/config/vite-utils.ts +0 -113
  25. package/src/directives/bubble-function-declaration.ts +0 -33
  26. package/src/directives/compile.ts +0 -54
  27. package/src/directives/generate-unique-name.ts +0 -22
  28. package/src/directives/get-descriptive-name.ts +0 -39
  29. package/src/directives/get-import-identifier.ts +0 -34
  30. package/src/directives/get-root-statement-path.ts +0 -14
  31. package/src/directives/index.ts +0 -233
  32. package/src/directives/is-statement-top-level.ts +0 -13
  33. package/src/directives/paths.ts +0 -63
  34. package/src/directives/plugin.ts +0 -389
  35. package/src/directives/remove-unused-variables.ts +0 -70
  36. package/src/directives/types.ts +0 -12
  37. package/src/directives/xxhash32.ts +0 -214
  38. package/src/env.d.ts +0 -17
  39. package/src/fns/client.ts +0 -141
  40. package/src/fns/handler.spec.ts +0 -85
  41. package/src/fns/handler.ts +0 -287
  42. package/src/fns/registration.ts +0 -19
  43. package/src/fns/serialization.ts +0 -250
  44. package/src/fns/server.ts +0 -46
  45. package/src/fns/shared.ts +0 -116
  46. package/src/http/index.ts +0 -216
  47. package/src/index.tsx +0 -7
  48. package/src/internal.d.ts +0 -14
  49. package/src/middleware/index.ts +0 -92
  50. package/src/router.tsx +0 -37
  51. package/src/server/StartServer.tsx +0 -58
  52. package/src/server/assets/PatchVirtualDevStyles.tsx +0 -31
  53. package/src/server/assets/index.ts +0 -70
  54. package/src/server/assets/render.tsx +0 -46
  55. package/src/server/collect-styles.ts +0 -70
  56. package/src/server/fetchEvent.spec.ts +0 -85
  57. package/src/server/fetchEvent.ts +0 -36
  58. package/src/server/handler.ts +0 -261
  59. package/src/server/index.tsx +0 -29
  60. package/src/server/manifest/client-manifest.ts +0 -8
  61. package/src/server/manifest/dev-client-manifest.ts +0 -21
  62. package/src/server/manifest/dev-ssr-manifest.ts +0 -23
  63. package/src/server/manifest/prod-client-manifest.ts +0 -21
  64. package/src/server/manifest/prod-ssr-manifest.ts +0 -109
  65. package/src/server/manifest/ssr-manifest.ts +0 -10
  66. package/src/server/routes.ts +0 -126
  67. package/src/server/spa/StartServer.tsx +0 -42
  68. package/src/server/spa/handler.ts +0 -29
  69. package/src/server/spa/index.tsx +0 -5
  70. package/src/server/types.ts +0 -82
  71. package/src/server/util.ts +0 -12
  72. package/src/shared/ErrorBoundary.tsx +0 -52
  73. package/src/shared/GET.ts +0 -8
  74. package/src/shared/HttpHeader.tsx +0 -42
  75. package/src/shared/HttpStatusCode.ts +0 -27
  76. package/src/shared/clientOnly.ts +0 -44
  77. package/src/shared/dev-overlay/CodeView.tsx +0 -90
  78. package/src/shared/dev-overlay/DevOverlayDialog.tsx +0 -316
  79. package/src/shared/dev-overlay/createStackFrame.ts +0 -74
  80. package/src/shared/dev-overlay/download.ts +0 -6
  81. package/src/shared/dev-overlay/env.d.ts +0 -4
  82. package/src/shared/dev-overlay/get-source-map.ts +0 -33
  83. package/src/shared/dev-overlay/icons.tsx +0 -456
  84. package/src/shared/dev-overlay/index.tsx +0 -63
  85. package/src/shared/dev-overlay/styles.css +0 -292
  86. package/src/shared/lazy.ts +0 -52
  87. package/src/shared/serverFunction.ts +0 -10
  88. package/src/utils/debounce.ts +0 -10
  89. package/src/virtual.d.ts +0 -27
  90. package/tsconfig.json +0 -24
  91. package/vitest.config.ts +0 -9
package/src/fns/shared.ts DELETED
@@ -1,116 +0,0 @@
1
- import { deserializeJSONStream, deserializeJSStream } from "./serialization.ts";
2
-
3
- export const BODY_FORMAT_KEY = "X-Start-Type";
4
-
5
- export const BODY_FORMAL_FILE = "__START__";
6
-
7
- export const enum BodyFormat {
8
- Seroval = "0",
9
- String = "1",
10
- FormData = "2",
11
- URLSearchParams = "3",
12
- Blob = "4",
13
- File = "5",
14
- ArrayBuffer = "6",
15
- Uint8Array = "7",
16
- }
17
-
18
- export function getHeadersAndBody(body: any):
19
- | {
20
- headers?: HeadersInit;
21
- body: BodyInit;
22
- }
23
- | undefined {
24
- switch (true) {
25
- case typeof body === "string":
26
- return {
27
- headers: {
28
- "Content-Type": "text/plain",
29
- [BODY_FORMAT_KEY]: BodyFormat.String,
30
- },
31
- body,
32
- };
33
- case body instanceof FormData:
34
- return {
35
- headers: {
36
- [BODY_FORMAT_KEY]: BodyFormat.FormData,
37
- },
38
- body,
39
- };
40
- case body instanceof URLSearchParams:
41
- return {
42
- headers: {
43
- "Content-Type": "application/x-www-form-urlencoded",
44
- [BODY_FORMAT_KEY]: BodyFormat.URLSearchParams,
45
- },
46
- body,
47
- };
48
- case body instanceof File: {
49
- const formData = new FormData();
50
- formData.append(BODY_FORMAL_FILE, body, body.name);
51
- return {
52
- headers: {
53
- [BODY_FORMAT_KEY]: BodyFormat.File,
54
- },
55
- body: formData,
56
- };
57
- }
58
- case body instanceof Blob:
59
- return {
60
- headers: {
61
- [BODY_FORMAT_KEY]: BodyFormat.Blob,
62
- },
63
- body,
64
- };
65
- case body instanceof ArrayBuffer:
66
- return {
67
- headers: {
68
- [BODY_FORMAT_KEY]: BodyFormat.ArrayBuffer,
69
- },
70
- body,
71
- };
72
- case body instanceof Uint8Array:
73
- return {
74
- headers: {
75
- [BODY_FORMAT_KEY]: BodyFormat.Uint8Array,
76
- },
77
- body: new Uint8Array(body),
78
- };
79
- default:
80
- return undefined;
81
- }
82
- }
83
-
84
- export async function extractBody(instance: string, client: boolean, source: Request | Response) {
85
- const contentType = source.headers.get("content-type");
86
- const startType = source.headers.get(BODY_FORMAT_KEY);
87
- const clone = source.clone();
88
-
89
- switch (true) {
90
- case startType === BodyFormat.Seroval:
91
- if (client && import.meta.env.SEROVAL_MODE === "js") {
92
- return await deserializeJSStream(instance, clone);
93
- }
94
- return await deserializeJSONStream(clone);
95
- case startType === BodyFormat.String:
96
- return await clone.text();
97
- case startType === BodyFormat.File: {
98
- const formData = await clone.formData();
99
- return formData.get(BODY_FORMAL_FILE);
100
- }
101
- case startType === BodyFormat.FormData:
102
- case contentType?.startsWith("multipart/form-data"):
103
- return await clone.formData();
104
- case startType === BodyFormat.URLSearchParams:
105
- case contentType?.startsWith("application/x-www-form-urlencoded"):
106
- return new URLSearchParams(await clone.text());
107
- case startType === BodyFormat.Blob:
108
- return await clone.blob();
109
- case startType === BodyFormat.ArrayBuffer:
110
- return await clone.arrayBuffer();
111
- case startType === BodyFormat.Uint8Array:
112
- return new Uint8Array(await clone.arrayBuffer());
113
- }
114
-
115
- return undefined;
116
- }
package/src/http/index.ts DELETED
@@ -1,216 +0,0 @@
1
- import type { H3Event, HTTPEvent, InferEventInput } from "h3";
2
- import * as h3 from "h3";
3
- import { getRequestEvent } from "solid-js/web";
4
-
5
- function _setContext(event: H3Event, key: string, value: any) {
6
- event.context[key] = value;
7
- }
8
-
9
- function _getContext(event: H3Event, key: string) {
10
- return event.context[key];
11
- }
12
-
13
- function getEvent() {
14
- return getRequestEvent()!.nativeEvent;
15
- }
16
-
17
- export function getWebRequest(): Request {
18
- return getEvent().req;
19
- }
20
-
21
- export const HTTPEventSymbol = Symbol("$HTTPEvent");
22
-
23
- export function isEvent(obj: any): obj is h3.H3Event | { [HTTPEventSymbol]: h3.H3Event } {
24
- return (
25
- typeof obj === "object" &&
26
- (obj instanceof h3.H3Event ||
27
- obj?.[HTTPEventSymbol] instanceof h3.H3Event ||
28
- obj?.__is_event__ === true)
29
- );
30
- // Implement logic to check if obj is an H3Event
31
- }
32
-
33
- type Tail<T> = T extends [any, ...infer U] ? U : never;
34
-
35
- type PrependOverload<
36
- TOriginal extends (...args: Array<any>) => any,
37
- TOverload extends (...args: Array<any>) => any,
38
- > = TOverload & TOriginal;
39
-
40
- // add an overload to the function without the event argument
41
- type WrapFunction<TFn extends (...args: Array<any>) => any> = PrependOverload<
42
- TFn,
43
- (
44
- ...args: Parameters<TFn> extends [h3.HTTPEvent<any> | h3.H3Event<any>, ...infer TArgs]
45
- ? TArgs
46
- : Parameters<TFn>
47
- ) => ReturnType<TFn>
48
- >;
49
-
50
- function createWrapperFunction<TFn extends (...args: Array<any>) => any>(
51
- h3Function: TFn,
52
- ): WrapFunction<TFn> {
53
- return ((...args: Array<any>) => {
54
- const event = args[0];
55
- if (!isEvent(event)) {
56
- args.unshift(getEvent());
57
- } else {
58
- args[0] =
59
- event instanceof h3.H3Event || (event as any).__is_event__ ? event : event[HTTPEventSymbol];
60
- }
61
-
62
- return (h3Function as any)(...args);
63
- }) as any;
64
- }
65
-
66
- // Creating wrappers for each utility and exporting them with their original names
67
- // readRawBody => getWebRequest().text()/.arrayBuffer()
68
- type WrappedReadBody = <T, TEventInput = InferEventInput<"body", H3Event, T>>(
69
- ...args: Tail<Parameters<typeof h3.readBody<T, H3Event, TEventInput>>>
70
- ) => ReturnType<typeof h3.readBody<T, h3.H3Event, TEventInput>>;
71
- export const readBody = createWrapperFunction(h3.readBody) as PrependOverload<
72
- typeof h3.readBody,
73
- WrappedReadBody
74
- >;
75
- type WrappedGetQuery = <T, TEventInput = Exclude<InferEventInput<"query", H3Event, T>, undefined>>(
76
- ...args: Tail<Parameters<typeof h3.getQuery<T, H3Event, TEventInput>>>
77
- ) => ReturnType<typeof h3.getQuery<T, H3Event, TEventInput>>;
78
- export const getQuery = createWrapperFunction(h3.getQuery) as PrependOverload<
79
- typeof h3.getQuery,
80
- WrappedGetQuery
81
- >;
82
- export const isMethod = createWrapperFunction(h3.isMethod);
83
- export const isPreflightRequest = createWrapperFunction(h3.isPreflightRequest);
84
- type WrappedGetValidatedQuery = <
85
- T extends HTTPEvent,
86
- TEventInput = InferEventInput<"query", H3Event, T>,
87
- >(
88
- ...args: Tail<Parameters<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>>
89
- ) => ReturnType<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>;
90
- export const getValidatedQuery = createWrapperFunction(h3.getValidatedQuery) as PrependOverload<
91
- typeof h3.getValidatedQuery,
92
- WrappedGetValidatedQuery
93
- >;
94
- export const getRouterParams = createWrapperFunction(h3.getRouterParams);
95
- export const getRouterParam = createWrapperFunction(h3.getRouterParam);
96
- type WrappedGetValidatedRouterParams = <
97
- T extends HTTPEvent,
98
- TEventInput = InferEventInput<"routerParams", H3Event, T>,
99
- >(
100
- ...args: Tail<Parameters<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>>
101
- ) => ReturnType<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>;
102
- export const getValidatedRouterParams = createWrapperFunction(
103
- h3.getValidatedRouterParams,
104
- ) as PrependOverload<typeof h3.getValidatedRouterParams, WrappedGetValidatedRouterParams>;
105
- export const assertMethod = createWrapperFunction(h3.assertMethod);
106
- export const getRequestHeaders = createWrapperFunction(h3.getRequestHeaders);
107
- export const getRequestHeader = createWrapperFunction(h3.getRequestHeader);
108
- export const getRequestURL = createWrapperFunction(h3.getRequestURL);
109
- export const getRequestHost = createWrapperFunction(h3.getRequestHost);
110
- export const getRequestProtocol = createWrapperFunction(h3.getRequestProtocol);
111
- export const getRequestIP = createWrapperFunction(h3.getRequestIP);
112
- export const setResponseStatus = (code?: number, text?: string) => {
113
- const e = getEvent();
114
-
115
- if (e.res.status !== undefined) e.res.status = code;
116
- if (e.res.statusText !== undefined) e.res.statusText = text;
117
- };
118
- export const getResponseStatus = () => getEvent().res.status;
119
- export const getResponseStatusText = () => getEvent().res.statusText;
120
- export const getResponseHeaders = () => Object.fromEntries(getEvent().res.headers.entries());
121
- export const getResponseHeader = (name: string) => getEvent().res.headers.get(name);
122
- export const setResponseHeaders = (values: Record<string, string>) => {
123
- const headers = getEvent().res.headers;
124
- for (const [name, value] of Object.entries(values)) {
125
- headers.set(name, value);
126
- }
127
- };
128
- export const setResponseHeader = (name: string, value: string | string[]) => {
129
- const headers = getEvent().res.headers;
130
-
131
- (Array.isArray(value) ? value : [value]).forEach(value => {
132
- headers.set(name, value);
133
- });
134
- };
135
- export const appendResponseHeaders = (values: Record<string, string>) => {
136
- const headers = getEvent().res.headers;
137
- for (const [name, value] of Object.entries(values)) {
138
- headers.append(name, value);
139
- }
140
- };
141
- export const appendResponseHeader = (name: string, value: string | string[]) => {
142
- const headers = getEvent().res.headers;
143
-
144
- (Array.isArray(value) ? value : [value]).forEach(value => {
145
- headers.append(name, value);
146
- });
147
- };
148
- export const defaultContentType = (type: string) =>
149
- getEvent().res.headers.set("content-type", type);
150
- export const proxyRequest = createWrapperFunction(h3.proxyRequest);
151
- export const fetchWithEvent = createWrapperFunction(h3.fetchWithEvent);
152
- export const getProxyRequestHeaders = createWrapperFunction(h3.getProxyRequestHeaders);
153
-
154
- export const parseCookies = createWrapperFunction(h3.parseCookies);
155
- export const getCookie = createWrapperFunction(h3.getCookie);
156
- export const setCookie = createWrapperFunction(h3.setCookie);
157
- export const deleteCookie = createWrapperFunction(h3.deleteCookie);
158
- // not exported :(
159
- type SessionDataT = Record<string, any>;
160
- type WrappedUseSession = <T extends SessionDataT>(
161
- ...args: Tail<Parameters<typeof h3.useSession<T>>>
162
- ) => ReturnType<typeof h3.useSession<T>>;
163
- export const useSession: WrappedUseSession = createWrapperFunction(h3.useSession);
164
- type WrappedGetSession = <T extends SessionDataT>(
165
- ...args: Tail<Parameters<typeof h3.getSession<T>>>
166
- ) => ReturnType<typeof h3.getSession<T>>;
167
- export const getSession: WrappedGetSession = createWrapperFunction(h3.getSession);
168
- type WrappedUpdateSession = <T extends SessionDataT>(
169
- ...args: Tail<Parameters<typeof h3.updateSession<T>>>
170
- ) => ReturnType<typeof h3.updateSession<T>>;
171
- export const updateSession: WrappedUpdateSession = createWrapperFunction(h3.updateSession);
172
- type WrappedSealSession = <T extends SessionDataT>(
173
- ...args: Tail<Parameters<typeof h3.sealSession<T>>>
174
- ) => ReturnType<typeof h3.sealSession<T>>;
175
- export const sealSession: WrappedSealSession = createWrapperFunction(h3.sealSession);
176
- export const unsealSession = createWrapperFunction(h3.unsealSession);
177
- export const clearSession = createWrapperFunction(h3.clearSession);
178
- export const handleCacheHeaders = createWrapperFunction(h3.handleCacheHeaders);
179
- export const handleCors = createWrapperFunction(h3.handleCors);
180
- export const appendCorsHeaders = createWrapperFunction(h3.appendCorsHeaders);
181
- export const appendCorsPreflightHeaders = createWrapperFunction(h3.appendCorsPreflightHeaders);
182
- export const appendHeader = appendResponseHeader;
183
- export const appendHeaders = appendResponseHeaders;
184
- export const setHeader = setResponseHeader;
185
- export const setHeaders = setResponseHeaders;
186
- export const getHeader = getRequestHeader;
187
- export const getHeaders = getRequestHeaders;
188
- export const getRequestFingerprint = createWrapperFunction(h3.getRequestFingerprint);
189
- export const getRequestWebStream = () => getEvent().req.body;
190
- export const readFormData = () => getEvent().req.formData();
191
- type WrappedReadValidatedBody = <
192
- T extends HTTPEvent,
193
- TEventInput = InferEventInput<"body", H3Event, T>,
194
- >(
195
- ...args: Tail<Parameters<typeof h3.readValidatedBody<T, H3Event, TEventInput>>>
196
- ) => ReturnType<typeof h3.readValidatedBody<T, H3Event, TEventInput>>;
197
- export const readValidatedBody = createWrapperFunction(h3.readValidatedBody) as PrependOverload<
198
- typeof h3.readValidatedBody,
199
- WrappedReadValidatedBody
200
- >;
201
- export const getContext = createWrapperFunction(_getContext);
202
- export const setContext = createWrapperFunction(_setContext);
203
- export const removeResponseHeader = (name: string) => getEvent().res.headers.delete(name);
204
- export const clearResponseHeaders = (headerNames?: string[]) => {
205
- const headers = getEvent().res.headers;
206
-
207
- if (headerNames && headerNames.length > 0) {
208
- for (const name of headerNames) {
209
- headers.delete(name);
210
- }
211
- } else {
212
- for (const name of headers.keys()) {
213
- headers.delete(name);
214
- }
215
- }
216
- };
package/src/index.tsx DELETED
@@ -1,7 +0,0 @@
1
- // @refresh skip
2
-
3
- export { default as clientOnly } from "./shared/clientOnly.ts";
4
- export { GET } from "./shared/GET.ts";
5
- export { HttpHeader } from "./shared/HttpHeader.tsx";
6
- export { HttpStatusCode } from "./shared/HttpStatusCode.ts";
7
- export { getServerFunctionMeta } from "./shared/serverFunction.ts";
package/src/internal.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import "h3";
2
- declare module "h3" {
3
- import { ViteDevServer } from "vite";
4
-
5
- export interface H3EventContext {
6
- viteDevServer?: ViteDevServer;
7
- }
8
- }
9
-
10
- import type { Rollup } from "vite";
11
- declare global {
12
- var START_CLIENT_BUNDLE: Rollup.OutputBundle;
13
- var USING_SOLID_START_DEV_SERVER: boolean | undefined;
14
- }
@@ -1,92 +0,0 @@
1
- // @refresh skip
2
-
3
- import type { H3Event, Middleware } from "h3";
4
- import { getFetchEvent } from "../server/fetchEvent.ts";
5
- import type { FetchEvent } from "../server/types.ts";
6
-
7
- /** Function responsible for receiving an observable [operation]{@link Operation} and returning a [result]{@link OperationResult}. */
8
-
9
- export type MiddlewareFn = (event: FetchEvent) => Promise<unknown> | unknown;
10
- /** This composes an array of Exchanges into a single ExchangeIO function */
11
-
12
- export type RequestMiddleware = (
13
- event: FetchEvent,
14
- ) => Response | Promise<Response> | void | Promise<void> | Promise<void | Response>;
15
-
16
- // copy-pasted from h3/dist/index.d.ts
17
- type EventHandlerResponse<T = any> = T | Promise<T>;
18
- type ResponseMiddlewareResponseParam = { body?: Awaited<EventHandlerResponse> };
19
-
20
- export type ResponseMiddleware = (
21
- event: FetchEvent,
22
- response: ResponseMiddlewareResponseParam,
23
- ) => Response | Promise<Response> | void | Promise<void>;
24
-
25
- function wrapRequestMiddleware(onRequest: RequestMiddleware) {
26
- return async (h3Event: H3Event) => {
27
- const fetchEvent = getFetchEvent(h3Event);
28
- const response = await onRequest(fetchEvent);
29
- if (response) return response;
30
- };
31
- }
32
-
33
- function wrapResponseMiddleware(onBeforeResponse: ResponseMiddleware): Middleware {
34
- return async (h3Event, next) => {
35
- const resp = await next();
36
-
37
- const fetchEvent = getFetchEvent(h3Event);
38
- const mwResponse = await onBeforeResponse(fetchEvent, {
39
- body: resp,
40
- });
41
- if (mwResponse) return mwResponse;
42
- };
43
- }
44
-
45
- /**
46
- * Creates middleware for handling requests and responses.
47
- *
48
- * @see https://docs.solidjs.com/solid-start/reference/server/create-middleware
49
- /**
50
- * Creates request/response middlewares via H3.
51
- *
52
- * Accepts an array of H3 {@link Middleware}
53
- *
54
- * @tip To run your middleware before response, `await next()` in your function block.
55
- *@example
56
- * const middleware = createMiddleware([
57
- * async (event, next) => {
58
- * const resp = await next();
59
- * if (resp instanceof Response) return resp;
60
- * return new Response("Not found", { status: 404 });
61
- * },
62
- * ]);
63
- *
64
- */
65
- export function createMiddleware(
66
- args:
67
- | {
68
- /** @deprecated Use H3 `Middleware` */
69
- onRequest?: RequestMiddleware | RequestMiddleware[] | undefined;
70
- /** @deprecated Use H3 `Middleware` */
71
- onBeforeResponse?: ResponseMiddleware | ResponseMiddleware[] | undefined;
72
- }
73
- | Middleware[],
74
- ): Middleware[] {
75
- if (Array.isArray(args)) return args;
76
-
77
- const mw: Middleware[] = [];
78
-
79
- if (typeof args.onRequest === "function") {
80
- mw.push(wrapRequestMiddleware(args.onRequest));
81
- } else if (Array.isArray(args.onRequest)) {
82
- mw.push(...args.onRequest.map(wrapRequestMiddleware));
83
- }
84
-
85
- if (typeof args.onBeforeResponse === "function") {
86
- mw.push(wrapResponseMiddleware(args.onBeforeResponse));
87
- } else if (Array.isArray(args.onBeforeResponse)) {
88
- mw.push(...args.onBeforeResponse.map(wrapResponseMiddleware));
89
- }
90
-
91
- return mw;
92
- }
package/src/router.tsx DELETED
@@ -1,37 +0,0 @@
1
- import { lazy, type Component } from "solid-js";
2
- import { getRequestEvent, isServer } from "solid-js/web";
3
-
4
- import { pageRoutes as routeConfigs } from "./server/routes.ts";
5
- import type { PageEvent } from "./server/types.ts";
6
-
7
- const components: Record<string, Component> = {};
8
-
9
- export function createRoutes() {
10
- function createRoute(route: any) {
11
- const component =
12
- route.$component && (components[route.$component.src] ??= lazy(route.$component.import));
13
-
14
- return {
15
- ...route,
16
- ...(route.$$route ? route.$$route.require().route : undefined),
17
- info: {
18
- ...(route.$$route ? route.$$route.require().route.info : {}),
19
- filesystem: true,
20
- },
21
- component,
22
- children: route.children ? route.children.map(createRoute) : undefined,
23
- };
24
- }
25
- const routes = routeConfigs.map(createRoute);
26
- return routes;
27
- }
28
-
29
- let routes: any[];
30
-
31
- /**
32
- *
33
- * Read more: https://docs.solidjs.com/solid-start/reference/routing/file-routes
34
- */
35
- export const FileRoutes = isServer
36
- ? () => (getRequestEvent() as PageEvent).routes
37
- : () => routes || (routes = createRoutes());
@@ -1,58 +0,0 @@
1
- // @refresh skip
2
- import type { Component } from "solid-js";
3
- import { Hydration, HydrationScript, NoHydration, getRequestEvent, ssr } from "solid-js/web";
4
- import App from "solid-start:app";
5
-
6
- import { ErrorBoundary, TopErrorBoundary } from "../shared/ErrorBoundary.tsx";
7
- import { useAssets } from "./assets/index.ts";
8
- import PatchVirtualDevStyles from "./assets/PatchVirtualDevStyles.tsx";
9
- import { getSsrManifest } from "./manifest/ssr-manifest.ts";
10
- import type { DocumentComponentProps, PageEvent } from "./types.ts";
11
-
12
- const docType = ssr("<!DOCTYPE html>");
13
-
14
- /**
15
- *
16
- * Read more: https://docs.solidjs.com/solid-start/reference/server/start-server
17
- */
18
- export function StartServer(props: { document: Component<DocumentComponentProps> }) {
19
- const context = getRequestEvent() as PageEvent;
20
-
21
- // @ts-ignore
22
- const nonce = context.nonce;
23
- useAssets(context.assets, nonce);
24
-
25
- return (
26
- <NoHydration>
27
- {docType as unknown as any}
28
- <TopErrorBoundary>
29
- <props.document
30
- assets={<HydrationScript />}
31
- scripts={
32
- <>
33
- <PatchVirtualDevStyles nonce={nonce} />
34
- <script
35
- type="module"
36
- nonce={nonce}
37
- async
38
- src={getSsrManifest("client").path(import.meta.env.START_CLIENT_ENTRY)}
39
- />
40
- </>
41
- }
42
- >
43
- {!import.meta.env.START_ISLANDS ? (
44
- <Hydration>
45
- <ErrorBoundary>
46
- <App />
47
- </ErrorBoundary>
48
- </Hydration>
49
- ) : (
50
- <ErrorBoundary>
51
- <App />
52
- </ErrorBoundary>
53
- )}
54
- </props.document>
55
- </TopErrorBoundary>
56
- </NoHydration>
57
- );
58
- }
@@ -1,31 +0,0 @@
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<HTMLElement>("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
-
23
- const serializedPatch = `(${patch.toString()})();`;
24
-
25
- const PatchVirtualDevStyles = (props: { nonce?: string }) => {
26
- if (!import.meta.env.PROD) {
27
- return <script nonce={props.nonce} innerHTML={serializedPatch} />;
28
- }
29
- };
30
-
31
- export default PatchVirtualDevStyles;
@@ -1,70 +0,0 @@
1
- import { onCleanup, sharedConfig } from "solid-js";
2
- import { getRequestEvent, useAssets as useAssets_ } from "solid-js/web";
3
- import { renderAsset, type Asset } from "./render.tsx";
4
-
5
- const REGISTRY = Symbol("assetRegistry");
6
- const NOOP = () => "";
7
-
8
- type AssetEntity = {
9
- key: string;
10
- consumers: number;
11
- preloadEl?: HTMLLinkElement;
12
- ssrIdx?: number;
13
- };
14
- type Registry = Record<string, AssetEntity>;
15
-
16
- const keyAttrs = ["href", "rel", "data-vite-dev-id"] as const;
17
-
18
- const getEntity = (registry: Registry, asset: Asset) => {
19
- let key = asset.tag;
20
- for (const k of keyAttrs) {
21
- if (!(k in asset.attrs)) continue;
22
- key += `[${k}='${asset.attrs[k as keyof Asset["attrs"]]}']`;
23
- }
24
-
25
- const entity = (registry[key] ??= {
26
- key,
27
- consumers: 0,
28
- });
29
-
30
- return entity;
31
- };
32
-
33
- export const useAssets = (assets: Asset[], nonce?: string) => {
34
- if (!assets.length) return;
35
-
36
- const registry: Registry = (getRequestEvent()!.locals[REGISTRY] ??= {});
37
- const ssrRequestAssets: Function[] = (sharedConfig.context as any)?.assets;
38
- const cssKeys: string[] = [];
39
-
40
- for (const asset of assets) {
41
- const entity = getEntity(registry, asset);
42
- const isCSSLink = asset.tag === "link" && asset.attrs.rel === "stylesheet";
43
- const isCSS = isCSSLink || asset.tag === "style";
44
- if (isCSS) {
45
- cssKeys.push(entity.key);
46
- }
47
-
48
- entity.consumers++;
49
- if (entity.consumers > 1) continue;
50
-
51
- // Mounting logic
52
- useAssets_(() => renderAsset(asset, nonce));
53
- entity.ssrIdx = ssrRequestAssets.length - 1;
54
- }
55
-
56
- onCleanup(() => {
57
- for (const key of cssKeys) {
58
- const entity = registry[key]!;
59
- entity.consumers--;
60
- if (entity.consumers != 0) {
61
- continue;
62
- }
63
-
64
- // Ideally this logic should be implemented directly in dom-expressions
65
- ssrRequestAssets.splice(entity.ssrIdx!, 1, NOOP);
66
-
67
- delete registry[key];
68
- }
69
- });
70
- };
@@ -1,46 +0,0 @@
1
- // @refresh skip
2
- import type { JSX } from "solid-js";
3
-
4
- const assetMap = {
5
- style: (props: { attrs: JSX.StyleHTMLAttributes<HTMLStyleElement>; children?: JSX.Element }) => (
6
- <style {...props.attrs}>{props.children}</style>
7
- ),
8
- link: (props: { attrs: JSX.LinkHTMLAttributes<HTMLLinkElement> }) => <link {...props.attrs} />,
9
- script: (props: {
10
- attrs: JSX.ScriptHTMLAttributes<HTMLScriptElement>;
11
- key: string | undefined;
12
- }) => {
13
- return props.attrs.src ? (
14
- <script {...props.attrs} id={props.key}>
15
- {" "}
16
- </script>
17
- ) : null;
18
- },
19
- noscript: (props: { attrs: JSX.HTMLAttributes<HTMLElement>; children: JSX.Element }) => (
20
- <noscript {...props.attrs}>{props.children}</noscript>
21
- ),
22
- };
23
-
24
- export function renderAsset(asset: Asset, nonce?: string) {
25
- let {
26
- tag,
27
- attrs: { key, ...attrs } = { key: undefined },
28
- children,
29
- } = asset as any;
30
- return (assetMap as any)[tag]({ attrs: { ...attrs, nonce }, key, children });
31
- }
32
-
33
- export type Asset =
34
- | {
35
- tag: "style";
36
- attrs: JSX.StyleHTMLAttributes<HTMLStyleElement> & { key?: string };
37
- children?: JSX.Element;
38
- }
39
- | {
40
- tag: "script";
41
- attrs: JSX.ScriptHTMLAttributes<HTMLScriptElement> & { key?: string };
42
- }
43
- | {
44
- tag: "link";
45
- attrs: JSX.LinkHTMLAttributes<HTMLLinkElement> & { key?: string };
46
- };