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

feat[devtools/extension]: show disclaimer when page doesnt run react and refactor react polling logic #27373

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

hoxyq
Copy link
Contributor

@hoxyq hoxyq commented Sep 14, 2023

Changes:

  1. Refactored react polling logic, now each .eval() call is wrapped in Promise, so we can chain them properly.
  2. When user has browser DevTools opened and React DevTools panels were mounted, user might navigate to the page, which doesn't have React running. Previously, we would show just blank white page, now we will show disclaimer. Disclaimer appears after 5 failed attempts to find React. We will also show this disclaimer if it takes too long to load the page, but once any React instance is loaded and registered, we will update the panels.
  3. Dark theme support for this disclaimer and popups in Firefox & Chromium-based browsers

Important: this is only valid for case when React DevTools panels were already created, like when user started debugging React app and then switched to non-React page. If user starts to debug non-React app (by opening browser DevTools for it), we will not create these panels, just like before.

Q: "Why do we poll to get information about react?"
A: To handle case when react is loaded after the page has been loaded, some sandboxes for example.

Before After
Screenshot 2023-09-14 at 15 37 37 Screenshot 2023-09-14 at 15 26 16

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Sep 14, 2023
@hoxyq hoxyq force-pushed the devtools/no-react-disclaimer branch from be7e5bc to 040b4ff Compare September 14, 2023 18:04
port.disconnect();
return;
ports[tabId].disconnectPipe?.();
ports[tabId].proxy.disconnect();
Copy link
Member

Choose a reason for hiding this comment

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

the old version has an early return here, why remove that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, this proxy port is opened from content script in isolated environment, which has access to window object, but not DOM.

This condition is usually an edge case, it means that previous port was not disconnected or we were not notified that it was disconnected. In previous implementation we would disconnect new port, which is questionable, but it could save us from situation with many new connections spam.

I think better approach in this case is disconnecting previous port properly and registering new one, connecting it with devtools page (in browser DevTools) port.

@hoxyq hoxyq merged commit 1b1dcb8 into facebook:main Sep 20, 2023
36 checks passed
@hoxyq hoxyq deleted the devtools/no-react-disclaimer branch September 20, 2023 12:30
hoxyq added a commit that referenced this pull request Sep 25, 2023
* refactor[devtools/extension]: refactored messaging logic across
different parts of the extension ([hoxyq](https://github.com/hoxyq) in
[#27417](#27417))
* fix[devtools/extension]: added a workaround for proxy content script
injection in firefox ([hoxyq](https://github.com/hoxyq) in
[#27375](#27375))
* fix[devtools/useTransition]: don't check for dispatch property when
determining if hook is stateful ([hoxyq](https://github.com/hoxyq) in
[#27365](#27365))
* feat[devtools/extension]: show disclaimer when page doesnt run react
and refactor react polling logic ([hoxyq](https://github.com/hoxyq) in
[#27373](#27373))
* feat:-Added a delete all filters action and added title to the add
filter a… ([Biki-das](https://github.com/Biki-das) in
[#27332](#27332))
* fix[devtools/extension]: unregister dynamically injected content
scripts instead of filtering ([hoxyq](https://github.com/hoxyq) in
[#27369](#27369))
* refactor[devtools/extension]: more stable element updates polling to
avoid timed out errors ([hoxyq](https://github.com/hoxyq) in
[#27357](#27357))
* feat[devtools/extension]: add dark theme for popup
([rakleed](https://github.com/rakleed) in
[#27330](#27330))
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
…and refactor react polling logic (facebook#27373)

Changes:
1. Refactored react polling logic, now each `.eval()` call is wrapped in
Promise, so we can chain them properly.
2. When user has browser DevTools opened and React DevTools panels were
mounted, user might navigate to the page, which doesn't have React
running. Previously, we would show just blank white page, now we will
show disclaimer. Disclaimer appears after 5 failed attempts to find
React. We will also show this disclaimer if it takes too long to load
the page, but once any React instance is loaded and registered, we will
update the panels.
3. Dark theme support for this disclaimer and popups in Firefox &
Chromium-based browsers

**Important**: this is only valid for case when React DevTools panels
were already created, like when user started debugging React app and
then switched to non-React page. If user starts to debug non-React app
(by opening browser DevTools for it), we will not create these panels,
just like before.

Q: "Why do we poll to get information about react?"
A: To handle case when react is loaded after the page has been loaded,
some sandboxes for example.

| Before | After |
| --- | --- |
| <img width="1840" alt="Screenshot 2023-09-14 at 15 37 37"
src="https://github.com/facebook/react/assets/28902667/2e6ffb39-5698-461d-bfd6-be2defb41aad">
| <img width="1840" alt="Screenshot 2023-09-14 at 15 26 16"
src="https://github.com/facebook/react/assets/28902667/1c8ad2b7-0955-41c5-b8cc-d0fdb03e13ca">
|
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
* refactor[devtools/extension]: refactored messaging logic across
different parts of the extension ([hoxyq](https://github.com/hoxyq) in
[facebook#27417](facebook#27417))
* fix[devtools/extension]: added a workaround for proxy content script
injection in firefox ([hoxyq](https://github.com/hoxyq) in
[facebook#27375](facebook#27375))
* fix[devtools/useTransition]: don't check for dispatch property when
determining if hook is stateful ([hoxyq](https://github.com/hoxyq) in
[facebook#27365](facebook#27365))
* feat[devtools/extension]: show disclaimer when page doesnt run react
and refactor react polling logic ([hoxyq](https://github.com/hoxyq) in
[facebook#27373](facebook#27373))
* feat:-Added a delete all filters action and added title to the add
filter a… ([Biki-das](https://github.com/Biki-das) in
[facebook#27332](facebook#27332))
* fix[devtools/extension]: unregister dynamically injected content
scripts instead of filtering ([hoxyq](https://github.com/hoxyq) in
[facebook#27369](facebook#27369))
* refactor[devtools/extension]: more stable element updates polling to
avoid timed out errors ([hoxyq](https://github.com/hoxyq) in
[facebook#27357](facebook#27357))
* feat[devtools/extension]: add dark theme for popup
([rakleed](https://github.com/rakleed) in
[facebook#27330](facebook#27330))
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
…and refactor react polling logic (#27373)

Changes:
1. Refactored react polling logic, now each `.eval()` call is wrapped in
Promise, so we can chain them properly.
2. When user has browser DevTools opened and React DevTools panels were
mounted, user might navigate to the page, which doesn't have React
running. Previously, we would show just blank white page, now we will
show disclaimer. Disclaimer appears after 5 failed attempts to find
React. We will also show this disclaimer if it takes too long to load
the page, but once any React instance is loaded and registered, we will
update the panels.
3. Dark theme support for this disclaimer and popups in Firefox &
Chromium-based browsers

**Important**: this is only valid for case when React DevTools panels
were already created, like when user started debugging React app and
then switched to non-React page. If user starts to debug non-React app
(by opening browser DevTools for it), we will not create these panels,
just like before.

Q: "Why do we poll to get information about react?"
A: To handle case when react is loaded after the page has been loaded,
some sandboxes for example.

| Before | After |
| --- | --- |
| <img width="1840" alt="Screenshot 2023-09-14 at 15 37 37"
src="https://github.com/facebook/react/assets/28902667/2e6ffb39-5698-461d-bfd6-be2defb41aad">
| <img width="1840" alt="Screenshot 2023-09-14 at 15 26 16"
src="https://github.com/facebook/react/assets/28902667/1c8ad2b7-0955-41c5-b8cc-d0fdb03e13ca">
|

DiffTrain build for commit 1b1dcb8.
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.

3 participants