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

[Fiber] Prefix owner stacks with the current stack at the console call #29697

Merged
merged 1 commit into from
Jun 3, 2024

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented May 31, 2024

This information is available in the regular stack but since that's hidden behind an expando and our appended stack to logs is not hidden, it hides the most important frames like the name of the current component.

This is closer to what happens to the native stack.

We only include stacks if they're within a ReactFiberCallUserSpace call frame. This should be most that have a current fiber but this is critical to filtering out most React frames if the regular node_modules filter doesn't work.

Most React warnings fire during the rendering phase and not inside a user space function but some do like hooks warnings and setState in render. This feature is more important if we port this to React DevTools appending stacks to all logs where it's likely to originate from inside a component and you want the line within that component to immediately part of the visible stack.

One thing that kind sucks is that we don't have a reliable way to exclude React internal stack frames. We filter node_modules but it might not match. For other cases I try hard to only track the stack frame at the root of React (e.g. immediately inside createElement) until the ReactFiberCallUserSpace so we don't need the filtering to work. In this case it's hard to achieve the same thing though. This is easier in RDT because we have the start/end line and parsing of stack traces so we can use that to exclude internals but that's a lot of code/complexity for shipping within the library.

For example in Safari:

Screenshot 2024-05-31 at 6 15 27 PM

Ideally warnOnUseFormStateInDev and useFormState wouldn't be included since they're React internals. Before this change, the Counter.js line also wasn't included though which points to exactly where the error is within the user code.

(Note Server Components have V8 formatted lines and Client Components have JSC formatted lines.)

This information is available in the regular stack but since that's hidden
behind an expando and our appended stack to logs is not hidden, it hides
the most important frames like the name of the current component.

This is closer to what happens to the native stack.

We only include stacks if they're within a ReactFiberCallUserSpace call frame.
This should be most that have a current fiber but this is critical to filtering
out most React frames if the regular node_modules filter doesn't work.

Most React warnings fire during the rendering phase and not inside a user space
function but some do like hooks warnings and setState in render.

This feature is more important if we port this to React DevTools appending stacks
to all logs.
@sebmarkbage sebmarkbage requested review from eps1lon and hoxyq May 31, 2024 22:17
Copy link

vercel bot commented May 31, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2024 10:21pm

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels May 31, 2024
@react-sizebot
Copy link

Comparing: 8bc81ca...89b976f

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.66 kB 6.66 kB +0.11% 1.82 kB 1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 496.39 kB 496.39 kB = 88.84 kB 88.84 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.67 kB 6.67 kB +0.11% 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 501.21 kB 501.21 kB = 89.54 kB 89.54 kB
facebook-www/ReactDOM-prod.classic.js = 593.88 kB 593.88 kB = 104.46 kB 104.46 kB
facebook-www/ReactDOM-prod.modern.js = 570.26 kB 570.26 kB = 100.87 kB 100.87 kB
oss-stable-semver/react-dom/cjs/react-dom-test-utils.development.js +2.25% 2.75 kB 2.81 kB +1.92% 1.30 kB 1.33 kB
oss-stable/react-dom/cjs/react-dom-test-utils.development.js +2.25% 2.75 kB 2.81 kB +1.92% 1.30 kB 1.33 kB
oss-experimental/react-dom/cjs/react-dom-test-utils.development.js +2.20% 2.82 kB 2.88 kB +1.96% 1.33 kB 1.35 kB
test_utils/ReactAllWarnings.js Deleted 63.65 kB 0.00 kB Deleted 15.90 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable-semver/react-dom/cjs/react-dom-test-utils.development.js +2.25% 2.75 kB 2.81 kB +1.92% 1.30 kB 1.33 kB
oss-stable/react-dom/cjs/react-dom-test-utils.development.js +2.25% 2.75 kB 2.81 kB +1.92% 1.30 kB 1.33 kB
oss-experimental/react-dom/cjs/react-dom-test-utils.development.js +2.20% 2.82 kB 2.88 kB +1.96% 1.33 kB 1.35 kB
oss-stable-semver/react/cjs/react-compiler-runtime.development.js +1.85% 3.36 kB 3.42 kB +1.40% 1.57 kB 1.60 kB
oss-stable/react/cjs/react-compiler-runtime.development.js +1.85% 3.36 kB 3.42 kB +1.40% 1.57 kB 1.60 kB
oss-stable-semver/use-sync-external-store/cjs/use-sync-external-store.development.js +1.82% 3.40 kB 3.46 kB +1.42% 1.48 kB 1.50 kB
oss-stable/use-sync-external-store/cjs/use-sync-external-store.development.js +1.82% 3.40 kB 3.46 kB +1.42% 1.48 kB 1.50 kB
oss-experimental/react/cjs/react-compiler-runtime.development.js +1.81% 3.43 kB 3.49 kB +1.50% 1.60 kB 1.62 kB
oss-experimental/use-sync-external-store/cjs/use-sync-external-store.development.js +1.79% 3.47 kB 3.53 kB +1.53% 1.50 kB 1.53 kB
facebook-www/ReactCacheOld-dev.classic.js +0.75% 8.31 kB 8.37 kB +0.55% 2.74 kB 2.75 kB
facebook-www/ReactCacheOld-dev.modern.js +0.75% 8.31 kB 8.37 kB +0.55% 2.74 kB 2.75 kB
oss-stable-semver/use-sync-external-store/cjs/use-sync-external-store-shim.native.development.js +0.74% 8.43 kB 8.49 kB +0.58% 3.30 kB 3.32 kB
oss-stable/use-sync-external-store/cjs/use-sync-external-store-shim.native.development.js +0.74% 8.43 kB 8.49 kB +0.58% 3.30 kB 3.32 kB
oss-experimental/use-sync-external-store/cjs/use-sync-external-store-shim.native.development.js +0.73% 8.50 kB 8.57 kB +0.63% 3.32 kB 3.34 kB
oss-stable-semver/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +0.69% 9.02 kB 9.08 kB +0.56% 3.40 kB 3.42 kB
oss-stable/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +0.69% 9.02 kB 9.08 kB +0.56% 3.40 kB 3.42 kB
oss-experimental/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +0.68% 9.09 kB 9.15 kB +0.59% 3.42 kB 3.44 kB
oss-stable-semver/react-cache/cjs/react-cache.development.js +0.67% 9.31 kB 9.37 kB +0.61% 3.11 kB 3.13 kB
oss-stable/react-cache/cjs/react-cache.development.js +0.67% 9.31 kB 9.37 kB +0.61% 3.11 kB 3.13 kB
oss-experimental/react-cache/cjs/react-cache.development.js +0.66% 9.38 kB 9.44 kB +0.61% 3.14 kB 3.16 kB
oss-stable-semver/react-dom/cjs/react-dom.react-server.development.js +0.36% 17.37 kB 17.44 kB +0.52% 3.88 kB 3.90 kB
oss-stable/react-dom/cjs/react-dom.react-server.development.js +0.36% 17.40 kB 17.46 kB +0.56% 3.91 kB 3.93 kB
oss-experimental/react-dom/cjs/react-dom.react-server.development.js +0.35% 17.48 kB 17.54 kB +0.56% 3.94 kB 3.96 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler-reflection.development.js +0.32% 19.46 kB 19.52 kB +0.36% 5.59 kB 5.61 kB
oss-stable/react-reconciler/cjs/react-reconciler-reflection.development.js +0.32% 19.46 kB 19.52 kB +0.36% 5.59 kB 5.61 kB
oss-experimental/react-reconciler/cjs/react-reconciler-reflection.development.js +0.32% 19.53 kB 19.60 kB +0.37% 5.62 kB 5.64 kB
oss-stable-semver/react-dom/cjs/react-dom.development.js +0.25% 25.09 kB 25.16 kB +0.31% 6.46 kB 6.48 kB
oss-stable/react-dom/cjs/react-dom.development.js +0.25% 25.12 kB 25.18 kB +0.31% 6.49 kB 6.51 kB
oss-experimental/react-dom/cjs/react-dom.development.js +0.25% 25.20 kB 25.26 kB +0.28% 6.52 kB 6.54 kB
oss-experimental/react/cjs/react-jsx-dev-runtime.development.js +0.23% 26.52 kB 26.58 kB +0.14% 8.59 kB 8.61 kB
oss-experimental/react/cjs/react-jsx-runtime.development.js +0.23% 27.55 kB 27.61 kB +0.15% 8.90 kB 8.91 kB
oss-experimental/react/cjs/react-jsx-runtime.react-server.development.js +0.22% 28.26 kB 28.33 kB +0.09% 9.08 kB 9.09 kB
oss-experimental/react/cjs/react-jsx-dev-runtime.react-server.development.js +0.22% 28.27 kB 28.33 kB +0.10% 9.08 kB 9.09 kB
test_utils/ReactAllWarnings.js Deleted 63.65 kB 0.00 kB Deleted 15.90 kB 0.00 kB

Generated by 🚫 dangerJS against 89b976f

@@ -1618,8 +1618,7 @@ describe('ReactHooks', () => {
' Previous render Next render\n' +
' ------------------------------------------------------\n' +
`1. ${formatHookNamesToMatchErrorMessage(hookNameA, hookNameB)}\n` +
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n' +
' in App (at **)',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the stack frame still available in browsers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these matches a subset, by removing the stack frame it matches any stack frame.

These end up having the mentioned internals in them so I didn't want to assert on those.

@sebmarkbage sebmarkbage merged commit 4dcdf21 into facebook:main Jun 3, 2024
40 checks passed
github-actions bot pushed a commit that referenced this pull request Jun 3, 2024
#29697)

This information is available in the regular stack but since that's
hidden behind an expando and our appended stack to logs is not hidden,
it hides the most important frames like the name of the current
component.

This is closer to what happens to the native stack.

We only include stacks if they're within a ReactFiberCallUserSpace call
frame. This should be most that have a current fiber but this is
critical to filtering out most React frames if the regular node_modules
filter doesn't work.

Most React warnings fire during the rendering phase and not inside a
user space function but some do like hooks warnings and setState in
render. This feature is more important if we port this to React DevTools
appending stacks to all logs where it's likely to originate from inside
a component and you want the line within that component to immediately
part of the visible stack.

One thing that kind sucks is that we don't have a reliable way to
exclude React internal stack frames. We filter node_modules but it might
not match. For other cases I try hard to only track the stack frame at
the root of React (e.g. immediately inside createElement) until the
ReactFiberCallUserSpace so we don't need the filtering to work. In this
case it's hard to achieve the same thing though. This is easier in RDT
because we have the start/end line and parsing of stack traces so we can
use that to exclude internals but that's a lot of code/complexity for
shipping within the library.

For example in Safari:

<img width="590" alt="Screenshot 2024-05-31 at 6 15 27 PM"
src="https://github.com/facebook/react/assets/63648/2820c8c0-8a03-42e9-8678-8348f66b051a">

Ideally warnOnUseFormStateInDev and useFormState wouldn't be included
since they're React internals. Before this change, the Counter.js line
also wasn't included though which points to exactly where the error is
within the user code.

(Note Server Components have V8 formatted lines and Client Components
have JSC formatted lines.)

DiffTrain build for [4dcdf21](4dcdf21)
github-actions bot pushed a commit that referenced this pull request Jun 3, 2024
#29697)

This information is available in the regular stack but since that's
hidden behind an expando and our appended stack to logs is not hidden,
it hides the most important frames like the name of the current
component.

This is closer to what happens to the native stack.

We only include stacks if they're within a ReactFiberCallUserSpace call
frame. This should be most that have a current fiber but this is
critical to filtering out most React frames if the regular node_modules
filter doesn't work.

Most React warnings fire during the rendering phase and not inside a
user space function but some do like hooks warnings and setState in
render. This feature is more important if we port this to React DevTools
appending stacks to all logs where it's likely to originate from inside
a component and you want the line within that component to immediately
part of the visible stack.

One thing that kind sucks is that we don't have a reliable way to
exclude React internal stack frames. We filter node_modules but it might
not match. For other cases I try hard to only track the stack frame at
the root of React (e.g. immediately inside createElement) until the
ReactFiberCallUserSpace so we don't need the filtering to work. In this
case it's hard to achieve the same thing though. This is easier in RDT
because we have the start/end line and parsing of stack traces so we can
use that to exclude internals but that's a lot of code/complexity for
shipping within the library.

For example in Safari:

<img width="590" alt="Screenshot 2024-05-31 at 6 15 27 PM"
src="https://github.com/facebook/react/assets/63648/2820c8c0-8a03-42e9-8678-8348f66b051a">

Ideally warnOnUseFormStateInDev and useFormState wouldn't be included
since they're React internals. Before this change, the Counter.js line
also wasn't included though which points to exactly where the error is
within the user code.

(Note Server Components have V8 formatted lines and Client Components
have JSC formatted lines.)

DiffTrain build for commit 4dcdf21.
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.

4 participants