Skip to content

Commit c5eada7

Browse files
authored
Merge pull request #7826 from JerryWu1234/buildv2async
feat: enhance locale handling with AsyncLocalStorage support for server-side requests
2 parents 9b73179 + 69a43e9 commit c5eada7

File tree

25 files changed

+436
-532
lines changed

25 files changed

+436
-532
lines changed

.changeset/gentle-laws-see.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik.dev/router': minor
3+
---
4+
5+
FEAT: if a server$ function throws an error that is not a `ServerError`, it will now log the error on the server

.changeset/pretty-parents-draw.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@qwik.dev/router': patch
3+
'@qwik.dev/core': patch
4+
---
5+
6+
FEAT: withLocale() uses AsyncLocalStorage for server-side requests when available. This allows async operations to retain the correct locale context.

packages/docs/src/repl/bundler/rollup-plugins.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export const replResolver = (
6363
if (id.startsWith('/qwik/')) {
6464
return id;
6565
}
66+
// Replace node: with modules that throw on import
67+
if (id.startsWith('node:')) {
68+
return id;
69+
}
6670
const match = id.match(/(@builder\.io\/qwik|@qwik\.dev\/core)(.*)/);
6771
if (match) {
6872
const pkgName = match[2];
@@ -114,6 +118,9 @@ export const replResolver = (
114118
if (input && typeof input.code === 'string') {
115119
return input.code;
116120
}
121+
if (id.startsWith('node:')) {
122+
return `throw new Error('Module "${id}" is not available in the REPL environment.');`;
123+
}
117124
if (id.startsWith('/qwik/')) {
118125
const path = id.slice('/qwik'.length);
119126
if (path === '/build') {

packages/docs/src/repl/ui/repl-output-update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const updateReplOutput = async (store: ReplStore, result: ReplResult) =>
3131
deepUpdate(store.clientBundles, result.clientBundles);
3232
deepUpdate(store.ssrModules, result.ssrModules);
3333

34-
if (result.diagnostics.length === 0) {
34+
if (!result.diagnostics.some((d) => d.category === 'error' || d.category === 'sourceError')) {
3535
if (result.html && store.html !== result.html) {
3636
store.html = result.html;
3737
store.events = result.events;

packages/qwik-router/global.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/* eslint-disable no-var */
22
// Globals used by qwik-router, for internal use only
33

4+
declare module '*?compiled-string' {
5+
const str: string;
6+
export default str;
7+
}
8+
49
type RequestEventInternal =
510
import('./middleware/request-handler/request-event').RequestEventInternal;
6-
type AsyncStore = import('node:async_hooks').AsyncLocalStorage<RequestEventInternal>;
711
type SerializationStrategy = import('@qwik.dev/core/internal').SerializationStrategy;
8-
9-
declare var qcAsyncRequestStore: AsyncStore | undefined;
1012
declare var _qwikActionsMap: Map<string, ActionInternal> | undefined;
1113

1214
type ExperimentalFeatures = import('@qwik.dev/core/optimizer').ExperimentalFeatures;

packages/qwik-router/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
"directory": "packages/qwik-router"
200200
},
201201
"scripts": {
202-
"build": "cd src/runtime && vite build --mode lib"
202+
"build": "vite build"
203203
},
204204
"sideEffects": false,
205205
"type": "module",

packages/qwik-router/src/buildtime/vite/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import swRegister from '@qwik-router-sw-register-build';
1+
import swRegister from '../runtime-generation/sw-register-build?compiled-string';
22
import type { QwikVitePlugin } from '@qwik.dev/core/optimizer';
33
import fs from 'node:fs';
44
import { basename, extname, join, resolve } from 'node:path';

packages/qwik-router/src/middleware/request-handler/async-request-store.ts

Whitespace-only changes.

packages/qwik-router/src/middleware/request-handler/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { requestHandler } from './request-handler';
1+
export { requestHandler, _asyncRequestStore } from './request-handler';
22

33
export { getErrorHtml } from './error-handler';
44
export { getNotFound } from './not-found-paths';

packages/qwik-router/src/middleware/request-handler/middleware.request-handler.api.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
```ts
66

77
import type { Action } from '@qwik.dev/router';
8+
import type { AsyncLocalStorage } from 'node:async_hooks';
89
import type { EnvGetter as EnvGetter_2 } from '@qwik.dev/router/middleware/request-handler';
910
import type { FailReturn } from '@qwik.dev/router';
1011
import type { Loader as Loader_2 } from '@qwik.dev/router';
@@ -24,6 +25,11 @@ import type { ValueOrPromise } from '@qwik.dev/core';
2425
export class AbortMessage {
2526
}
2627

28+
// Warning: (ae-forgotten-export) The symbol "RequestEventInternal" needs to be exported by the entry point index.d.ts
29+
//
30+
// @internal (undocumented)
31+
export let _asyncRequestStore: AsyncLocalStorage<RequestEventInternal> | undefined;
32+
2733
// Warning: (ae-forgotten-export) The symbol "CacheControlOptions" needs to be exported by the entry point index.d.ts
2834
//
2935
// @public (undocumented)
@@ -240,8 +246,6 @@ export interface ServerRequestEvent<T = unknown> {
240246
// @public (undocumented)
241247
export type ServerRequestMode = 'dev' | 'static' | 'server';
242248

243-
// Warning: (ae-forgotten-export) The symbol "RequestEventInternal" needs to be exported by the entry point index.d.ts
244-
//
245249
// @public (undocumented)
246250
export type ServerResponseHandler<T = any> = (status: number, headers: Headers, cookies: Cookie, resolve: (response: T) => void, requestEv: RequestEventInternal) => WritableStream<Uint8Array>;
247251

0 commit comments

Comments
 (0)