-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: Add support for unstable_Profiler to mount API #2055
Conversation
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.
- should the "mode" components exist in
.debug()
? ideally yes, but we'd want it to be the same answer for mount and shallow, and react may have made the decision for us. - if it does not show up in debug, what happens when you
mount
orshallow
a Profiler itself, instead of just a component that renders one? (because the root wrapper needs to wrap something, and mount shows that something in its debug tree) - The prop warnings seems useful to shim in whenever the Profiler is used
- There very well might be a bug with the test renderer, or with server rendering - ideally the profiler has actual meaningful behavior (even if that's "it just noops and renders its children) on the server, and thus in the shallow renderer
It does appear in the I also had
Added some more test cases to the codesandbox in #2054. It looks like for Going to look into this again and open an issue on the react repo. It's not obvious to me how the Profiler should behave in |
The first source of truth is React itself in a browser - this determines how |
Update: Warnings are logged perfectly fine with mount. I don't think we need to shim those in
|
Anything blocking this? The purpose is only to support |
Given that the implication is that it would work in the shallow renderer once it becomes stable, it seems like we'd want to add (skipped) shallow tests now, as well. |
@eps1lon ok, i've rebased this and tweaked some things. Some tests are now failing for me locally, only because |
I would include it in the debug() output since it would be closer to the actual component stack (in react and devtools). If it appears in debug() it should probably be findable too? |
To clarify, these axioms would ideally remain true:
Thoughts? |
Sounds good. Follows principle of least surprise. |
To be even more explicit :-) once the debug/findability/shallow-mount-consistency issue is resolved, I'm stoked to merge and release this. The currently-skipped shallow tests, pending changes in the shallow renderer, don't need to block full support for mount (as long as we have a path to identical support in the future, which we do) |
76e401e
to
5b4a309
Compare
@@ -207,6 +207,7 @@ function toTree(vnode) { | |||
case FiberTags.ContextProvider: | |||
case FiberTags.ContextConsumer: | |||
return childrenToTree(node.child); | |||
case FiberTags.Profiler: |
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.
This was the mistake. I previously included this in the same branch as the context tags, strict mode etc. That branch will not be considered a node. At least this is how I understood it.
There's probably an argument to be made that they should also be considered as valid nodes (since they also appear in reacts component stack and devtools) but that's for another time (personally I'm not interested in those components WRT to find/debug).
Not sure if Profiler should be handled exactly like forwardRef
but tests are passing for now so 🤷♂️
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.
hmm - if they appear in react devtools, and the stack, then they definitely need to appear in debug
.
And it's green. shallow and mount now create the same component tree WRT to the Profiler. |
- [new] Add support for wrapping `Profiler` (#2055) - [new] support shallow rendering `createContext()` providers and consumers - add `isContextConsumer`, `getProviderFromConsumer` (#1966) - [new] add `wrapWithWrappingComponent`, `isCustomComponent` (#1960) - [new] add `getDerivedStateFromError` support (#2036) - [fix] avoid invariant violation in provider (#2083) - [fix] properly fix finding memo(SFC) components (#2081) - [fix] properly render memoized SFCs - [fix] `shallow`: avoid wrapping component for hooks - [deps] update `react-is` - [dev deps] update `eslint` - [refactor] use `react-is` predicates more - [build] include source maps
Is unstable profiler different than the latest Profiler? We're looking for support in our jest tests and are running into issues |
@andrewholsted if it's newly renamed in 16.9, enzyme hasn't added support for it yet. |
@ljharb Ok, thanks. I'm working on a PR now. It seems pretty straight forward (as it's just removing the .unstable_, or keeping it and making it backwards compatible). Running into some issues building enzyme-adapter-react-16 locally and linking to my project to verify. I'm assuming this is a use case enzyme wants to support? |
@andrewholsted note that the master branch is failing tests since the 16.9 release, so the first task to unblock all enzyme development is to make a PR fixing that :-/ Yes, the renamed Profiler should definitely be supported. |
Part of #2054
Opening this with failing tests. Will need to establish if we accept those for now or fix before merge. I'm also missing some context what work in
mount
is done by React and what is re-implemented in this package.TODO
pretest
removalid
supportnotes
about find by *
I guess this is related toSolved and explained in #2055 (comment)Profiler
not appearing inwrapper.debug()
output. Might be caused byProfiler
being one of those "mode-components" (e.g. StrictMode or ConcurrentMode)missing timings
These are implented in the fiber related code (ReactFiberCommitWork):
onRender
isn't even called withReactTestRenderer.create
. Maybe this is the actual blocker here?Update: Timings weren't missing. The test environment didn't have a
performance
API available at which point React usesDate.now
which isn't precise enough to display any duration.prop warnings
There is currently a test case that included a bare
<Profiler />
(existed before this PR). Those should trigger warnings about missingid
andonRender
props. Probably never triggered since this is not actual prop types validation but happens when creating the fiber: https://github.com/facebook/react/blob/4186952a6f3558eb4fae9f6c5f669bd898dc1d97/packages/react-reconciler/src/ReactFiber.js#L597Update: Warnings are logged perfectly fine with
mount
. I don't think we need to shim those ingetDisplayName
.