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 Component Stacks for IE and Native Classes in Safari #18575

Merged
merged 5 commits into from
Apr 11, 2020

Conversation

sebmarkbage
Copy link
Collaborator

This is a follow up to #18561

It adds more test cases and includes a fix to Safari since Safari adds another stack frame for the construct call. Polyfills might do something similar so this tries to be resilient by skipping over those.

Results from fixtures

Chrome:


    at Lazy
    at Component (http://localhost:8000/fixtures/stacks/Components.js:7:50)
    at div
    at Suspense
    at BabelClassWithFields (http://localhost:8000/fixtures/stacks/BabelClasses-compiled.js:54:31)
    at BabelClass (http://localhost:8000/fixtures/stacks/BabelClasses-compiled.js:36:29)
    at FrozenClass (http://localhost:8000/fixtures/stacks/Components.js:24:5)
    at NativeClass (http://localhost:8000/fixtures/stacks/Components.js:16:1)
    at SuspenseList
    at Custom Name (http://localhost:8000/fixtures/stacks/Components.js:11:23)
    at ErrorBoundary (http://localhost:8000/fixtures/stacks/Example.js:5:1)
    at Example (http://localhost:8000/fixtures/stacks/Example.js:33:21)

Firefox:


Lazy
Component@http://localhost:8000/fixtures/stacks/Components.js:7:1
div
Suspense
BabelClassWithFields@http://localhost:8000/fixtures/stacks/BabelClasses-compiled.js:54:31
BabelClass@http://localhost:8000/fixtures/stacks/BabelClasses-compiled.js:36:29
FrozenClass@http://localhost:8000/fixtures/stacks/Components.js:24:5
NativeClass@http://localhost:8000/fixtures/stacks/Components.js:16:49
SuspenseList
DisplayName@http://localhost:8000/fixtures/stacks/Components.js:11:1
ErrorBoundary@http://localhost:8000/fixtures/stacks/Example.js:5:49
Example@http://localhost:8000/fixtures/stacks/Example.js:33:21

Note: Firefox doesn't respect displayName in stack traces.

Safari:


Lazy
Component@http://localhost:8000/fixtures/stacks/Components.js:7:48
div
Suspense
BabelClassWithFields@http://localhost:8000/fixtures/stacks/BabelClasses-compiled.js:54:35
BabelClass@http://localhost:8000/fixtures/stacks/BabelClasses-compiled.js:36:34
FrozenClass@http://localhost:8000/fixtures/stacks/Components.js:24:10
NativeClass
SuspenseList
Custom Name@http://localhost:8000/fixtures/stacks/Components.js:11:21
ErrorBoundary
Example@http://localhost:8000/fixtures/stacks/Example.js:33:29

Note: Safari doesn't give us a line number for native classes without an explicit constructor.

Also adjust some expectations. I think the column should ideally be 1 but varies.
The Example row is one line off because it throws on the hook but should ideally be the component.
Similarly class components with constructors may have the line in the constructor.
We do this by first searching for the first different frame, then find
the same frames and then find the first different frame again.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Apr 11, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 11, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5007c88:

Sandbox Source
condescending-wilson-0pdup Configuration

@sizebot
Copy link

sizebot commented Apr 11, 2020

Details of bundled changes.

Comparing: 98d410f...5007c88

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js +0.9% +0.7% 110.44 KB 111.38 KB 26.99 KB 27.18 KB UMD_DEV
react.production.min.js 0.0% 0.0% 12.29 KB 12.29 KB 4.82 KB 4.82 KB UMD_PROD
JSXRuntime-dev.js +2.2% +1.5% 38.68 KB 39.54 KB 11 KB 11.17 KB FB_WWW_DEV
react-jsx-dev-runtime.development.js +2.6% +1.7% 33.93 KB 34.81 KB 10.09 KB 10.26 KB NODE_DEV
react-jsx-dev-runtime.production.min.js 0.0% 🔺+0.3% 454 B 454 B 321 B 322 B NODE_PROD
JSXDEVRuntime-dev.js +2.3% +1.5% 38.1 KB 38.96 KB 10.83 KB 10.99 KB FB_WWW_DEV
react-jsx-runtime.development.js +2.5% +1.7% 34.51 KB 35.39 KB 10.26 KB 10.43 KB NODE_DEV
react.development.js +1.2% +1.0% 71.62 KB 72.5 KB 19.25 KB 19.44 KB NODE_DEV
react.production.min.js 0.0% 0.0% 7.27 KB 7.27 KB 2.89 KB 2.89 KB NODE_PROD
React-dev.js +0.9% +0.7% 96.85 KB 97.71 KB 23.71 KB 23.88 KB FB_WWW_DEV

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-server.browser.development.js +0.6% +0.4% 161.26 KB 162.2 KB 41.04 KB 41.21 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 23.39 KB 23.39 KB 8.6 KB 8.6 KB UMD_PROD
react-dom.profiling.min.js +0.2% +0.2% 128.26 KB 128.53 KB 40.11 KB 40.19 KB NODE_PROFILING
ReactDOM-dev.js +0.1% +0.1% 988.57 KB 989.54 KB 219.72 KB 219.94 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.2% 🔺+0.2% 412.5 KB 413.18 KB 74.82 KB 74.96 KB FB_WWW_PROD
ReactDOM-profiling.js +0.2% +0.2% 423.4 KB 424.08 KB 76.67 KB 76.81 KB FB_WWW_PROFILING
react-dom-test-utils.development.js 0.0% 0.0% 75.14 KB 75.14 KB 20.12 KB 20.12 KB UMD_DEV
ReactDOMTesting-dev.js 0.0% 0.0% 931.52 KB 931.63 KB 207.54 KB 207.58 KB FB_WWW_DEV
ReactDOMTesting-prod.js 0.0% 🔺+0.1% 393.62 KB 393.72 KB 71.77 KB 71.81 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% 0.0% 69.98 KB 69.98 KB 19.61 KB 19.61 KB NODE_DEV
ReactDOMTesting-profiling.js 0.0% +0.1% 393.62 KB 393.72 KB 71.77 KB 71.81 KB FB_WWW_PROFILING
react-dom-server.node.development.js +0.6% +0.4% 153.02 KB 153.9 KB 40.52 KB 40.69 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 13.1 KB 13.1 KB 4.81 KB 4.81 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 23.69 KB 23.69 KB 8.72 KB 8.72 KB NODE_PROD
react-dom-server.browser.development.js +0.6% +0.4% 151.8 KB 152.68 KB 40.27 KB 40.44 KB NODE_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 23.28 KB 23.28 KB 8.57 KB 8.57 KB NODE_PROD
react-dom.development.js +0.1% +0.1% 939.84 KB 940.9 KB 205.37 KB 205.6 KB UMD_DEV
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 56.11 KB 56.11 KB 13.85 KB 13.85 KB UMD_DEV
react-dom.production.min.js 🔺+0.2% 🔺+0.2% 124.06 KB 124.33 KB 39.64 KB 39.71 KB UMD_PROD
ReactDOMForked-dev.js +0.1% +0.1% 988.59 KB 989.56 KB 219.87 KB 220.09 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10 KB 10 KB 3.36 KB 3.36 KB UMD_PROD
ReactDOMServer-dev.js +0.5% +0.4% 160.6 KB 161.46 KB 40.83 KB 40.99 KB FB_WWW_DEV
react-dom.profiling.min.js +0.2% +0.2% 127.91 KB 128.18 KB 40.87 KB 40.93 KB UMD_PROFILING
ReactDOMForked-prod.js 🔺+0.2% 🔺+0.2% 413.07 KB 413.75 KB 74.91 KB 75.04 KB FB_WWW_PROD
react-dom.development.js +0.1% +0.1% 894.89 KB 895.88 KB 202.89 KB 203.11 KB NODE_DEV
ReactDOMForked-profiling.js +0.2% +0.2% 423.97 KB 424.65 KB 76.77 KB 76.91 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 53.21 KB 53.21 KB 13.65 KB 13.65 KB NODE_DEV
react-dom.production.min.js 🔺+0.2% 🔺+0.2% 124.26 KB 124.53 KB 38.87 KB 38.96 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% -0.3% 1.17 KB 1.17 KB 669 B 667 B NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.2% +0.2% 657.16 KB 658.21 KB 138.22 KB 138.44 KB UMD_DEV
react-art.production.min.js 🔺+0.2% 🔺+0.2% 110.19 KB 110.46 KB 33.35 KB 33.43 KB UMD_PROD
react-art.development.js +0.2% +0.2% 560.53 KB 561.52 KB 120.7 KB 120.9 KB NODE_DEV
react-art.production.min.js 🔺+0.4% 🔺+0.4% 75.14 KB 75.41 KB 22.57 KB 22.66 KB NODE_PROD
ReactART-dev.js +0.2% +0.2% 594.93 KB 595.9 KB 125.2 KB 125.4 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.3% 🔺+0.4% 242.98 KB 243.66 KB 41.26 KB 41.41 KB FB_WWW_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler-reflection.development.js 0.0% 0.0% 16.23 KB 16.23 KB 4.92 KB 4.92 KB NODE_DEV
react-reconciler.development.js +0.2% +0.2% 602.26 KB 603.25 KB 127.35 KB 127.55 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.3% 🔺+0.4% 80.54 KB 80.82 KB 23.83 KB 23.91 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: 0.0%

React: size: 0.0%, gzip: 0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against 5007c88

@sizebot
Copy link

sizebot commented Apr 11, 2020

Details of bundled changes.

Comparing: 98d410f...5007c88

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
JSXDEVRuntime-dev.js +2.3% +1.6% 38.1 KB 38.96 KB 10.83 KB 11 KB FB_WWW_DEV
react-jsx-runtime.development.js 0.0% 0.0% 30.14 KB 30.14 KB 8.89 KB 8.9 KB NODE_DEV
react-jsx-runtime.profiling.min.js 0.0% +0.2% 946 B 946 B 594 B 595 B NODE_PROFILING
JSXRuntime-dev.js +2.2% +1.5% 38.68 KB 39.54 KB 11 KB 11.17 KB FB_WWW_DEV
react.profiling.min.js 0.0% -0.0% 14.9 KB 14.9 KB 5.63 KB 5.63 KB UMD_PROFILING
react.development.js 0.0% 0.0% 63.43 KB 63.43 KB 17.06 KB 17.06 KB NODE_DEV
React-dev.js +0.9% +0.7% 97.84 KB 98.7 KB 23.9 KB 24.08 KB FB_WWW_DEV
React-prod.js 0.0% 0.0% 17.3 KB 17.3 KB 4.53 KB 4.53 KB FB_WWW_PROD
react-jsx-dev-runtime.development.js 0.0% 0.0% 29.56 KB 29.56 KB 8.72 KB 8.72 KB NODE_DEV
React-profiling.js 0.0% 0.0% 17.3 KB 17.3 KB 4.53 KB 4.53 KB FB_WWW_PROFILING
react-jsx-dev-runtime.profiling.min.js 0.0% +0.3% 440 B 440 B 312 B 313 B NODE_PROFILING

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 119.63 KB 119.7 KB 37.5 KB 37.54 KB NODE_PROD
react-dom-test-utils.development.js 0.0% 0.0% 75.12 KB 75.12 KB 20.11 KB 20.11 KB UMD_DEV
ReactDOMTesting-profiling.js 0.0% 0.0% 405.44 KB 405.55 KB 73.56 KB 73.59 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 22.82 KB 22.82 KB 8.48 KB 8.49 KB NODE_PROD
react-dom.profiling.min.js +0.1% +0.1% 123.51 KB 123.58 KB 38.63 KB 38.67 KB NODE_PROFILING
react-dom-server.node.development.js 0.0% 0.0% 147.14 KB 147.14 KB 38.93 KB 38.93 KB NODE_DEV
react-dom-server.node.production.min.js 0.0% 0.0% 23.23 KB 23.23 KB 8.65 KB 8.65 KB NODE_PROD
ReactDOMForked-dev.js +0.1% +0.1% 1013.85 KB 1014.82 KB 225.11 KB 225.33 KB FB_WWW_DEV
ReactDOMForked-prod.js 🔺+0.2% 🔺+0.2% 424.5 KB 425.18 KB 76.56 KB 76.69 KB FB_WWW_PROD
react-dom.development.js 0.0% 0.0% 907.09 KB 907.21 KB 199.11 KB 199.15 KB UMD_DEV
ReactDOMForked-profiling.js +0.2% +0.2% 435.46 KB 436.14 KB 78.45 KB 78.58 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 155.09 KB 155.09 KB 39.44 KB 39.45 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.2% 1.16 KB 1.16 KB 660 B 659 B NODE_PROD
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 119.51 KB 119.58 KB 38.23 KB 38.26 KB UMD_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 22.92 KB 22.92 KB 8.51 KB 8.52 KB UMD_PROD
react-dom.profiling.min.js +0.1% +0.1% 123.25 KB 123.32 KB 39.48 KB 39.51 KB UMD_PROFILING
ReactDOMTesting-dev.js 0.0% 0.0% 958.06 KB 958.17 KB 213.18 KB 213.22 KB FB_WWW_DEV
react-dom.development.js 0.0% 0.0% 863.52 KB 863.63 KB 196.67 KB 196.72 KB NODE_DEV
ReactDOMTesting-prod.js 0.0% 0.0% 405.44 KB 405.55 KB 73.56 KB 73.59 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% 0.0% 145.92 KB 145.92 KB 38.68 KB 38.68 KB NODE_DEV
ReactDOM-dev.js +0.1% +0.1% 1013.83 KB 1014.81 KB 224.96 KB 225.18 KB FB_WWW_DEV
ReactDOMServer-dev.js +0.5% +0.4% 164.1 KB 164.96 KB 41.73 KB 41.89 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.2% 🔺+0.2% 423.91 KB 424.6 KB 76.46 KB 76.6 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% 0.0% 69.97 KB 69.97 KB 19.6 KB 19.6 KB NODE_DEV
ReactDOMServer-prod.js 0.0% 0.0% 53.3 KB 53.3 KB 12.85 KB 12.85 KB FB_WWW_PROD
ReactDOM-profiling.js +0.2% +0.2% 434.87 KB 435.56 KB 78.37 KB 78.51 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 0.0% -0.0% 13.09 KB 13.09 KB 4.8 KB 4.8 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 56.1 KB 56.1 KB 13.84 KB 13.84 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 9.98 KB 9.98 KB 3.36 KB 3.36 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 53.2 KB 53.2 KB 13.64 KB 13.65 KB NODE_DEV

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js 0.0% 0.0% 633.97 KB 634.08 KB 133.61 KB 133.64 KB UMD_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.1% 107.11 KB 107.18 KB 32.46 KB 32.51 KB UMD_PROD
react-art.development.js 0.0% 0.0% 538.28 KB 538.39 KB 116.03 KB 116.07 KB NODE_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.2% 72.11 KB 72.18 KB 21.65 KB 21.69 KB NODE_PROD
ReactART-dev.js +0.2% +0.2% 604.99 KB 605.96 KB 127.22 KB 127.41 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.3% 🔺+0.3% 250.43 KB 251.11 KB 42.54 KB 42.66 KB FB_WWW_PROD

Size changes (stable)

Generated by 🚫 dangerJS against 5007c88

@sebmarkbage
Copy link
Collaborator Author

There's still one more issue to solve after this. Internet Explorer requires an error to be thrown before it gets a stack. So I'll need to throw instead of just creating the controls.

Otherwise they don't get a stack frame associated with them in IE.
@sebmarkbage
Copy link
Collaborator Author

Ok after these changes it works in IE/Edge.

Edge


   at Lazy
   at Component (http://localhost:8000/fixtures/stacks/Components.js:7:49)
   at div
   at Suspense
   at BabelClassWithFields (http://localhost:8000/fixtures/stacks/BabelClasses-compiled.js:54:5)
   at BabelClass (http://localhost:8000/fixtures/stacks/BabelClasses-compiled.js:36:5)
   at FrozenClass (http://localhost:8000/fixtures/stacks/Components.js:24:5)
   at NativeClass (http://localhost:8000/fixtures/stacks/Components.js:16:43)
   at SuspenseList
   at DisplayName (http://localhost:8000/fixtures/stacks/Components.js:11:22)
   at ErrorBoundary (http://localhost:8000/fixtures/stacks/Example.js:5:45)
   at Example (http://localhost:8000/fixtures/stacks/Example.js:33:3)

IE10/11

After adjusting the fixtures to avoid ES2015 features.


   at Lazy
   at Component (http://localhost:8000/fixtures/stacks/Components.js:8:3)
   at div
   at Suspense
   at BabelClassWithFields (http://localhost:8000/fixtures/stacks/BabelClasses-compiled.js:54:5)
   at BabelClass (http://localhost:8000/fixtures/stacks/BabelClasses-compiled.js:36:5)
   at FrozenClass (http://localhost:8000/fixtures/stacks/Components.js:25:3)
   at NativeClass (http://localhost:8000/fixtures/stacks/Components.js:17:3)
   at SuspenseList
   at DisplayName (http://localhost:8000/fixtures/stacks/Components.js:12:3)
   at ErrorBoundary (http://localhost:8000/fixtures/stacks/Example.js:6:3)
   at Example (http://localhost:8000/fixtures/stacks/Example.js:36:3)

Notably IE8/9 doesn't give you a stack on errors.

@sebmarkbage
Copy link
Collaborator Author

Ok, this turned out to be a bit more code than I had originally hoped. I think we can still shave some bytes off from this implementation but it's still reasonable and much better than people adding meta data to code like displayName or line numbers since that doesn't scale.

@sebmarkbage sebmarkbage changed the title Fix Component Stacks for Native Classes in Safari Fix Component Stacks for IE and Native Classes in Safari Apr 11, 2020
Errors while generating stacks will bubble to the root. Since this technique
is a bit sketchy, we should probably protect against it.
Instead, we pass the prototype as the "this". It's new every time anyway.
@sebmarkbage sebmarkbage merged commit 72d00ab into facebook:master Apr 11, 2020
@bvaughn
Copy link
Contributor

bvaughn commented Apr 11, 2020

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants