-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Profiler: Support "reload and start profiling" option #1121
Comments
Is there a way (maybe via the backend's mount) to pass props to the root? |
Forcing a remount seems sketchy. It could cause side effects to be applied twice which could e.g. break a page, double-log data somewhere remotely– all sorts of things. It could also be pretty slow. |
I meant attach it to a button that will explicit fire a re-mount and record. But if you think this is not the way to go then fair enough |
Gotcha. Still seems questionable to me. e.g. What if there are multiple React roots on the page? Or multiple versions of React? |
Well how does the profiler handle multiple roots or versions now? |
@bvaughn would an approach like that work? Yes we need to take care of several configurations, multiple roots etc. but I think there are solutions to these problems. The main thing on that approach would be to discuss if the handshake between the render method and the profiler is something that would be of interest. |
I'm going to paste what I said on Twitter for anyone who sees this thread:
You responded:
Are we guaranteed that DevTools will always load/initialize before JS on the page? I think so based on my own testing, and interpretation of the docs, but it would be nice to definitely know. Otherwise React rendering immediately if the DevTools weren't present would defeat the purpose of waiting. The Mozilla docs say this about the timing of the content scripts
I think this confirms my assumption, but that being said, it looks like the DevTools extension was written under the assumption that React might load onto the page before the extension does. Maybe this used to be the case? Or maybe it was a misunderstanding (seems less likely)?
To be honest– this still doesn't feel like a good idea. If the React DevTools is guaranteed to run before React runs on the page, I'd rather invest energy into getting rid of the plugins initialization delay (or finding some other way) so that the Profiler can just start profiling immediately, before the first commit. I think there's an async delay with the bridge traffic currently that we'd have to work around, but maybe it would be possible to do this somehow? I haven't thought that much about it. |
Sure if sync preparation of the profiler can be assured it should be done that way, there is no reason to handshake and make it more complex than it should be. But if not I can't see any other way to support it.
No and it doesn't matter. The flow of
For a better UX if |
When it comes to the hook I think yes, the hook will be available before the page. AFAICT that's the point of: Is this correct? And maybe that's a way to delay the rendering of the rest of the document as well to achieve the behavior you described above? Not sure but seems a bit brutal. Also as pointed in the Readme file, there are other use cases that devtools require the hook to be loaded before the page. For example in order to read the original implementations of Set and Map to avoid any monkeypatching made by the user. |
I think that DevTools are not "atomic" when it comes to initialization. The backend and the hook injection seem that are guaranteed to execute before any other script in the page. But the content scripts may be not. |
The hook is the part that would need to be guaranteed to run before React does for an approach like the one you proposed to be potentially viable. Assuming Jared was right when he wrote those lines in 41f5760, then that would be the case. I'm still not a fan of increasing the surface area– (we'd need to add two new methods– one for |
That's on you and it'd be a totally respectable decision to not go that way. All I'm saying is that it's something technically feasible without much new code but unfortunately by somehow coupling the render method with the devtools and the profiler. |
Fair enough. I believe you're right that it's technically feasible 😄 Thanks for the discussion! |
Is there any known workaround to this? I tried disabling hydration so I could invoke it manually once I had started profiling, but the profiler tab doesn't appear until after |
Nope. This is something I plan to tackle with the DevTools rewrite. |
React DevTools has been rewritten and recently launched a new version 4 UI. The source code for this rewrite was done in a separate repository and now lives in the main React repo (github.com/facebook/react). Because version 4 was a total rewrite, and all issues in this repository are related to the old version 3 of the extension, I am closing all issues in this repository. If you can still reproduce this issue, or believe this feature request is still relevant, please open a new issue in the React repo: https://github.com/facebook/react/issues/new?labels=Component:%20Developer%20Tools |
Either resume recording if the DevTools (or a web page) are re-loaded while recording is active, or add a restart-and-profile button like Chrome "Performance" tab has. (This may not be possible due to initialization/timing issues.)
See this comment for some work in progress...
The text was updated successfully, but these errors were encountered: