Skip to content

injectStyle drops a re-injection with an unchanged hash but changed CSS (HMR hazard) #938

Closed

Description

@leonidaz

injectStyle(id, css) on the client (packages/octane/src/runtime.ts, _injectedStyles Set plus the style[data-octane=id] DOM query) dedupes by id only. Re-evaluating a module under HMR with an unchanged scope hash but changed CSS therefore leaves the old sheet in place: injectStyle(id, css1); injectStyle(id, css2) keeps css1.

With lexically scoped <style> blocks (RFC tsrx-org/RFCs#1, branch feat/scoped-styles-apply) the hash is derived from the first block's position and content, so editing a later block of a multi-block scope keeps the hash and hits this exactly. Pinned as it.fails in packages/octane/tests/runtime/style-hmr-reinject.test.ts next to a passing test of the current first-wins behavior.

Proposed fix: when a <style data-octane=id> already exists and its textContent differs from css, replace the text instead of returning; keep the Set for the no-DOM path. Consider also including a content hash in the id at compile time (the RFC's optional runtime dedupe, plan D12/S8.6).

Plan references: S3.6, S8.6.

Activity

  1. leonidaz commented on Sep 3, 2026

    @leonidaz
    CollaboratorAuthor

    Fixed in #939: injectStyle now refreshes a sheet this runtime already owns when a call arrives with an unchanged id and different CSS (a server-emitted sheet seen for the first time is still adopted untouched). Pinned by packages/octane/tests/runtime/style-hmr-reinject.test.ts.

  2. jonkwheeler commented on Sep 4, 2026

    @jonkwheeler
    Contributor

    Also covered for main in #957

    @leonidaz injectStyle replaces CSS when HMR keeps the same hash (same contract as #939 on the scoped-styles branch).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions