The Wayback Machine - https://web.archive.org/web/20230216220829/https://github.com/replayio/devtools/pull/8708
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

Implement "view React component source" #8708

Merged
merged 3 commits into from Feb 9, 2023

Conversation

markerikson
Copy link
Contributor

The React DevTools UI has support for "view component source". Provide an appropriate callback prop, and the RDT logic will give you the ID of the selected component. From there, you can talk to the RDT "backend" logic, send it a "viewElementSource" message, and it will save a reference to the component as window.$type. We can then evaluate code in the paused browser to retrieve that function reference, and do our usual "map the location and jump to the source" steps.

For function components, it jumps straight to the function. For class components, it jumps to render(). This behavior came straight from the extension:

https://github.com/facebook/react/blob/v18.0.0/packages/react-devtools-extensions/src/main.js#L194-L220

Results:

image

image

@vercel
Copy link

vercel bot commented Feb 8, 2023

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

Name Status Preview Comments Updated
devtools Ready (Inspect) Visit Preview Feb 9, 2023 at 4:53PM (UTC)
replay-soc2[bot]
replay-soc2 bot approved these changes Feb 8, 2023
@replay-io
Copy link

replay-io bot commented Feb 8, 2023

57 replays were recorded for 64b8080.

image 0 Failed
image 57 Passed

View test run on Replay ↗︎

@jasonLaster
Copy link
Collaborator

💃

bvaughn
bvaughn approved these changes Feb 9, 2023
Copy link
Collaborator

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

Awesome! This is great!

Looks like an RDT integration test is failing though. Didn't look at it but we should make sure it's not a regression before landing.

@markerikson
Copy link
Contributor Author

Yeah, I'll review that one in the morning.

@markerikson
Copy link
Contributor Author

Test definitely fails for me locally, so I broke something. Investigating...

- Refactored `createReactDevtools` setup to make `wall` available
- Added `viewSource` prop
- Added logic to tell the RDT backend to save the component instance,
  then fetch the function reference via the protocol
@markerikson markerikson force-pushed the feature/FE-263-react-component-source branch from 5ded12b to 64b8080 Compare February 9, 2023 16:36
@markerikson
Copy link
Contributor Author

Apparently wrapping createReactDevTools() in a useMemo() is bad somehow 🤷‍♂️

@replay-delta
Copy link

replay-delta bot commented Feb 9, 2023

4 of 370 changed

line-4-search-result-one-no-breakpoints.png
line-4-search-result-one-no-breakpoints.png
line-4-search-result-one-with-breakpoints.png
line-4-search-result-one-with-breakpoints.png
@markerikson markerikson merged commit 24d10f2 into main Feb 9, 2023
28 of 29 checks passed
@markerikson markerikson deleted the feature/FE-263-react-component-source branch February 9, 2023 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants