Skip to content

[Bug]: Publish prunes CSS classes that are only applied at runtime by JS #465

Description

@borskyj-symph

Summary

Publishing prunes CSS rules whose class is not attached to any node in the authored document. That includes modifier classes that only ever exist at runtime, toggled by JavaScript. The rule is present and correct everywhere up to publish, then absent from the published stylesheet.

Steps to reproduce

  1. Define a modifier that no authored node carries — one a script toggles:
.mobilenav { display: none; }
.mobilenav--open { display: flex; }
  1. Add a script asset that toggles .mobilenav--open on click.
  2. Call site_read_styles. Both rules come back correctly.
  3. Publish.
  4. Inspect the published stylesheet. .mobilenav--open is gone.

Expected behavior

An authored rule survives publish, or the pruning is visible before publish so it can be worked around.

Actual behavior

The rule is dropped because no authored node carries the class. The element keeps its base display: none no matter how the script toggles it, so the menu never opens on the published site.

The debugging cost is the real problem here. The failure appears only after publish, and the stored CSS reads back correctly at every point before that — so you start on the script, then event binding, and reach the stylesheet last. This is the same shape as a write that reports success and discards the input: you trust what you read back and look for the bug one layer below where it actually is.

The workaround in use is to apply all runtime state as inline styles from script. That loses the cascade entirely: no media queries, no pseudo-states, no theming on that state.

Any of these would resolve it:

  • Treat any class referenced in a runtime script asset as used. Covers the common case with no author opt-in.
  • A safelist in site config.
  • A per-rule keep flag that survives pruning.

Version or commit

Live hosted workspace, 30–31 Aug 2026. Workspace version not recorded; latest tag at the time of writing is v0.0.17.

Deployment mode

Hosted

Logs or screenshots

n/a — visible by diffing site_read_styles output against the published stylesheet.

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