@solidjs/router 2.0.0-next.28 → 2.0.0-next.30

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.
@@ -1,9 +1,6 @@
1
1
  import { $TRACK, action as createSolidAction, createMemo, onCleanup, getOwner } from "solid-js";
2
2
  import { isResponseEnvelope, isServer, REVALIDATE_HEADER } from "@solidjs/web";
3
3
  import { createServerReference, decodeRedirectHeaderValue, decodeResponsePayload, parseServerFunctionActionUrl, REDIRECT_HEADER, subscribeFlightData } from "@solidjs/web/server-functions";
4
- // The explicit /server specifier is safe here: the only call site is
5
- // server-guarded, so client builds tree-shake the codec away.
6
- import { decodeFlashCookie } from "@solidjs/web/server-functions/server";
7
4
  import { provideFlashDecoder, provideFlightConsumer, useRouter } from "../routing.js";
8
5
  import { setRouterFormHandler } from "./events.js";
9
6
  import { mockBase, setFunctionName } from "../utils.js";
@@ -116,10 +113,16 @@ function installRouterIntegrations() {
116
113
  return;
117
114
  integrationsInstalled = true;
118
115
  if (isServer) {
119
- // Server-only: initSubmissions only decodes during SSR, so client builds
120
- // tree-shake the codec (which now lives behind the runtime's server entry).
121
- // The codec is async from @solidjs/web 2.0.0-rc.7 (encrypted cookie).
122
- provideFlashDecoder(decodeFlashCookie);
116
+ // The codec lives behind the runtime's SERVER entry, which must stay off
117
+ // the client module graph entirely — a static import here shipped it to
118
+ // every Vite dev page (#616; prod tree-shook it, dev doesn't shake). The
119
+ // decoder slot must still fill synchronously (a cold-start POST-redirect-
120
+ // GET reads submissions on the very first render), so install a wrapper
121
+ // and let the first decode pull the module: the codec is async anyway
122
+ // (encrypted cookie, @solidjs/web 2.0.0-rc.7+) and the seeding read
123
+ // already parks on the decode promise; a failed load reads as "no flash",
124
+ // the runtime's own malformed-cookie semantics.
125
+ provideFlashDecoder(cookieHeader => import("@solidjs/web/server-functions/server").then(m => m.decodeFlashCookie(cookieHeader)));
123
126
  }
124
127
  else {
125
128
  setRouterFormHandler(handleFormAction);
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { getOwner, runWithOwner, createMemo, createRenderEffect, onCleanup, untrack, createContext, createSignal, useContext, NotReadyError, isPending, DEV, latest, createComponent, createRoot, Show, createEffect, sharedConfig, OBSERVE, onSettled, getObserver, $TRACK, action as action$1 } from 'solid-js';
2
2
  import { registerElementClaim, delegateEvents, isServer, getRequestEvent, hasFlashCookie, clearFlashCookie, createComponent as createComponent$1, memo, dynamic, isServerFunction, getServerFunctionMetadata, getServerFunctionRPC, isResponseEnvelope, REVALIDATE_HEADER } from '@solidjs/web';
3
3
  import { REDIRECT_HEADER, decodeRedirectHeaderValue, subscribeFlightData, decodeResponsePayload, parseServerFunctionActionUrl, createServerReference } from '@solidjs/web/server-functions';
4
- import { decodeFlashCookie } from '@solidjs/web/server-functions/server';
5
4
 
6
5
  const hasSchemeRegex = /^(?:[a-z0-9]+:)?\/\//i;
7
6
  const trimPathRegex = /^\/+|(\/)\/+$/g;
@@ -554,7 +553,6 @@ function serverRouteOf(component) {
554
553
  */
555
554
  function serverRouteArgs(route, params, query) {
556
555
  const schema = route.key?.search;
557
- let search;
558
556
  if (schema) {
559
557
  const raw = {
560
558
  ...query
@@ -562,13 +560,22 @@ function serverRouteArgs(route, params, query) {
562
560
  const outcome = validateSearch(schema, raw);
563
561
  // Issues leave the raw values in place, matching useSearchParams: search
564
562
  // strings are user input, so defaults belong in the schema itself.
565
- search = outcome.issues ? raw : outcome.value;
563
+ return {
564
+ params: {
565
+ ...params
566
+ },
567
+ search: outcome.issues ? raw : outcome.value
568
+ };
566
569
  }
570
+ // No schema: leave the key out rather than carrying `search: undefined` —
571
+ // the args are sent as plain JSON by default and the runtime's JSON-safety
572
+ // check rejects explicit `undefined` (#615). Destructuring on the server
573
+ // reads the same either way, and the args-memo equality treats an absent
574
+ // key and undefined alike.
567
575
  return {
568
576
  params: {
569
577
  ...params
570
- },
571
- search
578
+ }
572
579
  };
573
580
  }
574
581
  const shallowEqual = (a, b) => a === b || !!a && !!b && typeof a === "object" && typeof b === "object" && Object.keys(a).length === Object.keys(b).length && Object.keys(a).every(k => a[k] === b[k]);
@@ -3075,10 +3082,16 @@ function installRouterIntegrations() {
3075
3082
  if (integrationsInstalled) return;
3076
3083
  integrationsInstalled = true;
3077
3084
  if (isServer) {
3078
- // Server-only: initSubmissions only decodes during SSR, so client builds
3079
- // tree-shake the codec (which now lives behind the runtime's server entry).
3080
- // The codec is async from @solidjs/web 2.0.0-rc.7 (encrypted cookie).
3081
- provideFlashDecoder(decodeFlashCookie);
3085
+ // The codec lives behind the runtime's SERVER entry, which must stay off
3086
+ // the client module graph entirely — a static import here shipped it to
3087
+ // every Vite dev page (#616; prod tree-shook it, dev doesn't shake). The
3088
+ // decoder slot must still fill synchronously (a cold-start POST-redirect-
3089
+ // GET reads submissions on the very first render), so install a wrapper
3090
+ // and let the first decode pull the module: the codec is async anyway
3091
+ // (encrypted cookie, @solidjs/web 2.0.0-rc.7+) and the seeding read
3092
+ // already parks on the decode promise; a failed load reads as "no flash",
3093
+ // the runtime's own malformed-cookie semantics.
3094
+ provideFlashDecoder(cookieHeader => import('@solidjs/web/server-functions/server').then(m => m.decodeFlashCookie(cookieHeader)));
3082
3095
  } else {
3083
3096
  setRouterFormHandler(handleFormAction);
3084
3097
  provideFlightConsumer(setupFlightDataConsumer);
@@ -12,15 +12,19 @@ export function serverRouteOf(component) {
12
12
  */
13
13
  export function serverRouteArgs(route, params, query) {
14
14
  const schema = route.key?.search;
15
- let search;
16
15
  if (schema) {
17
16
  const raw = { ...query };
18
17
  const outcome = validateSearch(schema, raw);
19
18
  // Issues leave the raw values in place, matching useSearchParams: search
20
19
  // strings are user input, so defaults belong in the schema itself.
21
- search = outcome.issues ? raw : outcome.value;
20
+ return { params: { ...params }, search: outcome.issues ? raw : outcome.value };
22
21
  }
23
- return { params: { ...params }, search };
22
+ // No schema: leave the key out rather than carrying `search: undefined` —
23
+ // the args are sent as plain JSON by default and the runtime's JSON-safety
24
+ // check rejects explicit `undefined` (#615). Destructuring on the server
25
+ // reads the same either way, and the args-memo equality treats an absent
26
+ // key and undefined alike.
27
+ return { params: { ...params } };
24
28
  }
25
29
  const shallowEqual = (a, b) => a === b ||
26
30
  (!!a &&
package/dist/types.d.ts CHANGED
@@ -144,12 +144,21 @@ export type RouteSectionComponent<T = unknown, P extends Params = Params> = Comp
144
144
  /**
145
145
  * What a server component route is called with (experimental): the params
146
146
  * the route's pattern (and its ancestors') declares, plus — only when the
147
- * route declares a `search` schema — that schema's validated output.
147
+ * route declares a `search` schema — that schema's validated output. Without
148
+ * a schema the `search` key is ABSENT, not `undefined`: the args travel as
149
+ * plain JSON by default, and the runtime's JSON-safety check rejects
150
+ * explicit `undefined` (#615). The type mirrors that — optional exactly when
151
+ * the search type admits undefined, required when a schema narrows it.
148
152
  */
149
- export interface ServerRouteArgs<P extends Params | TypedRouteConfig = Params, S = undefined> {
153
+ export type ServerRouteArgs<P extends Params | TypedRouteConfig = Params, S = undefined> = {
150
154
  params: ServerRouteParams<P>;
151
- search: P extends TypedRouteConfig ? SearchOutputOf<P> : S;
152
- }
155
+ } & (undefined extends ServerRouteSearch<P, S> ? {
156
+ search?: ServerRouteSearch<P, S>;
157
+ } : {
158
+ search: ServerRouteSearch<P, S>;
159
+ });
160
+ /** The search half of {@link ServerRouteArgs}: schema output when declared. */
161
+ export type ServerRouteSearch<P, S> = P extends TypedRouteConfig ? SearchOutputOf<P> : S;
153
162
  /**
154
163
  * `ServerRouteArgs<typeof route>`: a `defineFileRoute` config is a witness —
155
164
  * params from its pattern, search from its schema — the way
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "Ryan Turnquist"
7
7
  ],
8
8
  "license": "MIT",
9
- "version": "2.0.0-next.28",
9
+ "version": "2.0.0-next.30",
10
10
  "homepage": "https://github.com/solidjs/solid-router#readme",
11
11
  "repository": {
12
12
  "type": "git",