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

fix: source map sources #1741

Merged
merged 3 commits into from Nov 18, 2022
Merged

fix: source map sources #1741

merged 3 commits into from Nov 18, 2022

Conversation

rschristian
Copy link
Member

@rschristian rschristian commented Sep 20, 2022

What kind of change does this PR introduce?

bugfix

Did you add tests for your changes?

Will do

Summary

The source maps we're generating at the moment are quite junk, unfortunately.

"sources":[
   "webpack:///webpack/bootstrap",
   "webpack:///../node_modules/@preact/async-loader/async.js",
   "webpack:///./components/header/style.css",
   "webpack:///./components/header/index.js",
   "webpack:///./routes/home/index.js?ae36",
   "webpack:///./routes/profile/index.js?3d3e",
   "webpack:///./index.js",
   "webpack:///./components/app.js",
   "webpack:///../src/util.js",
   "webpack:///../src/index.js",
   "webpack:///../src/create-element.js",
   "webpack:///../src/component.js",
   "webpack:///../src/diff/children.js",
   "webpack:///../src/diff/props.js",
   "webpack:///../src/diff/index.js",
   "webpack:///../src/render.js",
   "webpack:///../src/clone-element.js",
   "webpack:///../src/create-context.js",
   "webpack:///../src/options.js",
   "webpack:///../src/constants.js",
   "webpack:///../src/diff/catch-error.js",
   "webpack:///../node_modules/preact-cli/lib/lib/entry.js",
   "webpack:///../node_modules/preact-router/match.js"
]

This is the "sources" key taken from bundle.<hash>.js.map from our default template. Notice some of those entries like ../src/diff/children.js or ../src/util.js. Apparently, Webpack's handling of sourcemaps without their sourcemap loader is quite poor, and leads to situations like this. Now we'd recognize that as being from Preact itself, but to a user? Who knows where that's from.

Result after this change:

"sources":[
   "webpack:///webpack/bootstrap",
   "webpack:///../node_modules/@preact/async-loader/async.js",
   "webpack:///./components/header/style.css",
   "webpack:///./components/header/index.js",
   "webpack:///./routes/home/index.js?6827",
   "webpack:///./routes/profile/index.js?245c",
   "webpack:///./index.js",
   "webpack:///./components/app.js",
   "webpack:///../node_modules/preact-router/src/util.js",
   "webpack:///../node_modules/preact-router/src/index.js",
   "webpack:///../node_modules/preact/src/util.js",
   "webpack:///../node_modules/preact/src/create-element.js",
   "webpack:///../node_modules/preact/src/component.js",
   "webpack:///../node_modules/preact/src/diff/children.js",
   "webpack:///../node_modules/preact/src/diff/props.js",
   "webpack:///../node_modules/preact/src/diff/index.js",
   "webpack:///../node_modules/preact/src/render.js",
   "webpack:///../node_modules/preact/src/clone-element.js",
   "webpack:///../node_modules/preact/src/create-context.js",
   "webpack:///../node_modules/preact/src/options.js",
   "webpack:///../node_modules/preact/src/constants.js",
   "webpack:///../node_modules/preact/src/diff/catch-error.js",
   "webpack:///../node_modules/preact-cli/lib/lib/entry.js",
   "webpack:///../node_modules/preact-router/match.js"
]

We set Webpack's context to env.src, hence the maybe odd looking paths. All works great though, no longer is Preact stuff mixed with user code in a debugger!

The changes to prerender.js are just for skipping work. #1426 limited showing the code frame to user code but our handler still did the full work of trying to track down the position regardless. I can extract it out to a separate PR if desirable, was chasing down a prerender error for Signals and was butting up against poor error message logic and broken source maps.

Does this PR introduce a breaking change?

No

@changeset-bot
Copy link

changeset-bot bot commented Sep 20, 2022

🦋 Changeset detected

Latest commit: 173de93

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

This PR includes changesets to release 1 package
Name Type
preact-cli Patch

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

@rschristian rschristian marked this pull request as ready for review November 17, 2022 07:51
@rschristian rschristian requested a review from a team as a code owner November 17, 2022 07:51
@rschristian rschristian merged commit 82662af into master Nov 18, 2022
@rschristian rschristian deleted the fix/source-maps branch November 18, 2022 23:45
@preact-bot preact-bot mentioned this pull request Nov 18, 2022
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.

None yet

2 participants