Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linked sourcemap annotations are incorrect when publicPath is not absolute #3922

Open
simon-paris opened this issue Sep 25, 2024 · 0 comments

Comments

@simon-paris
Copy link

simon-paris commented Sep 25, 2024

When publicPath is relative, it gets prepended to the sourcemap annotation, and I think that's incorrect.

Example:

  • Public path: ./build/
  • Script tag: <script src="./build/out.js"/>
  • Sourcemap annotation: //# sourceMappingURL=./build/out.js.map
  • Resolved sourcemap location: ./build/build/out.js.map

The correct annotation would be //# sourceMappingURL=out.js.map because sourcemaps are relative to the script tag src. The same issue happens if publicPath is build or /build.

I think the correct behavior is to prepend the publicPath only if it is absolute.

Sourcemap spec: https://github.com/tc39/source-map-spec/blob/main/source-map-rev3.md

When the source mapping URL is not absolute, then it is relative to the generated code’s “source origin”. The source origin is determined by one of the following cases:

  • If the generated source is not associated with a script element that has a “src” attribute and there exists a //# sourceURL comment in the generated code, that comment should be used to determine the source origin. Note: Previously, this was “//@ sourceURL”, as with “//@ sourceMappingURL”, it is reasonable to accept both but //# is preferred.
  • If the generated code is associated with a script element and the script element has a “src” attribute, the “src” attribute of the script element will be the source origin.
  • If the generated code is associated with a script element and the script element does not have a “src” attribute, then the source origin will be the page’s origin.
  • If the generated code is being evaluated as a string with the eval() function or via new Function(), then the source origin will be the page’s origin.

Related issues:

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

No branches or pull requests

1 participant