Skip to content

fix: resolve a data: resource from the loader's context - #1352

Merged
alexander-akait merged 3 commits into
mainfrom
fix/data-uri-resource
Oct 27, 2026
Merged

alexander-akait merged 3 commits into
mainfrom
fix/data-uri-resource

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Summary

webpack's HTML support (webpack/webpack#22940) sends an inline <style lang="scss"> body to loaders as a data:text/x-scss module. A data: URI has no path, so sass-loader resolved relative @use / @import against the URI itself and couldn't read the syntax from an extension.

Now a data: resource reads as stdin.scss / stdin.sass in this.context, and text/x-sass selects the indented syntax.

before: @use "./partials/vars"  →  Can't find stylesheet to import.
after:  resolved from the page's directory

Relative imports resolve from the page once webpack/webpack#22940 is released, which gives data: modules their referrer's directory as this.context; on older webpack this is a no-op. The test sets that context itself, so it runs on the released webpack.

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

Yes, test/data-uri.test.js (relative @use and indented syntax from the media type); it fails without this fix.

Does this PR introduce a breaking change?

No.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

n/a (webpack.js.org#8462 documents inline <style lang>).

Use of AI

Written with Claude Code under my direction; I reviewed it.

🤖 Generated with Claude Code

https://claude.ai/code/session_0127uEXaa4uCDQstWhYDegGb

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Sass compilation from data: URIs. SCSS imports now resolve from the loader context, and text/x-sass data URIs are read as indented Sass syntax.
    • Added coverage confirming that both SCSS and indented Sass supplied through data: URIs compile successfully and produce CSS.

A data: URI has no path, so relative @use / @import resolved against the
URI itself and the syntax could not be read from an extension. Resolve
from this.context (the referrer's directory with webpack giving data:
modules their issuer's context) and read text/x-sass as indented.
@changeset-bot

changeset-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eb24f3f

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

This PR includes changesets to release 1 package
Name Type
sass-loader Minor

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

The test loader sets this.context the way webpack/webpack#22940 does,
so the test checks the loader on the released webpack too.
@alexander-akait
alexander-akait marked this pull request as ready for review October 27, 2026 15:33
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ee118e0c-e425-4847-8eb7-9506c9e8eaa9
Commits

Reviewing files that changed from the base of the PR and between e3ef0d0 and eb24f3f.

Files selected for processing: 1
  • types/utils.d.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Walkthrough

The loader now maps data: resources to context-relative Sass paths. It selects stdin.sass for text/x-sass resources and stdin.scss for other data URIs. Sass option setup and the modern importer use the resolved path. Dependency registration excludes the matching synthetic path. Tests cover SCSS and indented Sass compilation across implementation and API pairs.

Priority: Normal

Merge Risk: Low · up to eb24f

Inline Sass can fail for projects containing a context-level stdin.scss or stdin.sass file; avoid merging until the synthetic path is collision-safe.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: resolve a data: resource from the loader's context" matches the main change. The changeset resolves data: URIs (such as inline <style lang="scss"> content) to stdin.scss or stdin.sass …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix: resolve a data: resource from the loader's context" matches the main change. The changeset resolves data: URIs (such as inline <style lang="scss"> content) to stdin.scss or stdin.sass under the loader context. The title is short, specific, and uses the conventional fix: prefix. It names the core behavior and does not describe unrelated work.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 5 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ef3dea51-5ee6-44ae-acfb-b1963ece5a88
Commits

Reviewing files that changed from the base of the PR and between 6670e5a and e3ef0d0.

Files selected for processing: 5
  • .changeset/data-uri-resource.md
  • src/index.js
  • src/utils.js
  • test/data-uri.test.js
  • test/helpers/dataUriContextLoader.cjs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread src/utils.js Resolved
@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.72%. Comparing base (6670e5a) to head (eb24f3f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1352      +/-   ##
==========================================
+ Coverage   96.62%   96.72%   +0.09%     
==========================================
  Files           2        2              
  Lines        1007     1037      +30     
==========================================
+ Hits          973     1003      +30     
  Misses         34       34              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alexander-akait
alexander-akait merged commit 8ecb2f0 into main Oct 27, 2026
16 checks passed
@alexander-akait
alexander-akait deleted the fix/data-uri-resource branch October 27, 2026 16:14
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