Skip to content

fix(qwikloader): bootstrap module loader via inline import to prevent WebKit streaming delay - #9182

Closed
Piercekaoru wants to merge 1 commit into
QwikDev:mainfrom
Piercekaoru:fix/webkit-streaming-qwikloader
Closed

Piercekaoru wants to merge 1 commit into
QwikDev:mainfrom
Piercekaoru:fix/webkit-streaming-qwikloader

Conversation

@Piercekaoru

Copy link
Copy Markdown

What is it?

  • Bug

Description

WebKit can defer the evaluation of <script async type="module" src="..."> scripts while an HTML stream remains open. When an application streams HTML, this delay can cause pre-resumption user interactions (such as early clicks) to be missed because the qwikloader bootstrap script is not evaluated until the stream finishes.

This change in packages/qwik/src/server/ssr-container.ts resolves the issue:

  • Retains <link rel="modulepreload"> to preserve early fetching behavior.
  • Replaces the external <script async type="module" src="..."> tag with an inline bootstrap script emitted via the existing nonce-aware emitInlineScript.
  • Starts a dynamic import with a URL resolved against document.baseURI; the server serializes the URL with JSON.stringify.
  • Escapes any literal < characters in the serialized URL string as \u003C to prevent premature script tag termination.
  • Uses document.baseURI to preserve relative and absolute loader URL resolution.
  • Preserves CSP nonces across both the modulepreload link and the inline import bootstrap script.
  • Leaves inline and never loader strategies untouched.
  • Enables the previously skipped WebKit mid-stream queue/replay E2E test.
  • Adds render API test coverage for default and explicit module modes, nonce propagation, relative/CDN URLs, and script tag termination escaping.
  • Regenerates only the affected SSG HTML snapshots.
  • Adds a patch changeset for @qwik.dev/core.

Fixes #8891

Testing

Test environment:

  • macOS 26.4.1
  • Node 24.19.0
  • pnpm 11.22.0
  • Playwright 1.61.1 (WebKit 26.5)

Verification results:

  • Pre-fix verification: The unskipped WebKit mid-stream regression test failed 3/3 times, timing out after polling _qwikEv.roots for 30s.
  • E2E verification:
    • Re-enabled previously skipped WebKit mid-stream queue/replay E2E test.
    • Focused test run across all browsers (--browser=all --repeat-each=5 --workers=1 --retries=0): 15 passed.
    • Full error-handling.e2e.ts suite (including production scenarios) across Chromium, Firefox, and WebKit: 120 passed, 9 pre-existing skipped.
  • SSG snapshot suite: 6 passed (clean verification after updating only the modified SSG HTML snapshots).
  • Unit and Render API tests:
    • Focused Vitest suite (render-api.spec.tsx and server/ssr-container.spec.ts): 90 passed. Added render API coverage for default/explicit module modes, nonce propagation, relative/CDN URLs, and script-tag termination escaping.
  • Build & Lint:
    • Dev build pnpm build.core.dev: passed.
    • Production build pnpm build --qwik --optimizer --qwikrouter: passed.
    • pnpm lint.eslint (following pnpm build --eslint), pnpm lint.prettier, and git diff --check: passed.
  • Full Unit Test Suite Caveat / Unrelated Failures:
    • pnpm test.unit --maxWorkers=4 reported 3961 passed, 7 failed, 18 skipped, 19 todo.
    • All 7 failures occurred in qwik-vite/src/plugins/plugin.unit.ts with Cannot find module '/qwik-vite/src/bindings/qwik.wasm.mjs'.
    • These 7 failures reproduce identically when temporarily reverting ssr-container.ts to base HEAD, confirming they are unrelated to this PR.
    • An initial unconstrained unit run also had one intermittent failure in error-handling.spec.tsx; it passed in isolation and in the final bounded full run.

Checklist

@Piercekaoru
Piercekaoru requested a review from a team as a code owner October 7, 2026 15:58
@changeset-bot

changeset-bot Bot commented Oct 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9e10436

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

This PR includes changesets to release 8 packages
Name Type
@qwik.dev/core Patch
@qwik.dev/devtools Patch
eslint-plugin-qwik Patch
@qwik.dev/mcp 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

@pkg-pr-new

pkg-pr-new Bot commented Oct 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

@qwik.dev/core

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

@qwik.dev/router

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

@qwik.dev/utils

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

eslint-plugin-qwik

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

create-qwik

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

@qwik.dev/optimizer

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

@qwik.dev/devtools

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

@qwik.dev/mcp

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/mcp@9182

commit: 9e10436

@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.

Hello! Thanks for the PR, the changes are looking good, but added small comment

Comment on lines +1583 to +1585
this.emitInlineScript(
`import(new URL(${JSON.stringify(qwikLoaderBundle).replaceAll('<', '\\u003C')},document.baseURI).href)`
);

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.

what about CSP rules? could you add chromium/firefox/webkit streaming e2e test with an enforced nonce-based CSP?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Opened #9208 as a replacement for this PR, with the enforced nonce-based CSP streaming coverage requested here

  • Chromium, Firefox and WebKit each run the held-stream click queue/replay test with and without script-src 'nonce-<value>' 'strict-dynamic'
  • The fixture uses an enforced response header rather than report-only, and asserts zero CSP violations
  • Both variants passed across all three browsers with 5 repetitions each, 30 passed with retries disabled
  • As a mutation check, removing only the bootstrap nonce caused CSP rejection in all three browsers; restoring it returned 30 passed
  • The full error-handling suite passed 126 tests with 6 existing skips

Local validation caveats are recorded in the new PR, including the missing optimizer bindings in the default monorepo unit run
GitHub CI on the replacement PR is still pending

@akasakariko

Copy link
Copy Markdown
Contributor

My mistake, I'll rework the fix to avoid this

@Varixo

Varixo commented Oct 10, 2026

Copy link
Copy Markdown
Member

My mistake, I'll rework the fix to avoid this

it may work, so first add the test and see if everything is fine

@Varixo

Varixo commented Oct 14, 2026

Copy link
Copy Markdown
Member

Closing in favour of #9208

@Varixo Varixo closed this Oct 14, 2026
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.

qwikloader: WebKit may defer the async module loader while a stream is held, losing pre-resume clicks

3 participants