Skip to content

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

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

alexander-akait merged 2 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="stylus"> body to loaders as a data:text/stylus module. A data: URI has no path, so Stylus resolved relative imports against the URI itself and reported an invalid dependency data:text/package.json.

Now a data: resource reads as stdin.styl in this.context.

before: warning "Invalid dependencies … data:text/package.json", relative @import unresolved
after:  resolved from the page's directory, no warning

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; 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
    • Stylus imports from data: resources now resolve using the configured context. This improves compatibility when compiling data-URI stylesheets and ensures the resulting CSS includes the expected rules and values.

A data: URI has no path, so Stylus resolved relative imports against the
URI itself and a dependency like data:text/package.json was reported.
Read the entry as a file in this.context (the referrer's directory with
webpack giving data: modules their issuer's context).
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:34
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Walkthrough

The loader now uses a context-based resource path when the resource path starts with data:. This path is used for Stylus options, dependency collection, configured import resolution, and entrypoint detection. A new test compiles a data URI with a context-configured loader and checks the emitted CSS. The changeset declares a minor release.

Priority: Normal

Merge Risk: Low · up to d9836

A data-URI stylesheet importing a real stdin.styl file may fail to resolve that file’s nested imports. The issue is narrow, but should be addressed or explicitly accepted before merging.

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 clearly and concisely describes the main change: resolving imports from a data: resource using the loader's context.
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: 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 4 functions across 3 files. (2 skipped: 2 unsupported.)

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: 43a28002-4c05-4b1a-ba6e-c5a3b9783868
Commits

Reviewing files that changed from the base of the PR and between 936ff82 and d983691.

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

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 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.25%. Comparing base (936ff82) to head (d983691).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #480      +/-   ##
==========================================
+ Coverage   96.21%   96.25%   +0.04%     
==========================================
  Files           2        2              
  Lines        1269     1283      +14     
==========================================
+ Hits         1221     1235      +14     
  Misses         48       48              

☔ 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 28c8929 into main Oct 27, 2026
16 checks passed
@alexander-akait
alexander-akait deleted the fix/data-uri-resource branch October 27, 2026 17:11
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