Skip to content

fix(html): skip unsupported <script> types instead of treating as JS (fixes #9506, #9479)#9515

Merged
ematipico merged 1 commit intobiomejs:mainfrom
shivamtiwari3:fix/skip-unsupported-script-types
Mar 17, 2026
Merged

fix(html): skip unsupported <script> types instead of treating as JS (fixes #9506, #9479)#9515
ematipico merged 1 commit intobiomejs:mainfrom
shivamtiwari3:fix/skip-unsupported-script-types

Conversation

@shivamtiwari3
Copy link
Contributor

@shivamtiwari3 shivamtiwari3 commented Mar 16, 2026

Summary

Fixes #9506
Fixes #9479.

The embed registry's script element detector was using fallback: Some(GuestLanguage::JsScript) in its EmbedTarget::Dynamic config. When resolve_script_language returned None for types like speculationrules or application/ld+json (which are ScriptType::Unsupported), EmbedTarget::resolve() applied the JsScript fallback via .or(*fallback), causing biome to parse non-JavaScript content as JavaScript.


Root Cause

In crates/biome_service/src/embed/registry.rs, HTML_DETECTORS had:

EmbedDetector::Element {
    tag: "script",
    target: EmbedTarget::Dynamic {
        resolver: resolve_script_language,
        fallback: Some(GuestLanguage::JsScript),  // ← problem
    },
},

resolve_script_language correctly returns None for ScriptType::Unsupported types (line if !script_type.is_javascript() { return None; }). However, EmbedTarget::resolve() applies the fallback when the resolver returns None:

Self::Dynamic { resolver, fallback } => resolver(candidate, file_source).or(*fallback),

So speculationrules and application/ld+json content was being passed to the JavaScript parser, producing false parse errors and incorrect lint diagnostics.


Solution

Remove the fallback (fallback: None). The resolve_script_language function already returns a correct GuestLanguage for every legitimate JavaScript script case — it only returns None for unsupported types or non-HTML file sources, both of which should mean "skip this element".


Testing

  • Added no_diagnostics_for_unsupported_script_types in crates/biome_service/src/workspace/server.tests.rs that reproduces the exact scenario from both issues: an HTML file containing <script type="speculationrules"> and <script type="application/ld+json"> blocks. The test asserts zero diagnostics are returned.
  • All existing biome_service tests (98) and biome_html_formatter tests (127) pass.

Checklist

  • Fixes the root cause (not just the symptom)
  • New test covers the exact failing scenario from the issues
  • All existing tests pass
  • No unrelated changes
  • Code style matches project conventions
  • Read CONTRIBUTING.md and followed its requirements

This PR was written primarily by Claude Code.

…ixes biomejs#9506, biomejs#9479)

Root cause: EmbedTarget::Dynamic for the script element detector had
`fallback: Some(GuestLanguage::JsScript)`. When resolve_script_language
returned None for types like speculationrules or application/ld+json
(which are Unsupported in ScriptType), the fallback applied JsScript,
causing biome to parse non-JS content as JavaScript and report false
parse errors.

Fix: Remove the fallback (set to None). The resolver already returns
an appropriate JS GuestLanguage for all valid JS script cases, so None
from the resolver always means "skip this element".
@changeset-bot
Copy link

changeset-bot bot commented Mar 16, 2026

🦋 Changeset detected

Latest commit: 6d3a70d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the A-Project Area: project label Mar 16, 2026
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I know the fix was simple :)

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 16, 2026

Walkthrough

This pull request fixes false parse errors reported by Biome for unsupported HTML script types. Changes include modifying the script and style detector fallbacks from returning a default guest language to returning None, which signals to skip unsupported types entirely. Documentation has been expanded to clarify which script types are handled (speculationrules, application/ld+json, text/x-handlebars-\*) and how the resolver determines embedding behaviour. Regression tests validate that these script types no longer produce spurious diagnostics.

Suggested labels

A-Project, A-Parser, L-HTML

Suggested reviewers

  • ematipico
  • dyc3
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarises the main fix: removing the incorrect JsScript fallback for unsupported script types like speculationrules and application/ld+json.
Linked Issues check ✅ Passed The PR successfully addresses both linked issues (#9506 and #9479) by removing the incorrect fallback that caused false parse errors for unsupported script types like speculationrules and application/ld+json.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the embed registry's script detector fallback behaviour. The changeset entry, registry modifications, and regression test are all focused on the stated problem.
Description check ✅ Passed The description comprehensively explains the root cause, solution, and testing approach for fixing false parse errors in unsupported script types.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use Trivy to scan for security misconfigurations and secrets in Infrastructure as Code files.

Add a .trivyignore file to your project to customize which findings Trivy reports.

@ematipico ematipico merged commit f85c069 into biomejs:main Mar 17, 2026
14 checks passed
@github-actions github-actions bot mentioned this pull request Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Project Area: project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 biome 2.4.7 breaks speculation rules 💅 Linter treating application/ld+json script tags as JS in 2.4.7

2 participants