Repository navigation
fix(preview): keep preview scaffolding hidden when the user styles * - #293
Merged
midudev merged 2 commits intoOct 20, 2026
Merged
Conversation
`* { display: flex }` outranks the browser's internal stylesheet that hides
`<style>` and `<script>`, so the raw CSS and JS text rendered inside the
preview. Add a reset with `!important` after the user's `<style>` element.
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.
The preview document holds the user's CSS in
<style id="preview-style">and their JavaScript in<script type="module">. The browser hides both tags through its internal stylesheet. A user rule like* { display: flex }outranks that stylesheet, since author styles beat user-agent styles at any specificity. The raw code text then renders in the preview, next to the result.Repro: open https://codi.link and set the CSS to
* { display: flex }.Both come from the same sandbox with the CSS tab selected: HTML
<div class="board">board</div>, CSS* { display: flex }plus.board { border: 2px solid #000; width: 400px; height: 400px }.Fix
The reset goes into the generated document. It sits after the user's
<style>, so it wins specificity ties as well:!importantmatters, because* { display: flex !important }is possible too. Otherwise nothing changes: the reset restores the browser's default, and user selectors keep applying to the user's own elements.The ZIP export uses the same document.
src/download.jsbuilds itsindex.htmlfromcreateHtml, so the fix covers that path.Verification
Chromium, document generated by
createHtmlfor* { display: flex }:#preview-stylecomputed displaybun run lintpasses.