Skip to content

fix(core): keep locale across async withLocale without ALS - #9008

Merged
Varixo merged 2 commits into
QwikDev:mainfrom
xia-chao:fix/withlocale-async-no-als
Sep 14, 2026
Merged

Varixo merged 2 commits into
QwikDev:mainfrom
xia-chao:fix/withlocale-async-no-als

Conversation

@xia-chao

Copy link
Copy Markdown
Contributor

What is it?

  • Bug

Description

withLocale('zh-CN', async () => { ... }) is supposed to keep getLocale() as zh-CN for the whole function, including after await.

That already works when AsyncLocalStorage is present. When it is not (browser build, some edge runtimes), the old code used try/finally. The finally runs the moment the function returns a Promise, so after await the locale is gone and getLocale() throws Reading locale outside of context.

This change waits until that Promise finishes (success or error), then puts the previous locale back. Sync withLocale is unchanged.

Related: this is the leftover hole after #8999, which taught Qwik how to find ALS on more runtimes. This PR is about the path that still has no ALS.

Checklist

  • My code follows the developer guidelines of this project
  • I performed a self-review of my own code
  • I added a changeset with pnpm change
  • I added new tests to cover the fix / functionality

try/finally restored _locale as soon as fn returned a Promise, so getLocale() threw after await when AsyncLocalStorage was missing.
@xia-chao
xia-chao requested a review from a team as a code owner September 11, 2026 09:00
@changeset-bot

changeset-bot Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3a0b961

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@qwik.dev/core Patch
@qwik.dev/devtools Patch
eslint-plugin-qwik Patch
@qwik.dev/react Patch
@qwik.dev/router Patch
@qwik.dev/utils Patch
create-qwik Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Varixo Varixo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey! thanks for the PR, added small comment

Comment thread packages/qwik/src/core/use/use-locale.ts Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@xia-chao

Copy link
Copy Markdown
Contributor Author

@Varixo
yes! You are right!
Please review

@xia-chao
xia-chao requested a review from Varixo September 14, 2026 17:53

@Varixo Varixo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the PR!

@Varixo
Varixo enabled auto-merge (squash) September 14, 2026 20:06
@pkg-pr-new

pkg-pr-new Bot commented Sep 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

@qwik.dev/core

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/core@9008

@qwik.dev/router

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/router@9008

@qwik.dev/utils

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/utils@9008

eslint-plugin-qwik

npm i https://pkg.pr.new/QwikDev/qwik/eslint-plugin-qwik@9008

create-qwik

npm i https://pkg.pr.new/QwikDev/qwik/create-qwik@9008

@qwik.dev/optimizer

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/optimizer@9008

@qwik.dev/devtools

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/devtools@9008

commit: 3a0b961

@Varixo
Varixo merged commit c25867d into QwikDev:main Sep 14, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants