Skip to content

fix(import): close each style block's open @media before joining blocks - #560

Open
tommy230 wants to merge 1 commit into
CoreBunch:mainfrom
tommy230:fix/style-block-unclosed-media
Open

tommy230 wants to merge 1 commit into
CoreBunch:mainfrom
tommy230:fix/style-block-unclosed-media

Conversation

@tommy230

Copy link
Copy Markdown
Contributor

Summary

If one <style> block on an imported page is missing a closing }, every <style> block after it ends up inside that block's media query. The later rules then apply only at that breakpoint.

<style>.nav a{color:#fff}@media (max-width:600px){.nav{display:none}</style>
<style>.nav a{color:#1e1e1e}</style>

A browser parses each <style> element as its own stylesheet, so the open @media ends with the first block. The importer joins the blocks into one string before parsing, which loses that boundary.

The fix closes whatever each block leaves open (braces, a comment, a string) before joining. Braces inside comments and strings are ignored. Balanced blocks are left unchanged.

Verification

  • bun run build
  • bun run lint
  • bun test: 7056 pass, 0 fail
  • Docker/deployment check, if relevant: not relevant

New tests in src/__tests__/htmlImport/mapping.test.ts fail on main and pass with this change.

Checklist

  • Tests cover behavior changes.
  • Docs were updated when behavior, config, deployment, or public surfaces changed.
  • No compatibility shim was added for old pre-release behavior.
  • No secrets, local databases, uploads, or generated artifacts are included.

🤖 Generated with Claude Code

A browser parses each <style> element as its own stylesheet, so an
unclosed @media or rule at the end of one block ends at that block. The
importer joins a page's blocks into one source, so one missing `}` pulled
every later block into the media query. Close each block's open braces,
comment, or string before joining.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant