Repository navigation
fix: resolve a data: resource's imports from the loader's context - #480
Conversation
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.
WalkthroughThe loader now uses a context-based resource path when the resource path starts with Priority: Merge Risk:
|
There was a problem hiding this comment.
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
Files selected for processing: 5-
.changeset/data-uri-resource.mdsrc/utils.jstest/data-uri.test.jstest/fixtures/data-uri-vars.styltest/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.
-
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Summary
webpack's HTML support (webpack/webpack#22940) sends an inline
<style lang="stylus">body to loaders as adata:text/stylusmodule. Adata:URI has no path, so Stylus resolved relative imports against the URI itself and reported an invalid dependencydata:text/package.json.Now a
data:resource reads asstdin.stylinthis.context.Relative imports resolve from the page once webpack/webpack#22940 is released, which gives
data:modules their referrer's directory asthis.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
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.