Commit Graph

160 Commits

Author SHA1 Message Date
Brian Vaughn
75d34aa083 Updated DevTools changelog 2021-12-14 16:50:17 -05:00
jstejada
0229baee21 React DevTools 4.21.0 -> 4.22.0 (#22951) 2021-12-14 14:19:21 -05:00
Brian Vaughn
911f92a44d DevTools: Support mulitple DevTools instances per page (#22949)
This is being done so that we can embed DevTools within the new React (beta) docs.

The primary changes here are to `react-devtools-inline/backend`:
* Add a new `createBridge` API
* Add an option to the `activate` method to support passing in the custom bridge object.

The `react-devtools-inline` README has been updated to include these new methods.

To verify these changes, this commit also updates the test shell to add a new entry-point for multiple DevTools.

This commit also replaces two direct calls to `window.postMessage()` with `bridge.send()` (and adds the related Flow types).
2021-12-14 12:16:16 -05:00
Brian Vaughn
3b3daf5573 Advocate for StrictMode usage within Components tree (#22886)
Adds the concept of subtree modes to DevTools to bridge protocol as follows:
1. Add-root messages get two new attributes: one specifying whether the root is running in strict mode and another specifying whether the root (really the root's renderer) supports the concept of strict mode.
2. A new backend message type (TREE_OPERATION_SET_SUBTREE_MODE). This type specifies a subtree root (id) and a mode (bitmask). For now, the only mode this message deals with is strict mode.

The DevTools frontend has been updated as well to highlight non-StrictMode compliant components.

The changes to the bridge protocol require incrementing the bridge protocol version number, which will also require updating the version of react-devtools-core backend that is shipped with React Native.
2021-12-10 11:05:18 -05:00
Mert Ciflikli
200415c91c fix typos (#22288) 2021-11-15 10:59:35 -05:00
Juan
6c7ef3fce5 React DevTools 4.20.2 -> 4.21.0 (#22661) 2021-10-31 19:19:02 -04:00
Juan
c213030b49 React DevTools 4.20.1 -> 4.20.2 (#22605) 2021-10-20 16:00:13 -04:00
Juan
b81de86332 React DevTools 4.20.0 -> 4.20.1 (#22583) 2021-10-19 10:55:39 -04:00
Juan
e5f486b5a8 React DevTools 4.19.2 -> 4.20.2 (#22569) 2021-10-15 12:50:17 -04:00
Gabriel Trompiz
9d3d03025c Reattachment of the splash page event listeners (#22558) (#22560) 2021-10-15 09:16:43 -04:00
Juan
545d4c2de7 Prevent errors/crashing when multiple installs of DevTools are present (#22517)
## Summary

This commit is a proposal for handling duplicate installation of DevTools, in particular scoped to duplicates such as a dev build or the internal versions of DevTools installed alongside the Chrome Web Store extension.

Specifically, this commit makes it so when another instance of the DevTools extension is installed alongside the extension installed from the Chrome Web Store, we don't produce a stream of errors or crash Chrome, which is what would usually happen in this case. 


### Detecting Duplicate Installations

- First, we check what type of installation the extension is: from the Chrome Web Store, the internal build of the extension, or a local development build.
- If the extension is from the **Chrome Web Store**:
  - During initialization, we first check if the internal or local builds of the extension have already been installed and are enabled. To do this, we send a [cross-extension message](https://developer.chrome.com/docs/extensions/mv3/messaging/#external) to the internal and local builds of the extension using their extension IDs.  
    - We can do this because the extension ID for the internal build (and for the Chrome Web Store) is a stable ID.
    - For the local build, at build time we hardcode a [`key` in the `manifest.json`](https://developer.chrome.com/docs/extensions/mv2/manifest/key/) which allows us to have a stable ID even for local builds.
  - If we detect that the internal or local extensions are already installed, then we skip initializing the current extension altogether so as to not conflict with the other versions. This means we don't initialize the frontend or the backend at all.
- If the extension is the **Internal Build**:
  - During initialization, we first check if the local builds of the extension has already been installed and is enabled. To do this, we send a [cross-extension message](https://developer.chrome.com/docs/extensions/mv3/messaging/#external) to the local build of the extension using its extension ID.  
    - We can do this for the local build because at build time we hardcode a [`key` in the `manifest.json`](https://developer.chrome.com/docs/extensions/mv2/manifest/key/) which allows us to have a stable ID even for local builds.
  - If we detect that the local extension is already installed, then we skip initializing the current extension altogether so as to not conflict with the that  version. This means we don't initialize the frontend or the backend at all.
- If the extension is a **Local Dev Build**:
  - Since other extensions check for the existence of this extension and disable themselves if they detect it, we don't need any special handling during initialization and assume that there are no duplicate extensions. This means that we will generally prefer keeping this extension enabled.

This behavior means that the order of priority for keeping an extension enabled is the following:

1. Local build
2. Internal build
3. Public build


### Preventing duplicate backend initialization

Note that the backend is injected and initialized by the content script listening to a message posted to the inspected window (via `postMessage`). Since the content script will be injected twice, once each by each instance of the extension, even if we initialize the extension once, both content scripts would still receive the single message posted from the single frontend, and it would then still inject and initialize the backend twice. 

In order to prevent this, we also add the extension ID to the message for injecting the backend. That way each content script can check if the message comes from its own extension, and if not it can ignore the message and avoid double injecting the backend.
  
### Other approaches

- I considered using the [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/) API generally to detect other installations, but that requires adding additional permissions to our production extension, which didn't seem ideal.
- I also considered a few options of writing a special flag to the inspected window and checking for it before initializing the extension. However, it's hard to avoid race conditions in that case, and it seemed more reliable to check specifically for the WebStore extension, which is realistically where we would encounter the overlap.
  
### Rollout

- This commit needs to be published and rolled out to the Chrome Web Store first.
- After this commit is published to the Chrome Web Store, any duplicate instances of the extension that are built and installed after this commit will no longer conflict with the Chrome Web Store version.
  
### Next Steps

- In a subsequent PR, I will extend this code to show a warning when duplicate extensions have been detected.

Part of #22486

## How did you test this change?

### Basic Testing

- yarn flow
- yarn test
- yarn test-build-devtools

### Double installation testing

Testing double-installed extensions for this commit is tricky because we are relying on the extension ID of the internal and Chrome Web Store extensions, but we obviously can't actually test the Web Store version (since we can't modify the already published version).

In order to simulate duplicate extensions installed, I did the following process:

- Built separate extensions where I hardcoded a constant for whether the extension is internal or public (e.g. `EXTENSION_INSTALLATION_TYPE = 'internal'`). Then I installed these built extensions corresponding to the "internal" and "Web Store" builds.
- Build and run the regular development extension (with `yarn build:chrome:dev && yarn test:chrome`), using the extension IDs of the previously built extensions as the "internal" and "public" extension IDs.

With this set up in place, I tested the following on pages both with and without React:

- When only the local extension enabled, DevTools works normally.
- When only the "internal" extension enabled, DevTools works normally.
- When only the "public" extension enabled, DevTools works normally.
- When "internal" and "public" extensions are installed, "public" extension is disabled and "internal" extension works normally.
- When the local extension runs alongside the other extensions, other extensions disable themselves and local build works normally.
- When we can't recognize what type of build the extension corresponds to, we show an error.
- When all 3 extensions are installed and enabled in all different combinations, DevTools no longer produces errors or crashes Chrome, and works normally.
2021-10-14 17:15:31 -04:00
Gabriel Trompiz
a45533cc25 Allow to use the Profiler when no client is connected in standalone DevTools (#22551) 2021-10-14 08:31:45 -04:00
Brian Vaughn
20ca9b565a React DevTools 4.19.1 -> 4.19.2 2021-10-08 13:51:25 -04:00
Brian Vaughn
bdd6d5064d React DevTools 4.19.0 -> 4.19.1 (#22480) 2021-10-01 11:50:05 -04:00
Luna Ruan
0883c4cd3a React DevTools 4.18.0 -> 4.19.0 (#22461) 2021-09-29 12:06:13 -04:00
38elements
cbf6178ed3 Fix links in packages/react-devtools/README.md (#22356) 2021-09-20 15:10:29 -04:00
BIKI DAS
c62d5831d3 react-devtools\OVERVIEW.md --> fixed typos (#22372) 2021-09-20 15:09:37 -04:00
Juan
1090ccd019 [DevTools] Enable hook names in standalone app (#22320) 2021-09-17 10:21:54 -04:00
Luna Ruan
cb8a50619b [DevTools] Add React Devtools Extension Startup and File Structure to OVERVIEW.md (#22283) 2021-09-09 15:58:27 -07:00
Kausik S S
c46c0733e2 Typo fixed (#22171) 2021-09-06 20:05:15 +01:00
Luna Ruan
3385b377f7 React DevTools 4.17.0 -> 4.18.0 (#22234) 2021-09-01 13:39:36 -07:00
Brian Vaughn
582858083e React DevTools 4.16.0 -> 4.17.0 2021-08-24 11:12:42 -07:00
Brian Vaughn
b5fbf5464b Automated DevTools release process (#22161) 2021-08-24 14:05:50 -04:00
Luna Ruan
152ecce117 DevTools 4.15.0 -> 4.16.0 (#22104) 2021-08-16 14:55:47 -07:00
Brian Vaughn
82583617b7 Updated DevTools CHANGELOG
Fixed header typo
2021-08-12 11:03:33 -04:00
Brian Vaughn
c2bb975337 Added Scheduling Profiler notes and videos to the DevTools CHANGELOG 2021-08-12 11:02:30 -04:00
Brian Vaughn
07e58658c9 Add script to generate DevTools changelog text (#22077) 2021-08-12 10:43:56 -04:00
Brian Vaughn
ef582fbea1 Added taneliang and kartikcho to scheduling profiler credits 2021-08-11 17:48:37 -04:00
Juan
c6f2188ed6 DevTools 4.14.0 -> 4.15.0 2021-08-11 16:47:20 -04:00
Shubham Pandey
6f3fcbd6fa Some remaining instances of master to main (#21982)
Co-authored-by: Shubham Pandey <shubham.pandey@mfine.co>
2021-07-30 08:56:55 -04:00
Brian Vaughn
d9dd96530f Added testing instructions to devtools contributing guide 2021-07-28 19:05:01 -04:00
Christian Schulze
9b76d2d7b3 react-devtools: set icon on macos (#21908) 2021-07-19 10:26:41 -04:00
Brian Vaughn
d0ec283819 DevTools 4.13.5 -> 4.14.0 2021-07-16 00:25:01 -04:00
Brian Vaughn
25984e5231 Update CONTRIBUTING.md 2021-07-08 17:38:59 -04:00
Brian Vaughn
92af60afb2 Update CONTRIBUTING.md 2021-07-08 14:37:13 -04:00
Brian Vaughn
27423de395 Update CONTRIBUTING.md 2021-07-08 14:28:53 -04:00
Brian Vaughn
8148fe5ff4 Added DevTools CONTRIBUTING guide 2021-07-08 14:11:30 -04:00
Brian Vaughn
d483463bc8 Updated scripts and config to replace "master" with "main" branch (#21768) 2021-06-29 14:26:24 -04:00
Brian Vaughn
0ae5290b54 DevTools 4.13.4 -> 4.13.5 2021-05-25 15:18:47 -04:00
Brian Vaughn
51ebccc374 DevTools: Add 4.13.4 changelog 2021-05-20 17:00:17 -04:00
Brian Vaughn
97c25b0e9c DevTools: Add 4.10.4 to CHANGELOG 2021-05-20 16:31:18 -04:00
Brian Vaughn
132b72d7b6 DevTools 4.13.3 -> 4.13.4 2021-05-20 11:24:30 -04:00
Brian Vaughn
3f8f4675d4 Updated DevTools CHANGELOG for 4.13.3 release 2021-05-19 10:59:32 -04:00
Brian Vaughn
d6604ac031 Account for another DevTools + Fast Refresh edge case (#21523)
DevTools now 'untrack' Fibers (cleans up the ID-to-Fiber mapping) after a slight delay in order to support a Fast Refresh edge case:
1. Component type is updated and Fast Refresh schedules an update+remount.
2. flushPendingErrorsAndWarningsAfterDelay() runs, sees the old Fiber is no longer mounted (it's been disconnected by Fast Refresh), and calls untrackFiberID() to clear it from the Map.
3. React flushes pending passive effects before it runs the next render, which logs an error or warning, which causes a new ID to be generated for this Fiber.
4. DevTools now tries to unmount the old Component with the new ID.

The underlying problem here is the premature clearing of the Fiber ID, but DevTools has no way to detect that a given Fiber has been scheduled for Fast Refresh. (The '_debugNeedsRemount' flag won't necessarily be set.)

The best we can do is to delay untracking by a small amount, and give React time to process the Fast Refresh delay.
2021-05-18 22:44:29 -04:00
Brian Vaughn
343776fc90 Added React entry-points change to DevTools changelog 2021-05-18 13:25:29 -04:00
Brian Vaughn
4d402cdda0 Preparing DevTools 4.13.2 -> 4.13.3 for release 2021-05-18 13:23:06 -04:00
Brian Vaughn
0a8fefca4c DevTools 4.13.1 -> 4.13.2 2021-05-07 08:52:02 -04:00
Brian Vaughn
014edf1980 Prepare DevTools 4.13.1 release 2021-05-04 22:35:30 -04:00
Brian Vaughn
2a7bb41548 Preparing DevTools 4.12.4 -> 4.13.0 release (#21378) 2021-04-28 12:36:24 -04:00
Brian Vaughn
a5267faad5 Updated DevTools CHANGELOG for 4.10 releases 2021-04-28 08:58:27 -04:00