@solidjs/start 2.0.0-rc.7 → 2.0.0-rc.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @solidjs/start
2
2
 
3
+ ## 2.0.0-rc.9
4
+
5
+ ### Patch Changes
6
+
7
+ - 8eef552: Remove type-only import remnants from client server-function transforms so they do not retain server-only dependency chains.
8
+
9
+ ## 2.0.0-rc.8
10
+
11
+ ### Patch Changes
12
+
13
+ - 3573985: Await asynchronous `serverFunctions.onError` handlers before serializing server function errors.
14
+ Preserve the original error if the handler throws or rejects.
15
+
3
16
  ## 2.0.0-rc.7
4
17
 
5
18
  ### Patch Changes
@@ -131,14 +131,17 @@ export interface SolidStartOptions {
131
131
  * straight to its caller, and errors from API routes never reach it
132
132
  * either.
133
133
  *
134
- * The export is called synchronously with the thrown value, and what it
135
- * returns decides what the client sees:
134
+ * The handler may be asynchronous. SolidStart awaits its return value
135
+ * before serializing the response, allowing a monitoring service to flush
136
+ * first. The resolved value decides what the client sees:
136
137
  *
137
138
  * - `undefined` (or `null`) sends what was thrown, unchanged.
138
139
  * - A `Response` is passed through unchanged, which keeps a thrown
139
140
  * `redirect()` working.
140
141
  * - Any other value is sent in place of what was thrown, and the client
141
142
  * call rejects with it.
143
+ * - If the handler throws or rejects, what the server function threw is
144
+ * sent unchanged.
142
145
  *
143
146
  * Control flow reaches the export the same way errors do, so a handler
144
147
  * that replaces everything it sees turns redirects into errors.
@@ -147,10 +150,6 @@ export interface SolidStartOptions {
147
150
  * properties, so an error meant to be safe to expose must not carry
148
151
  * internal detail.
149
152
  *
150
- * The return value is not awaited, so make the export a plain function
151
- * rather than an `async` one, and report failures with calls that do not
152
- * need awaiting.
153
- *
154
153
  * Type the export as `ServerFunctionErrorHandler` from
155
154
  * `@solidjs/start/server`. The module is bundled into the server only, so
156
155
  * it may import server-only code such as a monitoring SDK.
@@ -12,6 +12,18 @@ function isInvalidForRemoval(path) {
12
12
  }
13
13
  return isPathValid(target, t.isObjectPattern) || isPathValid(target, t.isArrayPattern);
14
14
  }
15
+ function countValidImport(node) {
16
+ if (node.importKind === "type") {
17
+ return 0;
18
+ }
19
+ let count = 0;
20
+ for (const specifier of node.specifiers) {
21
+ if (specifier.type !== "ImportSpecifier" || specifier.importKind === "value") {
22
+ count += 1;
23
+ }
24
+ }
25
+ return count;
26
+ }
15
27
  export function removeUnusedVariables(program) {
16
28
  // TODO(Alexis):
17
29
  // This implementation is simple but slow
@@ -34,7 +46,7 @@ export function removeUnusedVariables(program) {
34
46
  if (binding.references === 0 && !binding.path.removed) {
35
47
  const parent = binding.path.parentPath;
36
48
  if (isPathValid(parent, t.isImportDeclaration)) {
37
- if (parent.node.specifiers.length === 1) {
49
+ if (countValidImport(parent.node) <= 1) {
38
50
  parent.remove();
39
51
  }
40
52
  else {
@@ -3,14 +3,15 @@
3
3
  * it to type the default export of the module named by the
4
4
  * `serverFunctions.onError` option in `vite.config.ts`.
5
5
  *
6
- * Called synchronously, and the value it returns is not awaited, so it cannot
7
- * be an `async` function.
6
+ * The handler may be asynchronous. SolidStart awaits its return value before
7
+ * sending the error to the client. If the handler throws or rejects, SolidStart
8
+ * sends the original thrown value instead.
8
9
  *
9
10
  * @param thrown The value the server function threw. This is a `Response` when
10
11
  * the server function threw control flow such as a `redirect()`.
11
12
  * @returns `undefined` (or `null`) to send `thrown` unchanged, a `Response` to
12
- * pass control flow through untouched, or any other value to send in place of
13
- * `thrown`.
13
+ * preserve control flow, any other replacement value, or a promise resolving
14
+ * to any of those values.
14
15
  *
15
16
  * @example
16
17
  * ```ts
@@ -30,4 +31,4 @@
30
31
  * ```
31
32
  */
32
33
  export type ServerFunctionErrorHandler = (thrown: unknown) => unknown;
33
- export declare function applyServerFunctionErrorHandler(thrown: unknown): unknown;
34
+ export declare function applyServerFunctionErrorHandler(thrown: unknown): Promise<unknown>;
@@ -1,4 +1,10 @@
1
1
  import onServerFunctionError from "solid-start:server-fn-error-handler";
2
- export function applyServerFunctionErrorHandler(thrown) {
3
- return onServerFunctionError?.(thrown) ?? thrown;
2
+ export async function applyServerFunctionErrorHandler(thrown) {
3
+ try {
4
+ const replacement = await onServerFunctionError?.(thrown);
5
+ return replacement ?? thrown;
6
+ }
7
+ catch {
8
+ return thrown;
9
+ }
4
10
  }
@@ -125,7 +125,7 @@ export async function handleServerFunction(h3Event) {
125
125
  return serializeToJSONStream(result);
126
126
  }
127
127
  catch (x) {
128
- x = applyServerFunctionErrorHandler(x);
128
+ x = await applyServerFunctionErrorHandler(x);
129
129
  if (x instanceof Response) {
130
130
  if (singleFlight && instance) {
131
131
  x = await handleSingleFlight(event, x);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/start",
3
- "version": "2.0.0-rc.7",
3
+ "version": "2.0.0-rc.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/solidjs/solid-start.git",