@qwik.dev/router 2.0.0-rc.4 → 2.0.0-rc.6

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 { O as getRouteLoaderValues, d as loadRoute, k as getRouteLoaders } 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 { c as RequestEvHttpStatusMessage, i as resolveRequestHandlers, r as renderQwikMiddleware, t as runQwikRouter } from "./user-response.mjs";
2
+ import { u as trimInternalPathname } from "./request-path.mjs";
3
+ import { C as getRouteLoaderValues, o as loadRoute, w as getRouteLoaders } from "./head.qwik.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);
@@ -159,12 +172,13 @@ async function workerRender(sys, opts, staticRoute, pendingPromises, callback, d
159
172
  if (writeLoaderDataEnabled && !isNotFoundPage) {
160
173
  const routeLoaders = getRouteLoaders(requestEv);
161
174
  const loaderValues = getRouteLoaderValues(requestEv);
162
- const manifestHash = opts.manifest?.manifestHash || "dev";
175
+ const manifestHash = requestEv.sharedMap.get("@manifestHash") || opts.manifest?.manifestHash || "dev";
163
176
  for (const loader of routeLoaders) {
164
177
  if (loader.__cacheControl !== "immutable") continue;
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
@@ -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;
@@ -534,7 +533,8 @@ export declare interface LinkProps extends AnchorAttributes {
534
533
  * Controls when Qwik should prefetch the javascript bundles required to render this **`Link`**
535
534
  * target during client-side navigation.
536
535
  *
537
- * Defaults to **`"visible"`**.
536
+ * Defaults to **`"visible"`**. A link that prefetches when visible is hinted again, ahead of the
537
+ * others, when the user hovers or focuses it.
538
538
  *
539
539
  * Prefetching will not occur if the user has the **data saver** setting enabled.
540
540
  */
@@ -619,6 +619,7 @@ declare type LoaderOptions = {
619
619
  */
620
620
  readonly id?: string;
621
621
  readonly validation?: DataValidator[];
622
+ /** Controls value serialization during SSR; defaults to `auto`. */
622
623
  readonly serializationStrategy?: SerializationStrategy;
623
624
  /**
624
625
  * Cache-Control for this loader's JSON responses. The browser HTTP cache is the single source of
@@ -652,6 +653,9 @@ declare type LoaderOptions = {
652
653
  * When set, the server includes an `ETag` header on `q-loader-*.json` responses and returns `304`
653
654
  * if the client sends a matching `If-None-Match` header.
654
655
  *
656
+ * With `serializationStrategy: 'never'`, the eTag is also sent with the page, so the first client
657
+ * fetch with the same eTag reuses the rendered data without re-running its subscribers.
658
+ *
655
659
  * For auto-computed eTags, use `cacheKey` instead — on cache write the eTag is hashed from the
656
660
  * serialized response and stored alongside it, so subsequent hits get the same eTag.
657
661
  */
@@ -1103,10 +1107,10 @@ export declare const routeLoader$: LoaderConstructor;
1103
1107
  /** Shared SSR paths and client-only loader navigation state. */
1104
1108
  declare type RouteLoaderCtx = {
1105
1109
  loaderPaths: Record<string, string | undefined>;
1106
- /** SPA navigation function. Client-only and intentionally omitted from SSR state. */
1110
+ /** Resolves after navigation prepares loader requests, before their results. */
1107
1111
  goto?: NoSerialize<(path: string, options: {
1108
1112
  replaceState: boolean;
1109
- }) => unknown>;
1113
+ }) => Promise<void>>;
1110
1114
  /** Router callback that re-resolves the document head after a loader gets a new value. */
1111
1115
  onValue?: RouteNavigate;
1112
1116
  /** Client manifest hash for q-loader fetch URLs. */