@qwik.dev/router 2.0.0-rc.3 → 2.0.0-rc.5

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,7 +1,7 @@
1
- import { D as getRouteLoaderValues, O as getRouteLoaders, d as loadRoute } from "./head.qwik.mjs";
2
- import { l as trimInternalPathname } from "./request-path.mjs";
3
- import { i as resolveRequestHandlers, r as renderQwikMiddleware, t as runQwikRouter } from "./user-response.mjs";
4
- import { _serialize } from "@qwik.dev/core/internal";
1
+ import { S as getRouteLoaders, i as loadRoute, x as getRouteLoaderValues } from "./head.qwik.mjs";
2
+ import { u as trimInternalPathname } from "./request-path.mjs";
3
+ import { c as RequestEvHttpStatusMessage, i as resolveRequestHandlers, r as renderQwikMiddleware, t as runQwikRouter } from "./user-response.mjs";
4
+ import { _serialize } from "@qwik.dev/core/internal/serializer";
5
5
  import { parentPort } from "node:worker_threads";
6
6
  var staticWorkerThreadDeps = {
7
7
  loadRoute,
@@ -15,7 +15,12 @@ async function workerThread(sys) {
15
15
  const pendingPromises = /* @__PURE__ */ new Set();
16
16
  const deps = {
17
17
  ...staticWorkerThreadDeps,
18
- serialize: _serialize
18
+ serialize: _serialize,
19
+ announceFile: (pathname, filePath) => parentPort?.postMessage({
20
+ type: "file",
21
+ pathname,
22
+ filePath
23
+ })
19
24
  };
20
25
  process.on("uncaughtException", (e) => {
21
26
  console.error("Worker uncaught exception (suppressed):", e.message);
@@ -110,6 +115,13 @@ async function workerRender(sys, opts, staticRoute, pendingPromises, callback, d
110
115
  getWritableStream: (status, headers, _, _r, requestEv) => {
111
116
  const isNotFoundPage = url.pathname.endsWith("/404.html");
112
117
  result.ok = status >= 200 && status < 300 || isNotFoundPage && status === 404;
118
+ if (status >= 500) {
119
+ const statusMessage = requestEv.sharedMap.get(RequestEvHttpStatusMessage);
120
+ result.error = {
121
+ message: statusMessage ? `Responded with ${status}: ${statusMessage}` : `Responded with ${status}`,
122
+ stack: void 0
123
+ };
124
+ }
113
125
  if (!result.ok) return createNoopWritableStream();
114
126
  result.contentType = (headers.get("Content-Type") || "").toLowerCase();
115
127
  const isHtml = result.contentType.includes("text/html");
@@ -122,6 +134,7 @@ async function workerRender(sys, opts, staticRoute, pendingPromises, callback, d
122
134
  try {
123
135
  if (hasRouteWriter || writeLoaderDataEnabled) await sys.ensureDir(routeFilePath);
124
136
  if (hasRouteWriter) {
137
+ deps.announceFile(staticRoute.pathname, routeFilePath);
125
138
  routeWriter = sys.createWriteStream(routeFilePath);
126
139
  routeWriter.on("error", (e) => {
127
140
  console.error(e);
@@ -165,6 +178,7 @@ async function workerRender(sys, opts, staticRoute, pendingPromises, callback, d
165
178
  const data = loaderValues[loader.__id];
166
179
  if (data === void 0) continue;
167
180
  const loaderFilePath = sys.getLoaderFilePath(url.pathname, loader.__id, manifestHash);
181
+ deps.announceFile(staticRoute.pathname, loaderFilePath);
168
182
  const loaderWriter = sys.createWriteStream(loaderFilePath);
169
183
  loaderWriter.on("error", (e) => {
170
184
  console.error(e);
@@ -207,12 +221,12 @@ async function workerRender(sys, opts, staticRoute, pendingPromises, callback, d
207
221
  }
208
222
  return completion;
209
223
  };
210
- if (routeWriter) return closePromise.then(() => failRouteOnCaughtBoundary(r));
211
- return failRouteOnCaughtBoundary(r);
224
+ const failure = r ?? rsp.requestEv.sharedMap.get("@sentServerError");
225
+ if (routeWriter) return closePromise.then(() => failRouteOnCaughtBoundary(failure));
226
+ return failRouteOnCaughtBoundary(failure);
212
227
  });
213
228
  }).then((e) => {
214
229
  if (e !== void 0) {
215
- if (isRedirectMessage(e)) return;
216
230
  if (e instanceof Error) result.error = {
217
231
  message: e.message,
218
232
  stack: e.stack
@@ -249,9 +263,6 @@ async function workerRender(sys, opts, staticRoute, pendingPromises, callback, d
249
263
  }
250
264
  /** Create a fresh no-op WritableStream (must be a real instance for pipeTo checks). */
251
265
  var createNoopWritableStream = () => new WritableStream();
252
- function isRedirectMessage(value) {
253
- return typeof value === "object" && value !== null && value.constructor?.name === "RedirectMessage";
254
- }
255
266
  async function requestHandlerForSsg(serverRequestEv, opts, deps) {
256
267
  const { render, checkOrigin, qwikRouterConfig } = opts;
257
268
  if (!qwikRouterConfig) throw new Error("qwikRouterConfig is required.");
package/lib/index.d.ts CHANGED
@@ -157,10 +157,10 @@ declare type AnchorAttributes = QwikIntrinsicElements['a'];
157
157
  *
158
158
  * - `true`: use the surface's default key.
159
159
  *
160
- * - SSR default: `${status}|${eTag}|${pathname}` when an eTag is set, otherwise
161
- * `${status}|${pathname}`.
162
- * - Loader default: `${pathname}|${filteredSearch}|${loaderId}|${eTag}` when an eTag is set,
163
- * otherwise `${pathname}|${filteredSearch}|${loaderId}`.
160
+ * - SSR default: `${status}|${eTag}|${origin}${pathname}` when an eTag is set, otherwise
161
+ * `${status}|${origin}${pathname}`.
162
+ * - Loader default: `${origin}${pathname}|${filteredSearch}|${loaderId}|${eTag}` when an eTag is set,
163
+ * otherwise `${origin}${pathname}|${filteredSearch}|${loaderId}`.
164
164
  * - Function: receives the request event and the normalized, unquoted eTag (or an empty string when
165
165
  * none was provided). Return the cache key string, or `null` or `''` to skip caching for this
166
166
  * request. Loader callbacks receive the loader-scoped request event, with `url`, `query`, and
@@ -410,15 +410,14 @@ export declare interface FormProps<O, I> extends Omit<QwikJSX.IntrinsicElements[
410
410
  */
411
411
  reloadDocument?: boolean;
412
412
  /**
413
- * When `true` all the form inputs will be reset in SPA mode, just like happens in a full page
414
- * form submission.
413
+ * Resets SPA form controls after responses, including validation failures.
415
414
  *
416
415
  * Defaults to `false`
417
416
  */
418
417
  spaReset?: boolean;
419
418
  /**
420
- * Event handler executed right after the action is executed successfully and returns some data.
421
- * Like the native `on*$` events, it accepts an inline function as well as a QRL.
419
+ * Runs after a form submission returns, including validation failures. Like the native `on*$`
420
+ * events, it accepts an inline function as well as a QRL.
422
421
  */
423
422
  onSubmitCompleted$?: QRLEventHandlerMulti<CustomEvent<FormSubmitSuccessDetail<O>>, HTMLFormElement> | EventHandler<CustomEvent<FormSubmitSuccessDetail<O>>, HTMLFormElement> | undefined;
424
423
  key?: string | number | null;
@@ -652,6 +651,9 @@ declare type LoaderOptions = {
652
651
  * When set, the server includes an `ETag` header on `q-loader-*.json` responses and returns `304`
653
652
  * if the client sends a matching `If-None-Match` header.
654
653
  *
654
+ * With `serializationStrategy: 'never'`, the eTag is also sent with the page, so the first client
655
+ * fetch with the same eTag reuses the rendered data without re-running its subscribers.
656
+ *
655
657
  * For auto-computed eTags, use `cacheKey` instead — on cache write the eTag is hashed from the
656
658
  * serialized response and stored alongside it, so subsequent hits get the same eTag.
657
659
  */
@@ -659,8 +661,8 @@ declare type LoaderOptions = {
659
661
  /**
660
662
  * Enable in-memory server-side caching of this loader's serialized JSON response.
661
663
  *
662
- * - `true` — use the default key `${pathname}|${filteredSearch}|${loaderId}` (suffixed with
663
- * `|${eTag}` when an eTag is set).
664
+ * - `true` — use the default key `${origin}${pathname}|${filteredSearch}|${loaderId}` (suffixed
665
+ * with `|${eTag}` when an eTag is set).
664
666
  * - Function `(requestEv, eTag) => string | null` — return a custom key, or `null` to skip caching
665
667
  * this request. For user-specific data, include user identity and relevant permissions in the
666
668
  * key or disable this cache.
@@ -1103,10 +1105,10 @@ export declare const routeLoader$: LoaderConstructor;
1103
1105
  /** Shared SSR paths and client-only loader navigation state. */
1104
1106
  declare type RouteLoaderCtx = {
1105
1107
  loaderPaths: Record<string, string | undefined>;
1106
- /** SPA navigation function. Client-only and intentionally omitted from SSR state. */
1108
+ /** Resolves after navigation prepares loader requests, before their results. */
1107
1109
  goto?: NoSerialize<(path: string, options: {
1108
1110
  replaceState: boolean;
1109
- }) => unknown>;
1111
+ }) => Promise<void>>;
1110
1112
  /** Router callback that re-resolves the document head after a loader gets a new value. */
1111
1113
  onValue?: RouteNavigate;
1112
1114
  /** Client manifest hash for q-loader fetch URLs. */