Repository navigation
fix: refresh injectStyle sheets when HMR keeps the hash - #957
Merged
Merged
Conversation
Same-id re-injection with different CSS now updates the owned <style data-octane> text instead of keeping the stale first sheet. Server-emitted sheets and the no-DOM Set path stay first-wins. Co-authored-by: Jon Wheeler <[email protected]>
jonkwheeler
marked this pull request as ready for review
September 4, 2026 19:03
leonidaz
added a commit
that referenced
this pull request
Sep 5, 2026
Resolve against main's #957, #960, and #961, which landed on the statement-scoped style machinery this branch replaces: - runtime.ts: keep the branch's `injectStyle` (main's in-place refresh is already here; the React Float match stays a `data-href` token match for batched multi-hash islands). - style-hmr-reinject.test.ts: take main's superset (adds the document-less case). - compile.js / style-scopes.js: keep the sibling-scope pre-pass; drop main's `componentStyleRoots`/`annotateRootWithHash`/`applyCssScoping` and the `applyStyleRefs` import. Main's synthesized-class merge flag (#961) applies unchanged to the pre-pass's stamped attributes. - `<style ref>` (#960) is not carried over: the attribute stays unsupported in Octane pending its removal from TSRX, so its fixture, tests, and changeset are dropped and the immutability fixture no longer uses it. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 task done
14 of 21 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #938.
injectStyle(id, css)on the client now refreshes an already-owned<style data-octane>when a later call arrives with the same id and different CSS (HMR of a later block in a multi-block scope). A server-emitted sheet seen for the first time is still adopted untouched, and the no-DOM path still records the id in_injectedStyleswithout creating a tag.Base verification:
feat/scoped-styles-applyalready contains this contract as part of #939 (theit.failspin was flipped there ine8ac8adb5).mainstill had first-wins-only dedupe and nostyle-hmr-reinjectsuite. This PR lands only the isolated runtime fix onmainso #938 can close independently of the scoped-styles RFC.Why
The compiled scope hash is derived from the first block's position and content. Editing a later block under HMR keeps the hash, so
injectStyle(id, css1); injectStyle(id, css2)used to leavecss1in the document.Changes
injectStyle: ifstyle[data-octane=id]exists and this runtime already owns it, replacetextContentwhen it differs. Otherwise adopt (SSR) or record the id (nodocument).packages/octane/tests/runtime/style-hmr-reinject.test.tswith identical-repeat, server-adopt first-wins, HMR replace, and no-DOM first-wins.octane.No content-hash-in-id change (plan D12); not required for this fix.
Validation
pnpm format:check(not run; used scoped format)pnpm typecheck:fileson the two changed source filespnpm test(full suite not run)packages/octane/tests/runtime/style-hmr-reinject.test.ts(dev +octane-prod),ssr-control.test.ts,style.test.tsBefore the runtime change, the HMR case failed (kept
css1) and a first no-DOM call threw ondocument.createElement. After the change, 8/8 pass in bothoctaneandoctane-prod. Removing thetextContentassign made only the HMR case fail again; first-wins and no-DOM stayed green. Nearby injectStyle coverage: 136 passed.pnpm format:fileson the changed paths: unchanged.pnpm sync: no generated files.Risk / follow-ups
injectStyle(token-matchdata-hreffor React batched resources). Merging both will need a small reconcile in that function; this PR does not take the~=change.injectStyleis module-eval / HMR, not a per-render hot path. Extra work is onedata-octanequery plus a string compare on the existing-sheet branch.Provenance
agent-authored)Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.