-
Notifications
You must be signed in to change notification settings - Fork 46.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
Export captureOwnerStacks() only in DEV "react" builds #29923
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Comparing: f3e09d6...98dc7fb Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
So, this could be used in a test environment (if using a node build of React) by testing utilities to get the name of the current component? This would help us to not access React internals in some of our tests :) |
@phryneas Well, yes and no. One of the concerns about this API surface that I'm concerned about is that people end up building "enzyme"-style testing that assert on the implementation details of the above tree. Notably this doesn't actually give you the name of the current component because the nearest is the callsite that created this component. You'd have to get The problem with that is not just that it uses internals but if you assert on the implementation details of another component that can change its internals an split into multiple components or merge. Which might even include React internals themselves. We're actually planning on changing forwardRef, memo etc. to be split into user component and so the owner stack involving those would change. The test selectors API we've designed is more designed in such a way that you can only assert on implementation details that are public anyway. Where as this can inspect things that are much less stable. So depending on how you use it it might be a bad idea anyway. If you just use it to print better error messages when something fails for other reasons though, yea that's a good use case for it. |
Only with the enableOwnerStacks flag (which is not on in www).
acb8a08
to
98dc7fb
Compare
Guilty 😅 Examples on how those tests look:
From your feedback up there, this seems to be the wrong API for us to use, so I'll stay away from it. But I have to wonder: As you seem to be adding a few interesting APIs, could this be something we could chat about a bit? I've seen a few calls on Twitter recently that React should be more performance testing with the argument that the "suspense sibling change" impact could have been caught sooner that way. |
IMO some of the communication undersold how much we knew about this already and did the call anyway. It's tradeoffs and time constraints. Regardless testing React itself against other libraries is something we can do easily anyway and we get coverage from real products. It's also overvaluing status quo (which is my problem with the whole thing). If you can never regress you must almost by definition end up in a local maxima which is where React is heading. It doesn't necessarily affect testing of most user code. Like React need to be able to change some implementation details like this without breaking all user tests. So there's a risk of an over reliance on implementation details. Like imagine if every manual useEffect+fetch encoded these semantics then upgrading would be a blocker just due to the tests. For the library use case like yours it's a little different. You're more concerned about details and if React makes a breaking change then you'd actually be motivated to fix the tests and workaround a change. But then also relying on internals is maybe not the end of the world because breaking your tests isn't going to break your downstream users. But feel free to open a different issue about that. |
Only with the enableOwnerStacks flag (which is not on in www).
This is a new DEV-only API to be able to implement what we do for console.error in user space.
This API does not actually include the current stack that you'd get from
new Error().stack
. That you'd have to add yourself.This adds the ability to have conditional development exports because we plan on eventually having separate ESM builds that use the "development" or "production" export conditions.
NOTE: This removes the export of
act
fromreact
in prod (as opposed to a function that throws) - inline with what we do with other conditional exports.