Avoid relying on buggy import order in the legacy importer#245
Merged
Conversation
Historically, the legacy importer shim has strongly assumed that all calls to `canonicalize()` would doubled: once as a URL resolved relative to the current importer, and again as a URL passed to the importers list. However, this relies on buggy, non-spec-compliant behavior in Dart Sass: absolute URLs should never be passed to the current importer, only to the global list of importers. This change avoids relying on that behavior by instead disambiguating relative loads using a custom URL protocol prefix. All canonical URLs passed to Dart Sass now have the prefix `legacy-importer-` added to the beginning. This allows us to disambiguate relative loads, and ignore them for non-`file:` URLs, since relative loads and _only_ relative loads will have schemes beginning with `legacy-importer-`. To avoid regressing the developer experience, we then strip these prefixes from all URLs before they're passed to any developer-facing APIs or displayed to the user.
jathak
approved these changes
Sep 8, 2023
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.
Historically, the legacy importer shim has strongly assumed that all
calls to
canonicalize()would doubled: once as a URL resolvedrelative to the current importer, and again as a URL passed to the
importers list. However, this relies on buggy, non-spec-compliant
behavior in Dart Sass: absolute URLs should never be passed to the
current importer, only to the global list of importers.
This change avoids relying on that behavior by instead disambiguating
relative loads using a custom URL protocol prefix. All canonical URLs
passed to Dart Sass now have the prefix
legacy-importer-added tothe beginning. This allows us to disambiguate relative loads, and
ignore them for non-
file:URLs, since relative loads and onlyrelative loads will have schemes beginning with
legacy-importer-.To avoid regressing the developer experience, we then strip these
prefixes from all URLs before they're passed to any developer-facing
APIs or displayed to the user.
See sass/sass-spec#1935
See sass/dart-sass#2077