Repository navigation
Description
Describe the bug
When a streamed fragment carries its own stylesheet, sink.fragment in @solidjs/web/dist/server.js writes the link with inline event handlers:
<link rel="stylesheet" href="/assets/FragmentCssPanel-….css" onload="$dfc('2000037051000710001')" onerror="$dfc('2000037051000710001')">Inline event handler attributes cannot carry a nonce. Under a strict CSP (script-src 'nonce-…' 'strict-dynamic', no 'unsafe-inline'), which renderToStream({ nonce }) otherwise supports for every other script it emits, the browser blocks both handlers. $dfc never runs, _$HY.sc[key] stays at 1, and the fragment never leaves its <Loading> fallback.
This happens when a lazy() component with its own CSS is created only after async data resolves, so its stylesheet is announced in the fragment instead of the <head>.
Your Example Website or App
Steps to Reproduce the Bug or Issue
- Render a page with
renderToStream(..., { nonce: { script: nonce, style: false } })and sendContent-Security-Policy: script-src 'nonce-<nonce>' 'strict-dynamic'. - Inside
<Loading>, read an async memo and render<Show when={data()}><LazyPanel /></Show>, whereLazyPanel = lazy(() => import('./Panel'))andPanelimports a CSS Module. - Load the page in Chromium.
The console reports a CSP violation for each inline handler, and _$HY.sc keeps the fragment key at 1.
Expected behavior
The fragment stylesheet links should release the fragment without inline handlers, so the streaming runtime keeps working under the same nonce-based CSP as the rest of the document.
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chromium (Playwright)
solid-js/@solidjs/web: 2.0.0-rc.13,@solidjs/vite-plugin: 3.0.0-next.47
Additional context
Proposed fix (validated on the server side only). Mark the links with a data attribute and install one capture-phase listener in REPLACE_SCRIPT. That script is emitted with the nonce, through emitTask($dfs(...)) and writeTasks(), before the links are written. Inline scripts are parser-blocking, so the listener exists before any fragment link is parsed. load and error don't bubble, but they do reach document in the capture phase.
- `<link rel="stylesheet" href="${entry}"${styleAttr} onload="$dfc('${key}')" onerror="$dfc('${key}')">`
+ `<link rel="stylesheet" href="${entry}"${styleAttr} data-dfc="${key}">`Appended to REPLACE_SCRIPT:
function $dfe(e,k){(e=e.target)&&e.getAttribute&&(k=e.getAttribute("data-dfc"))&&$dfc(k)}document.addEventListener("load",$dfe,!0);document.addEventListener("error",$dfe,!0)With this change (applied to server.js, server.dev.js and server.observe.js), the page reports no CSP violation, no on*= attribute is emitted, and _$HY.sc drains to {}.
Related finding: a separate client-side stall. Even with the fix above, the fragment in this fixture still stays in its fallback. This is independent of the CSP:
- With the unpatched server bundle, CSP bypassed (
bypassCSP: true) and the document streamed normally,$dfcruns (_$HY.scis{}), but<p>Carregando fragmento...</p>remains and hydration never completes (_$HY.eventsstays non-null). - If the same response is delivered in one piece (Playwright
route.fulfillwith the full body), the fragment is swapped in. That suggests the stall happens when$dfdelegates to_$HY.fbecause hydration has already started, rather than in$dfr.
I left the two problems in one report because they show up in the same fixture, but they are probably independent.
Activity
fix(web): stylesheet-gated fragments reveal under a nonce CSP and whe…
ryansolid commentedon Oct 2, 2026
signals: the hold model (L2) — core rebuilt from its rulings; −23% fl…