preact-cli icon indicating copy to clipboard operation
preact-cli copied to clipboard

fix: source map sources

Open rschristian opened this issue 3 years ago • 1 comments

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"
]

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.

Also now have slightly less jumbled up errors:

  • Before Before
  • After After

Does this PR introduce a breaking change?

No

rschristian avatar Sep 20 '22 03:09 rschristian

🦋 Changeset detected

Latest commit: 173de93762f175b04906cbafc2c2b69b46e0a85f

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

changeset-bot[bot] avatar Sep 20 '22 03:09 changeset-bot[bot]