-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Switch from cheap-module-source-map eval-source-map #4930
Conversation
@@ -77,7 +77,7 @@ module.exports = { | |||
mode: 'development', | |||
// You may want 'eval' instead if you prefer to see the compiled output in DevTools. | |||
// See the discussion in https://github.com/facebook/create-react-app/issues/343 | |||
devtool: 'cheap-module-source-map', | |||
devtool: 'source-map', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's tough. I'd be curious to get thoughts from others. In my experience, source-map
gets pretty slow for large bundles because it is a lot of work to regenerate the full map of the bundle. You can't cache things very well because any change to any file will force the recalculation of mappings for any file after the one that changed in the bundle. I usually go for eval-source-map
for that reason.
If such an expensive option is chosen, source maps should probably be mad optional in dev as they already are in prod https://github.com/facebook/create-react-app/blob/3a51fde1bdd1841c156d14bfc08c8046f303b9ba/packages/react-scripts/config/webpack.config.prod.js#L98 I personally always disable source maps in the browser anyway as I've yet to see a case where they are more helpful than problematic. |
Good point @loganfsmyth. I can look into |
f8e1039
to
a891114
Compare
I just tested several of the webpack devtool modes with the debugger.html format: source-map: average compile times 1853.48 over 8 runs It looks like, there were two sets of times (1.5 sec) (600 ms). Thanks @loganfsmyth for the summary above about the benefits of eval-source-maps. @Pajn I agree it could be nice to add a new option. It looks like |
Thanks for doing this research! Can you make sure the error overlay still works please? |
@Timer I'm not sure @jasonLaster is familiar with what error overlay is |
That's fair, @jasonLaster: if you edit <img
onClick={() => {
document.body()
}}
src={logo}
className="App-logo"
alt="logo"
/> Running the dev server and triggering this exception should cause an overlay to appear: If this doesn't work, can you please provide more details on where the sourcemaps are located and how to retrieve them? |
Nice catch. Looks like it is missed |
The travis failure looks like a node 10 timeout. The others pass |
I think we'll need to update this logic: but it shouldn't be a big deal... we do similar things on the debugger side to get the maps :) |
I restarted the one job. Unfortunately, we don't have tests that make sure the error overlay is working so Travis won't catch this. This file probably needs adjusted: https://github.com/facebook/create-react-app/blob/next/packages/react-error-overlay/src/utils/getSourceMap.js edit: you beat me to it! Think you can take care of this? 😄 |
I'm running into a couple of issues getting the data for the error overlay: A bit of context, with This has a couple of interesting effects
As an aside, I wish that there were a devtools extension api that would let you from content just get this data. We have it within the devtools client and would be happy to share :) [1] "use strict";
eval("<source contents>;n//# //# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJz\n//#sourceURL=webpack-internal:///...") |
a891114
to
7c28534
Compare
@Timer and I paired on a solution, which lets us use eval-based sourcemaps and continues to support the error overlay. There are a couple of benefits with eval-based sourcemaps
The significant change is that there is no longer a single bundle.js map file, which the error overlay can use to map the error stack. The PR introduces a new webpack dev middleware, which lets the error overlay fetch the generated source and retrieve the sourcemap as it did before. As a side note, the error overlay will not support errors that occur during render methods as One potential risk with this approach is that it does rely on a couple of implementation details with webpack and the dev-server. I think eventually it would be nice if the middleware were maintained from within the webpack project as it is likely useful for other projects that use Firefox Scope & Variable Mappingindex 7e261ca..0ab8fa1 100644
--- a/packages/react-scripts/template/src/App.js
+++ b/packages/react-scripts/template/src/App.js
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
+import { dancer } from './emojis'
class App extends Component {
render() {
@@ -8,13 +9,12 @@ class App extends Component {
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
+ <h1>{dancer}</h1>
<a
diff --git a/packages/react-scripts/template/src/emojis.js b/packages/react-scripts/template/src/emojis.js
new file mode 100644
index 0000000..c335a60
--- /dev/null
+++ b/packages/react-scripts/template/src/emojis.js
@@ -0,0 +1,3 @@
+const dancer = "🕺"; |
7c28534
to
003396b
Compare
@@ -34,7 +34,11 @@ async function map( | |||
}); | |||
await settle( | |||
files.map(async fileName => { | |||
const fileSource = await fetch(fileName).then(r => r.text()); | |||
const fetchUrl = fileName.startsWith('webpack-internal:') | |||
? `/getInternalSource?fileName=${encodeURIComponent(fileName)}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we export this URL from a package? That way if we change it we don't need to update two places.
See https://github.com/facebook/create-react-app/blob/next/packages/react-dev-utils/launchEditorEndpoint.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we should probably make this more in line with the other url, i.e. /__get-internal-source
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/__get-internal-source.
👍
Can we export this URL from a package?
I'm a bit worried about importing that module in react-error-overlay. It looks like react-dev-utils might be a new dependency.
003396b
to
7fd0e96
Compare
It looks like chrome stable and safari fail to show the error overlay with eval-source-map. Based on that, I think we should likely switch back to cheap-module-source-map for the time being.
[2] |
Fixes issue
Switches webpack's devtool mode from
cheap-module-source-map
tosource-map
so that the mappings include column positions.This enables variable and scope mappings in Firefox, which makes it easier to debug applications built with webpack and babel. This should fix the
this
mapping issue. It will also simplify the scopes pane by showing the "original" scopes and variables. It will also enable in-line code preview and console support when evaluating "original" expressions.The incremental build times were 25% slower for
source-map
vscheap-module-source-maps
(500ms vs 400ms) on a simple app. I believe that webpack's cache means that these numbers would not be that different on a larger app.Both modes had equivalent breakpoint support on page load and while the app was running.
Chrome
Firefox