@solidjs/start 2.0.0-beta.1 → 2.0.0-beta.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.
Files changed (238) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/dist/client/StartClient.d.ts +7 -0
  3. package/{src/client/StartClient.tsx → dist/client/StartClient.jsx} +7 -15
  4. package/dist/client/index.jsx +2 -0
  5. package/dist/client/mount.d.ts +1 -0
  6. package/dist/client/mount.js +1 -0
  7. package/dist/client/spa/index.d.ts +4 -0
  8. package/dist/client/spa/index.jsx +5 -0
  9. package/dist/config/boundary-modules.d.ts +14 -0
  10. package/dist/config/boundary-modules.js +41 -0
  11. package/dist/config/constants.d.ts +16 -0
  12. package/dist/config/constants.js +16 -0
  13. package/dist/config/dev-server.d.ts +4 -0
  14. package/dist/config/dev-server.js +146 -0
  15. package/dist/config/env.d.ts +19 -0
  16. package/dist/config/env.js +85 -0
  17. package/dist/config/fs-router.d.ts +37 -0
  18. package/dist/config/fs-router.js +148 -0
  19. package/dist/config/fs-routes/fs-watcher.d.ts +3 -0
  20. package/dist/config/fs-routes/fs-watcher.js +53 -0
  21. package/dist/config/fs-routes/index.d.ts +7 -0
  22. package/dist/config/fs-routes/index.js +107 -0
  23. package/dist/config/fs-routes/router.d.ts +43 -0
  24. package/dist/config/fs-routes/router.js +146 -0
  25. package/dist/config/fs-routes/tree-shake.d.ts +2 -0
  26. package/dist/config/fs-routes/tree-shake.js +305 -0
  27. package/dist/config/index.d.ts +25 -0
  28. package/dist/config/index.js +252 -0
  29. package/dist/config/lazy.d.ts +3 -0
  30. package/dist/config/lazy.js +114 -0
  31. package/dist/config/manifest.d.ts +3 -0
  32. package/dist/config/manifest.js +109 -0
  33. package/dist/config/utils.d.ts +4 -0
  34. package/dist/config/utils.js +6 -0
  35. package/dist/config/vite-utils.d.ts +21 -0
  36. package/dist/config/vite-utils.js +85 -0
  37. package/dist/directives/bubble-function-declaration.d.ts +3 -0
  38. package/dist/directives/bubble-function-declaration.js +23 -0
  39. package/dist/directives/compile.d.ts +9 -0
  40. package/dist/directives/compile.js +40 -0
  41. package/dist/directives/generate-unique-name.d.ts +3 -0
  42. package/dist/directives/generate-unique-name.js +16 -0
  43. package/dist/directives/get-descriptive-name.d.ts +2 -0
  44. package/dist/directives/get-descriptive-name.js +37 -0
  45. package/dist/directives/get-import-identifier.d.ts +4 -0
  46. package/dist/directives/get-import-identifier.js +19 -0
  47. package/dist/directives/get-root-statement-path.d.ts +2 -0
  48. package/dist/directives/get-root-statement-path.js +12 -0
  49. package/dist/directives/index.d.ts +14 -0
  50. package/dist/directives/index.js +202 -0
  51. package/dist/directives/is-statement-top-level.d.ts +3 -0
  52. package/dist/directives/is-statement-top-level.js +9 -0
  53. package/dist/directives/paths.d.ts +9 -0
  54. package/dist/directives/paths.js +36 -0
  55. package/dist/directives/plugin.d.ts +21 -0
  56. package/dist/directives/plugin.js +302 -0
  57. package/dist/directives/remove-unused-variables.d.ts +3 -0
  58. package/dist/directives/remove-unused-variables.js +66 -0
  59. package/{src/directives/types.ts → dist/directives/types.d.ts} +5 -7
  60. package/dist/directives/types.js +1 -0
  61. package/dist/directives/xxhash32.d.ts +6 -0
  62. package/dist/directives/xxhash32.js +193 -0
  63. package/dist/fns/client.d.ts +3 -0
  64. package/dist/fns/client.js +106 -0
  65. package/dist/fns/handler.d.ts +5 -0
  66. package/dist/fns/handler.js +305 -0
  67. package/dist/fns/registration.d.ts +3 -0
  68. package/dist/fns/registration.js +15 -0
  69. package/dist/fns/serialization.d.ts +6 -0
  70. package/dist/fns/serialization.js +208 -0
  71. package/dist/fns/server.d.ts +7 -0
  72. package/dist/fns/server.js +38 -0
  73. package/dist/fns/shared.d.ts +17 -0
  74. package/dist/fns/shared.js +105 -0
  75. package/dist/http/http.d.ts +81 -0
  76. package/dist/http/http.js +129 -0
  77. package/dist/http/index.d.ts +2 -0
  78. package/dist/http/index.js +6 -0
  79. package/{src/index.tsx → dist/index.d.ts} +0 -2
  80. package/dist/index.jsx +6 -0
  81. package/dist/middleware/index.d.ts +39 -0
  82. package/dist/middleware/index.js +60 -0
  83. package/dist/router.d.ts +6 -0
  84. package/dist/router.jsx +29 -0
  85. package/dist/server/StartServer.d.ts +9 -0
  86. package/dist/server/StartServer.jsx +34 -0
  87. package/dist/server/assets/PatchVirtualDevStyles.d.ts +4 -0
  88. package/{src/server/assets/PatchVirtualDevStyles.tsx → dist/server/assets/PatchVirtualDevStyles.jsx} +7 -10
  89. package/dist/server/assets/index.d.ts +2 -0
  90. package/dist/server/assets/index.js +52 -0
  91. package/dist/server/assets/render.d.ts +19 -0
  92. package/dist/server/assets/render.jsx +14 -0
  93. package/dist/server/collect-styles.d.ts +3 -0
  94. package/dist/server/collect-styles.js +57 -0
  95. package/dist/server/fetchEvent.d.ts +7 -0
  96. package/dist/server/fetchEvent.js +26 -0
  97. package/dist/server/handler.d.ts +6 -0
  98. package/dist/server/handler.js +218 -0
  99. package/dist/server/index.d.ts +9 -0
  100. package/{src/server/index.tsx → dist/server/index.jsx} +4 -19
  101. package/dist/server/manifest/client-manifest.d.ts +9 -0
  102. package/dist/server/manifest/client-manifest.js +6 -0
  103. package/dist/server/manifest/dev-client-manifest.d.ts +4 -0
  104. package/dist/server/manifest/dev-client-manifest.js +24 -0
  105. package/dist/server/manifest/dev-ssr-manifest.d.ts +5 -0
  106. package/dist/server/manifest/dev-ssr-manifest.js +23 -0
  107. package/dist/server/manifest/prod-client-manifest.d.ts +5 -0
  108. package/dist/server/manifest/prod-client-manifest.js +26 -0
  109. package/dist/server/manifest/prod-ssr-manifest.d.ts +6 -0
  110. package/dist/server/manifest/prod-ssr-manifest.js +85 -0
  111. package/dist/server/manifest/ssr-manifest.d.ts +4 -0
  112. package/dist/server/manifest/ssr-manifest.js +6 -0
  113. package/dist/server/routes.d.ts +23 -0
  114. package/dist/server/routes.js +74 -0
  115. package/dist/server/spa/StartServer.d.ts +9 -0
  116. package/dist/server/spa/StartServer.jsx +25 -0
  117. package/dist/server/spa/handler.d.ts +8 -0
  118. package/dist/server/spa/handler.js +20 -0
  119. package/{src/server/spa/index.tsx → dist/server/spa/index.d.ts} +0 -1
  120. package/dist/server/spa/index.jsx +5 -0
  121. package/dist/server/types.d.ts +75 -0
  122. package/dist/server/types.js +1 -0
  123. package/dist/server/util.d.ts +2 -0
  124. package/dist/server/util.js +8 -0
  125. package/dist/server/web-stream.d.ts +9 -0
  126. package/dist/server/web-stream.js +26 -0
  127. package/dist/shared/ErrorBoundary.d.ts +3 -0
  128. package/dist/shared/ErrorBoundary.jsx +36 -0
  129. package/dist/shared/GET.d.ts +5 -0
  130. package/dist/shared/GET.js +8 -0
  131. package/dist/shared/HttpHeader.d.ts +10 -0
  132. package/dist/shared/HttpHeader.jsx +38 -0
  133. package/dist/shared/HttpStatusCode.d.ts +9 -0
  134. package/dist/shared/HttpStatusCode.js +18 -0
  135. package/dist/shared/clientOnly.d.ts +12 -0
  136. package/dist/shared/clientOnly.js +27 -0
  137. package/dist/shared/dev-overlay/CodeView.d.ts +7 -0
  138. package/dist/shared/dev-overlay/CodeView.jsx +62 -0
  139. package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +9 -0
  140. package/dist/shared/dev-overlay/DevOverlayDialog.jsx +226 -0
  141. package/dist/shared/dev-overlay/createStackFrame.d.ts +9 -0
  142. package/dist/shared/dev-overlay/createStackFrame.js +56 -0
  143. package/dist/shared/dev-overlay/download.d.ts +1 -0
  144. package/dist/shared/dev-overlay/download.js +6 -0
  145. package/dist/shared/dev-overlay/get-source-map.d.ts +2 -0
  146. package/dist/shared/dev-overlay/get-source-map.js +25 -0
  147. package/dist/shared/dev-overlay/icons.d.ts +28 -0
  148. package/dist/shared/dev-overlay/icons.jsx +150 -0
  149. package/dist/shared/dev-overlay/index.d.ts +5 -0
  150. package/dist/shared/dev-overlay/index.jsx +39 -0
  151. package/dist/shared/lazy.d.ts +3 -0
  152. package/dist/shared/lazy.js +42 -0
  153. package/dist/shared/serverFunction.d.ts +6 -0
  154. package/dist/shared/serverFunction.js +8 -0
  155. package/dist/utils/debounce.d.ts +4 -0
  156. package/dist/utils/debounce.js +10 -0
  157. package/env.d.ts +12 -0
  158. package/package.json +10 -5
  159. package/scripts/build.js +0 -15
  160. package/scripts/validate-imports.js +0 -316
  161. package/src/client/mount.ts +0 -1
  162. package/src/client/spa/index.tsx +0 -9
  163. package/src/config/constants.ts +0 -19
  164. package/src/config/dev-server.ts +0 -161
  165. package/src/config/env.ts +0 -105
  166. package/src/config/fs-router.ts +0 -162
  167. package/src/config/fs-routes/fs-watcher.ts +0 -66
  168. package/src/config/fs-routes/index.ts +0 -136
  169. package/src/config/fs-routes/router.ts +0 -184
  170. package/src/config/fs-routes/tree-shake.ts +0 -324
  171. package/src/config/index.ts +0 -239
  172. package/src/config/lazy.ts +0 -132
  173. package/src/config/manifest.ts +0 -120
  174. package/src/config/utils.ts +0 -5
  175. package/src/config/vite-utils.ts +0 -113
  176. package/src/directives/bubble-function-declaration.ts +0 -33
  177. package/src/directives/compile.ts +0 -54
  178. package/src/directives/generate-unique-name.ts +0 -22
  179. package/src/directives/get-descriptive-name.ts +0 -39
  180. package/src/directives/get-import-identifier.ts +0 -34
  181. package/src/directives/get-root-statement-path.ts +0 -14
  182. package/src/directives/index.ts +0 -233
  183. package/src/directives/is-statement-top-level.ts +0 -13
  184. package/src/directives/paths.ts +0 -63
  185. package/src/directives/plugin.ts +0 -389
  186. package/src/directives/remove-unused-variables.ts +0 -70
  187. package/src/directives/xxhash32.ts +0 -214
  188. package/src/env.d.ts +0 -17
  189. package/src/fns/client.ts +0 -141
  190. package/src/fns/handler.spec.ts +0 -85
  191. package/src/fns/handler.ts +0 -287
  192. package/src/fns/registration.ts +0 -19
  193. package/src/fns/serialization.ts +0 -250
  194. package/src/fns/server.ts +0 -46
  195. package/src/fns/shared.ts +0 -116
  196. package/src/http/index.ts +0 -216
  197. package/src/internal.d.ts +0 -14
  198. package/src/middleware/index.ts +0 -92
  199. package/src/router.tsx +0 -37
  200. package/src/server/StartServer.tsx +0 -58
  201. package/src/server/assets/index.ts +0 -70
  202. package/src/server/assets/render.tsx +0 -46
  203. package/src/server/collect-styles.ts +0 -70
  204. package/src/server/fetchEvent.spec.ts +0 -85
  205. package/src/server/fetchEvent.ts +0 -36
  206. package/src/server/handler.ts +0 -261
  207. package/src/server/manifest/client-manifest.ts +0 -8
  208. package/src/server/manifest/dev-client-manifest.ts +0 -21
  209. package/src/server/manifest/dev-ssr-manifest.ts +0 -23
  210. package/src/server/manifest/prod-client-manifest.ts +0 -21
  211. package/src/server/manifest/prod-ssr-manifest.ts +0 -109
  212. package/src/server/manifest/ssr-manifest.ts +0 -10
  213. package/src/server/routes.ts +0 -126
  214. package/src/server/spa/StartServer.tsx +0 -42
  215. package/src/server/spa/handler.ts +0 -29
  216. package/src/server/types.ts +0 -82
  217. package/src/server/util.ts +0 -12
  218. package/src/shared/ErrorBoundary.tsx +0 -52
  219. package/src/shared/GET.ts +0 -8
  220. package/src/shared/HttpHeader.tsx +0 -42
  221. package/src/shared/HttpStatusCode.ts +0 -27
  222. package/src/shared/clientOnly.ts +0 -44
  223. package/src/shared/dev-overlay/CodeView.tsx +0 -90
  224. package/src/shared/dev-overlay/DevOverlayDialog.tsx +0 -316
  225. package/src/shared/dev-overlay/createStackFrame.ts +0 -74
  226. package/src/shared/dev-overlay/download.ts +0 -6
  227. package/src/shared/dev-overlay/env.d.ts +0 -4
  228. package/src/shared/dev-overlay/get-source-map.ts +0 -33
  229. package/src/shared/dev-overlay/icons.tsx +0 -456
  230. package/src/shared/dev-overlay/index.tsx +0 -63
  231. package/src/shared/lazy.ts +0 -52
  232. package/src/shared/serverFunction.ts +0 -10
  233. package/src/utils/debounce.ts +0 -10
  234. package/src/virtual.d.ts +0 -27
  235. package/tsconfig.json +0 -24
  236. package/vitest.config.ts +0 -9
  237. /package/{src/client/index.tsx → dist/client/index.d.ts} +0 -0
  238. /package/{src → dist}/shared/dev-overlay/styles.css +0 -0
@@ -1,82 +0,0 @@
1
- import type { H3Event } from "h3";
2
- import type { JSX } from "solid-js";
3
- import type { RequestEvent } from "solid-js/web";
4
-
5
- // export const FETCH_EVENT = "$FETCH";
6
-
7
- export type DocumentComponentProps = {
8
- assets?: JSX.Element;
9
- scripts: JSX.Element;
10
- children?: JSX.Element;
11
- };
12
-
13
- export type Asset =
14
- | {
15
- tag: "style";
16
- attrs: JSX.StyleHTMLAttributes<HTMLStyleElement> & { key?: string };
17
- children?: JSX.Element;
18
- }
19
- | {
20
- tag: "script";
21
- attrs: JSX.ScriptHTMLAttributes<HTMLScriptElement> & { key?: string };
22
- }
23
- | {
24
- tag: "link";
25
- attrs: JSX.LinkHTMLAttributes<HTMLLinkElement> & { key?: string };
26
- };
27
-
28
- export type HandlerOptions = {
29
- mode?: "sync" | "async" | "stream";
30
- nonce?: string;
31
- renderId?: string;
32
- onCompleteAll?: (options: { write: (v: any) => void }) => void;
33
- onCompleteShell?: (options: { write: (v: any) => void }) => void;
34
- };
35
-
36
- export type ContextMatches = {
37
- originalPath: string;
38
- pattern: string;
39
- path: string;
40
- params: unknown;
41
- };
42
-
43
- export interface ResponseStub {
44
- status?: number;
45
- statusText?: string;
46
- headers: Headers;
47
- }
48
-
49
- export interface FetchEvent {
50
- request: Request;
51
- response: ResponseStub;
52
- clientAddress?: string;
53
- locals: App.RequestEventLocals;
54
- nativeEvent: H3Event;
55
- }
56
-
57
- export interface PageEvent extends RequestEvent {
58
- assets: any[];
59
- routes: any[];
60
- // prevUrl: string | null;
61
- // $type: typeof FETCH_EVENT;
62
- $islands: Set<string>;
63
- complete: boolean;
64
- nonce?: string;
65
- // mutation: boolean;
66
- }
67
-
68
- export interface APIEvent extends FetchEvent {
69
- params: { [key: string]: string };
70
- }
71
-
72
- export type APIHandler = (event: APIEvent) => any;
73
-
74
- export interface ServerFunctionMeta {
75
- id: string;
76
- }
77
-
78
- declare module "solid-js/web" {
79
- interface RequestEvent extends FetchEvent {
80
- serverOnly?: boolean;
81
- }
82
- }
@@ -1,12 +0,0 @@
1
- import type { ResponseStub } from "./types.ts";
2
-
3
- // according to https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages
4
- const validRedirectStatuses = new Set([301, 302, 303, 307, 308]);
5
-
6
- export function getExpectedRedirectStatus(response: ResponseStub): number {
7
- if (response.status && validRedirectStatuses.has(response.status)) {
8
- return response.status;
9
- }
10
-
11
- return 302;
12
- }
@@ -1,52 +0,0 @@
1
- // @refresh skip
2
- import { ErrorBoundary as DefaultErrorBoundary, catchError, type ParentProps } from "solid-js";
3
- import { isServer } from "solid-js/web";
4
- import { HttpStatusCode } from "./HttpStatusCode.ts";
5
- import { DevOverlay } from "./dev-overlay/index.tsx";
6
-
7
- export const ErrorBoundary =
8
- import.meta.env.DEV && import.meta.env.START_DEV_OVERLAY
9
- ? (props: ParentProps) => <DevOverlay>{props.children}</DevOverlay>
10
- : (props: ParentProps) => {
11
- const message = isServer
12
- ? "500 | Internal Server Error"
13
- : "Error | Uncaught Client Exception";
14
- return (
15
- <DefaultErrorBoundary
16
- fallback={error => {
17
- console.error(error);
18
- return (
19
- <>
20
- <span style="font-size:1.5em;text-align:center;position:fixed;left:0px;bottom:55%;width:100%;">
21
- {message}
22
- </span>
23
- <HttpStatusCode code={500} />
24
- </>
25
- );
26
- }}
27
- >
28
- {props.children}
29
- </DefaultErrorBoundary>
30
- );
31
- };
32
-
33
- export const TopErrorBoundary = (props: ParentProps) => {
34
- let isError = false;
35
- const res = catchError(
36
- () => props.children,
37
- err => {
38
- console.error(err);
39
- isError = !!err;
40
- },
41
- );
42
- return isError ? (
43
- <>
44
- <span style="font-size:1.5em;text-align:center;position:fixed;left:0px;bottom:55%;width:100%;">
45
- 500 | Internal Server Error
46
- </span>
47
- <HttpStatusCode code={500} />
48
- </>
49
- ) : (
50
- res
51
- );
52
- };
package/src/shared/GET.ts DELETED
@@ -1,8 +0,0 @@
1
- // @refresh skip
2
- /**
3
- *
4
- * Read more: https://docs.solidjs.com/solid-start/reference/server/get
5
- */
6
- export function GET<T extends (...args: any[]) => any>(fn: T) {
7
- return (fn as any).GET as (...args: Parameters<T>) => ReturnType<T>;
8
- }
@@ -1,42 +0,0 @@
1
- // @refresh skip
2
- import { onCleanup } from "solid-js";
3
- import { getRequestEvent, isServer } from "solid-js/web";
4
-
5
- import type { PageEvent } from "../server/types.ts";
6
- import { appendHeader, setHeader } from "../http/index.ts";
7
-
8
- export interface HttpHeaderProps {
9
- name: string;
10
- value: string;
11
- append?: boolean;
12
- }
13
-
14
- /**
15
- *
16
- * Read more: https://docs.solidjs.com/solid-start/reference/server/http-header
17
- */
18
- export const HttpHeader = isServer
19
- ? (props: HttpHeaderProps) => {
20
- const event = getRequestEvent() as PageEvent;
21
-
22
- if (props.append) appendHeader(props.name, props.value);
23
- else setHeader(props.name, props.value);
24
-
25
- onCleanup(() => {
26
- // @ts-expect-error
27
- if (event.nativeEvent.handled || event.complete) return;
28
- const value = event.response.headers.get(props.name);
29
- if (!value) return;
30
- if (!value.includes(", ")) {
31
- if (value === props.value) event.response.headers.delete(props.name);
32
- return;
33
- }
34
- const values = value.split(", ");
35
- const index = values.indexOf(props.value);
36
- index !== -1 && values.splice(index, 1);
37
- if (values.length) event.response.headers.set(props.name, values.join(","));
38
- else event.response.headers.delete(props.name);
39
- });
40
- return null;
41
- }
42
- : (_props: HttpHeaderProps) => null;
@@ -1,27 +0,0 @@
1
- // @refresh skip
2
- import { onCleanup } from "solid-js";
3
- import { getRequestEvent, isServer } from "solid-js/web";
4
- import type { PageEvent } from "../server/types.ts";
5
-
6
- export interface HttpStatusCodeProps {
7
- code: number;
8
- text?: string;
9
- }
10
-
11
- /**
12
- *
13
- * Read more: https://docs.solidjs.com/solid-start/reference/server/http-status-code
14
- */
15
- export const HttpStatusCode = isServer
16
- ? (props: HttpStatusCodeProps) => {
17
- const event = getRequestEvent() as PageEvent;
18
- event.response.status = props.code;
19
- event.response.statusText = props.text;
20
- onCleanup(
21
- () =>
22
- // !event.nativeEvent.handled &&
23
- !event.complete && (event.response.status = 200),
24
- );
25
- return null;
26
- }
27
- : (_props: HttpStatusCodeProps) => null;
@@ -1,44 +0,0 @@
1
- // @refresh skip
2
- import type { Component, ComponentProps, JSX, Setter } from "solid-js";
3
- import { createMemo, createSignal, onMount, sharedConfig, splitProps, untrack } from "solid-js";
4
- import { isServer } from "solid-js/web";
5
-
6
- /**
7
- *
8
- * Read more: https://docs.solidjs.com/solid-start/reference/client/client-only
9
- */
10
- // not using Suspense
11
- export default function clientOnly<T extends Component<any>>(
12
- fn: () => Promise<{
13
- default: T;
14
- }>,
15
- options: { lazy?: boolean } = {},
16
- ) {
17
- if (isServer) return (props: ComponentProps<T> & { fallback?: JSX.Element }) => props.fallback;
18
-
19
- const [comp, setComp] = createSignal<T>();
20
- !options.lazy && load(fn, setComp);
21
- return (props: ComponentProps<T>) => {
22
- let Comp: T | undefined;
23
- let m: boolean;
24
- const [, rest] = splitProps(props, ["fallback"]);
25
- options.lazy && load(fn, setComp);
26
- if ((Comp = comp()) && !sharedConfig.context) return Comp(rest);
27
- const [mounted, setMounted] = createSignal(!sharedConfig.context);
28
- onMount(() => setMounted(true));
29
- return createMemo(
30
- () => (
31
- (Comp = comp()), (m = mounted()), untrack(() => (Comp && m ? Comp(rest) : props.fallback))
32
- ),
33
- );
34
- };
35
- }
36
-
37
- function load<T>(
38
- fn: () => Promise<{
39
- default: T;
40
- }>,
41
- setComp: Setter<T>,
42
- ) {
43
- fn().then(m => setComp(() => m.default));
44
- }
@@ -1,90 +0,0 @@
1
- // @refresh skip
2
- import { type BuiltinLanguage, getSingletonHighlighter, type Highlighter } from "shiki";
3
- import { loadWasm } from "shiki/engine/oniguruma";
4
- import langJS from "shiki/langs/javascript.mjs";
5
- import langJSX from "shiki/langs/jsx.mjs";
6
- import langTSX from "shiki/langs/tsx.mjs";
7
- import langTS from "shiki/langs/typescript.mjs";
8
- import url from "shiki/onig.wasm?url";
9
- import darkPlus from "shiki/themes/dark-plus.mjs";
10
- import { createEffect, createResource, type JSX } from "solid-js";
11
-
12
- let HIGHLIGHTER: Highlighter;
13
-
14
- async function loadHighlighter() {
15
- if (!HIGHLIGHTER) {
16
- await loadWasm(await fetch(url));
17
- HIGHLIGHTER = await getSingletonHighlighter({
18
- themes: [darkPlus],
19
- langs: [langJS, langJSX, langTS, langTSX],
20
- });
21
- }
22
- return HIGHLIGHTER;
23
- }
24
-
25
- export interface CodeViewProps {
26
- fileName: string;
27
- content: string;
28
- line: number;
29
- }
30
-
31
- const RANGE = 8;
32
-
33
- export function CodeView(props: CodeViewProps): JSX.Element | null {
34
- const lines = () =>
35
- props.content.split("\n").map((item, index) => ({
36
- index: index + 1,
37
- line: item,
38
- }));
39
-
40
- const minLine = () => Math.max(props.line - (1 + RANGE), 0);
41
- const maxLine = () => Math.min(props.line + RANGE, lines().length - 1);
42
-
43
- let ref: HTMLDivElement | undefined;
44
-
45
- const [data] = createResource(
46
- () =>
47
- lines()
48
- .slice(minLine(), maxLine())
49
- .map(item => item.line)
50
- .join("\n"),
51
- async value => {
52
- const highlighter = await loadHighlighter();
53
- const fileExtension = props.fileName.split(/[#?]/)[0]!.split(".").pop()?.trim();
54
- let lang = fileExtension as BuiltinLanguage;
55
- if (fileExtension === "mjs" || fileExtension === "cjs") {
56
- lang = "js";
57
- }
58
- return highlighter.codeToHtml(value, {
59
- theme: "dark-plus",
60
- lang,
61
- });
62
- },
63
- );
64
-
65
- createEffect(() => {
66
- const result = data();
67
- if (ref && result) {
68
- ref.innerHTML = result;
69
-
70
- const lines = ref.querySelectorAll('span[class="line"]');
71
-
72
- for (let i = 0, len = lines.length; i < len; i++) {
73
- const el = lines[i] as HTMLElement;
74
- if (props.line - minLine() - 1 === i) {
75
- el.dataset.startDevOverlayErrorLine = '';
76
- }
77
- }
78
- }
79
- });
80
-
81
- return (
82
- <div
83
- ref={ref}
84
- data-start-dev-overlay-code-view
85
- style={{
86
- "--dev-overlay-code-view-start": minLine() + 1,
87
- }}
88
- />
89
- );
90
- }
@@ -1,316 +0,0 @@
1
- // @refresh skip
2
- import ErrorStackParser from "error-stack-parser";
3
- import * as htmlToImage from "html-to-image";
4
- import type { JSX } from "solid-js";
5
- import { createMemo, createSignal, ErrorBoundary, For, Show, Suspense } from "solid-js";
6
- import { Portal } from "solid-js/web";
7
- // @ts-ignore - terracotta module resolution issue with NodeNext
8
- import { Dialog, DialogOverlay, DialogPanel, Select, SelectOption } from "terracotta";
9
- import info from "../../../package.json" with { type: "json" };
10
- import { CodeView } from "./CodeView.tsx";
11
- import { createStackFrame, type StackFrameSource } from "./createStackFrame.ts";
12
- import download from "./download.ts";
13
- import {
14
- ArrowLeftIcon,
15
- ArrowRightIcon,
16
- CameraIcon,
17
- DiscordIcon,
18
- GithubIcon,
19
- RefreshIcon,
20
- SolidStartIcon,
21
- ViewCompiledIcon,
22
- ViewOriginalIcon,
23
- } from "./icons.tsx";
24
- import "./styles.css";
25
-
26
- export function classNames(...classes: (string | boolean | undefined)[]): string {
27
- return classes.filter(Boolean).join(" ");
28
- }
29
-
30
- interface ErrorInfoProps {
31
- error: unknown;
32
- }
33
-
34
- function ErrorInfo(props: ErrorInfoProps): JSX.Element {
35
- const error = createMemo(() => {
36
- const e = props.error;
37
-
38
- if (e instanceof Error) {
39
- return { name: e.name, message: e.message };
40
- }
41
-
42
- if (e instanceof ErrorEvent) {
43
- return { message: e.message };
44
- }
45
-
46
- return { message: (e as Error).toString() };
47
- });
48
-
49
- return (
50
- <span data-start-dev-overlay-error-info>
51
- <span data-start-dev-overlay-error-info-name>{error().name}</span>
52
- <span data-start-dev-overlay-error-info-message>{error().message}</span>
53
- </span>
54
- );
55
- }
56
-
57
- interface StackFramesContentProps {
58
- error: Error;
59
- isCompiled: boolean;
60
- }
61
-
62
- function getFileName(source: string): string {
63
- try {
64
- const path = source.startsWith("/") ? new URL(source, "file://") : new URL(source);
65
- const paths = path.pathname.split("/");
66
- return paths[paths.length - 1]!;
67
- } catch (error) {
68
- return getFileName(`/${source}`);
69
- }
70
- }
71
-
72
- function getFilePath(source: StackFrameSource) {
73
- const line = source.line ? `:${source.line}` : "";
74
- const column = source.column ? `:${source.column}` : "";
75
- return `${getFileName(source.source)}${line}${column}`;
76
- }
77
-
78
- function CodeFallback(): JSX.Element {
79
- return (
80
- <div data-start-dev-overlay-stack-frames-code-fallback>
81
- <span>Source not available.</span>
82
- </div>
83
- );
84
- }
85
-
86
- function StackFramesContent(props: StackFramesContentProps) {
87
- const stackframes = ErrorStackParser.parse(props.error);
88
-
89
- const [selectedFrame, setSelectedFrame] = createSignal(stackframes[0]!);
90
-
91
- return (
92
- <div data-start-dev-overlay-stack-frames-content>
93
- <div data-start-dev-overlay-stack-frames-code>
94
- <ErrorBoundary fallback={null}>
95
- {(() => {
96
- const data = createStackFrame(selectedFrame(), () => props.isCompiled);
97
- return (
98
- <Suspense fallback={<CodeFallback />}>
99
- <Show when={data()} keyed fallback={<CodeFallback />}>
100
- {source => (
101
- <>
102
- <span data-start-dev-overlay-stack-frames-code-source>{source.source}</span>
103
- <div data-start-dev-overlay-stack-frames-code-container>
104
- <CodeView
105
- fileName={source.source}
106
- line={source.line}
107
- content={source.content}
108
- />
109
- </div>
110
- </>
111
- )}
112
- </Show>
113
- </Suspense>
114
- );
115
- })()}
116
- </ErrorBoundary>
117
- </div>
118
- <Select<ErrorStackParser.StackFrame>
119
- data-start-dev-overlay-stack-frames
120
- value={selectedFrame()}
121
- onChange={setSelectedFrame}
122
- >
123
- <For each={stackframes}>
124
- {current => (
125
- <ErrorBoundary
126
- fallback={
127
- <div data-start-dev-overlay-stack-frame>
128
- <span data-start-dev-overlay-stack-frame-function>
129
- {current.functionName ?? "<anonymous>"}
130
- </span>
131
- <span data-start-dev-overlay-stack-frame-file>
132
- {getFilePath({
133
- source: current.getFileName()!,
134
- content: "",
135
- line: current.getLineNumber()!,
136
- column: current.getColumnNumber()!,
137
- name: current.getFunctionName(),
138
- })}
139
- </span>
140
- </div>
141
- }
142
- >
143
- {(() => {
144
- const data = createStackFrame(current, () => props.isCompiled);
145
- return (
146
- <Suspense>
147
- <Show when={data()} keyed>
148
- {source => (
149
- <SelectOption data-start-dev-overlay-stack-frame value={current}>
150
- <span data-start-dev-overlay-stack-frame-function>
151
- {source.name ?? "<anonymous>"}
152
- </span>
153
- <span data-start-dev-overlay-stack-frame-file>{getFilePath(source)}</span>
154
- </SelectOption>
155
- )}
156
- </Show>
157
- </Suspense>
158
- );
159
- })()}
160
- </ErrorBoundary>
161
- )}
162
- </For>
163
- </Select>
164
- </div>
165
- );
166
- }
167
-
168
- interface StackFramesProps {
169
- error: unknown;
170
- isCompiled: boolean;
171
- }
172
-
173
- function StackFrames(props: StackFramesProps) {
174
- return (
175
- <Show when={props.error instanceof Error && props.error} keyed>
176
- {current => <StackFramesContent error={current} isCompiled={props.isCompiled} />}
177
- </Show>
178
- );
179
- }
180
-
181
- interface DevOverlayDialogProps {
182
- errors: any[];
183
- resetError: () => void;
184
- }
185
-
186
- const ISSUE_THREAD = "https://github.com/solidjs/solid-start/issues/new";
187
- const DISCORD_INVITE = "https://discord.com/invite/solidjs";
188
-
189
- export default function DevOverlayDialog(props: DevOverlayDialogProps): JSX.Element {
190
- const [currentPage, setCurrentPage] = createSignal(1);
191
- const [isCompiled, setIsCompiled] = createSignal(false);
192
- const length = createMemo(() => props.errors.length);
193
-
194
- const truncated = createMemo(() => {
195
- return Math.min(currentPage(), length());
196
- });
197
-
198
- function goPrev() {
199
- setCurrentPage(c => {
200
- if (c > 1) {
201
- return c - 1;
202
- }
203
- return length();
204
- });
205
- }
206
-
207
- function goNext() {
208
- setCurrentPage(c => {
209
- if (c < length()) {
210
- return c + 1;
211
- }
212
- return 1;
213
- });
214
- }
215
-
216
- function toggleIsCompiled() {
217
- setIsCompiled(c => !c);
218
- }
219
-
220
- const [panel, setPanel] = createSignal<HTMLElement>();
221
-
222
- function downloadScreenshot() {
223
- const current = panel();
224
- if (current) {
225
- htmlToImage
226
- .toPng(current, {
227
- style: {
228
- transform: "scale(0.75)",
229
- },
230
- })
231
- .then(url => {
232
- download(url, "start-screenshot.png");
233
- });
234
- }
235
- }
236
-
237
- function redirectToGithub() {
238
- const url = new URL(ISSUE_THREAD);
239
- url.searchParams.append("labels", "bug");
240
- url.searchParams.append("labels", "needs+triage");
241
- url.searchParams.append("template", "bug.yml");
242
- url.searchParams.append("title", `[Bug?]:` + props.errors[truncated() - 1].toString());
243
- window.open(url, "_blank")!.focus();
244
- }
245
-
246
- function redirectToDiscord() {
247
- window.open(DISCORD_INVITE, "_blank")!.focus();
248
- }
249
-
250
- return (
251
- <Portal>
252
- <Dialog data-start-dev-overlay isOpen>
253
- <div>
254
- <DialogOverlay data-start-dev-overlay-background />
255
- <DialogPanel ref={setPanel} data-start-dev-overlay-panel-container>
256
- <div data-start-dev-overlay-panel>
257
- <div data-start-dev-overlay-navbar>
258
- <div data-start-dev-overlay-navbar-left>
259
- <div data-start-dev-overlay-version>
260
- <div>
261
- <SolidStartIcon title="Solid Start Version" />
262
- </div>
263
- <span>{info.version as string}</span>
264
- </div>
265
- <Show when={props.errors.length > 1}>
266
- <div data-start-dev-overlay-pagination>
267
- <button data-start-dev-overlay-button onClick={goPrev} type="button">
268
- <ArrowLeftIcon title="Go Previous" />
269
- </button>
270
- <div data-start-dev-overlay-page-counter>
271
- {`${truncated()} of ${props.errors.length}`}
272
- </div>
273
- <button data-start-dev-overlay-button onClick={goNext} type="button">
274
- <ArrowRightIcon title="Go Next" />
275
- </button>
276
- </div>
277
- </Show>
278
- </div>
279
- <div data-start-dev-overlay-controls>
280
- <button data-start-dev-overlay-button onClick={redirectToGithub} type="button">
281
- <GithubIcon title="Create an issue thread on Github" />
282
- </button>
283
- <button data-start-dev-overlay-button onClick={redirectToDiscord} type="button">
284
- <DiscordIcon title="Join our Discord Channel" />
285
- </button>
286
- <button data-start-dev-overlay-button onClick={downloadScreenshot} type="button">
287
- <CameraIcon title="Capture Error Overlay" />
288
- </button>
289
- <button data-start-dev-overlay-button onClick={toggleIsCompiled} type="button">
290
- <Show
291
- when={isCompiled()}
292
- fallback={<ViewOriginalIcon title="View Original Source" />}
293
- >
294
- <ViewCompiledIcon title="View Compiled Source" />
295
- </Show>
296
- </button>
297
- <button data-start-dev-overlay-button onClick={props.resetError} type="button">
298
- <RefreshIcon title="Reset Error" />
299
- </button>
300
- </div>
301
- </div>
302
- <Show when={props.errors[truncated() - 1]} keyed>
303
- {current => (
304
- <div data-start-dev-overlay-content>
305
- <ErrorInfo error={current} />
306
- <StackFrames error={current} isCompiled={isCompiled()} />
307
- </div>
308
- )}
309
- </Show>
310
- </div>
311
- </DialogPanel>
312
- </div>
313
- </Dialog>
314
- </Portal>
315
- );
316
- }