Skip to content

[🐞] useQwikSpeak results in QWIK ERROR Code(20) since v2.0.0-beta.9 #8261

@schoero

Description

@schoero

Which component is affected?

Qwik Runtime

Describe the bug

I recently wanted to upgrade a website to the latest beta in a project where I use qwik-speak.

qwik throws the following error since v2.0.0-beta.9 up to the latest v2.0.0-beta.17:

QWIK ERROR Code(20) https://github.com/QwikDev/qwik/blob/main/packages/qwik/src/core/error/error.ts#L28 Error: Code(20) https://github.com/QwikDev/qwik/blob/main/packages/qwik/src/core/error/error.ts#L28
    at createAndLogError (file:///Users/schoero/GitHub/qwik-use-hook-repro/node_modules/@builder.io/qwik/dist/core.prod.mjs:96:54)
    at logErrorAndStop (file:///Users/schoero/GitHub/qwik-use-hook-repro/node_modules/@builder.io/qwik/dist/core.prod.mjs:64:57)
    at qError (file:///Users/schoero/GitHub/qwik-use-hook-repro/node_modules/@builder.io/qwik/dist/core.prod.mjs:181:12)
    at useInvokeContext (file:///Users/schoero/GitHub/qwik-use-hook-repro/node_modules/@builder.io/qwik/dist/core.prod.mjs:2679:15)
    at useSequentialScope (file:///Users/schoero/GitHub/qwik-use-hook-repro/node_modules/@builder.io/qwik/dist/core.prod.mjs:587:18)
    at useContextProvider (file:///Users/schoero/GitHub/qwik-use-hook-repro/node_modules/@builder.io/qwik/dist/core.prod.mjs:606:31)
    at useQwikSpeak (file:///Users/schoero/GitHub/qwik-use-hook-repro/node_modules/qwik-speak/lib/use-qwik-speak.qwik.mjs:52:3)
    at qrl2.root_component_tntnak2DhJ8 [as resolved] (/Users/schoero/GitHub/qwik-use-hook-repro/src/root.tsx:30:43)
    at qrl2.invokeApply (/Users/schoero/GitHub/qwik-use-hook-repro/node_modules/@qwik.dev/core/dist/core.mjs:5995:22)
    at qrl2.invoke (/Users/schoero/GitHub/qwik-use-hook-repro/node_modules/@qwik.dev/core/dist/core.mjs:5988:22)

which links to the following error message:

Calling a 'use*()' method outside 'component$(() => { HERE })' is not allowed. 'use*()' methods provide hooks to the 'component$' state and lifecycle, ie 'use' hooks can only be called synchronously within the 'component$' function or another 'use' method.\nSee https://qwik.dev/docs/core/tasks/#use-method-rules`, // 20

Note that this worked up to v2.0.0-beta.8. I don't think that a breaking change regarding the context is mentioned in the changelog of v2.0.0-beta.9 which is why I think it is a bug in qwik.

Reproduction

https://github.com/schoero/qwik-use-hook-repro

Steps to reproduce

  1. Clone the reproduction repository and start the dev server:
git clone https://github.com/schoero/qwik-use-hook-repro.git
npm i
npm run dev
  1. Or create a new Qwik project
npm create qwik@beta
  1. Install qwik-speak
npm install qwik-speak --save-dev
  1. Follow the steps on the qwik-speak guide: https://github.com/robisim74/qwik-speak/blob/main/docs/quick-start.md

System Info

System:
    OS: macOS 15.7.3
    CPU: (8) arm64 Apple M2
    Memory: 89.14 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.5.0 - /Users/schoero/.volta/tools/image/node/24.5.0/bin/node
    Yarn: 1.22.22 - /Users/schoero/.volta/tools/image/yarn/1.22.22/bin/yarn
    npm: 11.5.1 - /Users/schoero/.volta/tools/image/node/24.5.0/bin/npm
    pnpm: 10.16.0 - /Users/schoero/.volta/bin/pnpm
    bun: 1.3.5 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 144.0.7559.60
    Firefox: 142.0
    Safari: 26.2
  npmPackages:
    typescript: 5.9.3 => 5.9.3 
    vite: 7.2.2 => 7.2.2

Additional Information

This is the code where qwik-speak tries to use the context: https://github.com/robisim74/qwik-speak/blob/ee90dbb34258b36ffad1a56fa4c61518442dc5cd/packages/qwik-speak/src/use-qwik-speak.tsx#L88-L94

Note that it tries to set the context before using it:

  // Set Qwik Speak server context
  setSpeakServerContext(config);

  // Set the getLang function to use Qwik locale
  setGetLangFn(() => getLocale(config.defaultLocale.lang));

  // Create Qwik context
  useContextProvider(SpeakContext, state);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions