From 21a851e03507e77bf51b410c36e4d32d6e5bf728 Mon Sep 17 00:00:00 2001 From: Alexandru Tasica Date: Fri, 20 May 2022 13:05:23 +0300 Subject: [PATCH] Fix devtools typos and grammar (#24587) Closes #24587 --- .../src/__tests__/ReactFlight-test.js | 4 ++-- packages/react-devtools-core/src/editor.js | 2 +- packages/react-devtools/OVERVIEW.md | 24 +++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/react-client/src/__tests__/ReactFlight-test.js b/packages/react-client/src/__tests__/ReactFlight-test.js index 4b72bdd85a4e1..b837f3ff8bb2c 100644 --- a/packages/react-client/src/__tests__/ReactFlight-test.js +++ b/packages/react-client/src/__tests__/ReactFlight-test.js @@ -705,7 +705,7 @@ describe('ReactFlight', () => { }); // @gate enableServerContext - it('propagates ServerContext and cleansup providers in flight', async () => { + it('propagates ServerContext and cleans up the providers in flight', async () => { const ServerContext = React.createServerContext( 'ServerContext', 'default', @@ -856,7 +856,7 @@ describe('ReactFlight', () => { }); // @gate enableServerContext - it('takes ServerContext from client for refetching usecases', async () => { + it('takes ServerContext from the client for refetching use cases', async () => { const ServerContext = React.createServerContext( 'ServerContext', 'default', diff --git a/packages/react-devtools-core/src/editor.js b/packages/react-devtools-core/src/editor.js index 5d53cf92158e9..a570befd9ef24 100644 --- a/packages/react-devtools-core/src/editor.js +++ b/packages/react-devtools-core/src/editor.js @@ -97,7 +97,7 @@ function guessEditor(): Array { } } - // Last resort, use old skool env vars + // Last resort, use old-school env vars if (process.env.VISUAL) { return [process.env.VISUAL]; } else if (process.env.EDITOR) { diff --git a/packages/react-devtools/OVERVIEW.md b/packages/react-devtools/OVERVIEW.md index 76aeff3343c6b..7f705e4c3f34a 100644 --- a/packages/react-devtools/OVERVIEW.md +++ b/packages/react-devtools/OVERVIEW.md @@ -4,7 +4,7 @@ The React DevTools extension consists of multiple pieces: * The **frontend** portion is the extension you see (the Components tree, the Profiler, etc.). * The **backend** portion is invisible. It runs in the same context as React itself. When React commits changes to e.g. the DOM, the backend is responsible for notifying the frontend by sending a message through the **bridge** (an abstraction around e.g. `postMessage`). -One of the largest performance bottlenecks of the old React DevTools was the amount of bridge traffic. Each time React commits an update, the backend sends every fiber that changed across the bridge, resulting in a lot of (JSON) serialization. The primary goal for the DevTools rewrite was to reduce this traffic. Instead of sending everything across the bridge, **the backend should only send the minimum amount required to render the Components tree**. The frontend can request more information (e.g. an element's props) on demand, only as needed. +One of the largest performance bottlenecks of the old React DevTools was the amount of bridge traffic. Each time React commits an update, the backend sends every fiber that changed across the bridge, resulting in a lot of (JSON) serialization. The primary goal for the DevTools rewrite was to reduce this traffic. Instead of sending everything across the bridge, **the backend should only send the minimum amount required to render the Components tree**. The frontend can request more information (e.g. an element's props) on-demand, only as needed. The old DevTools also rendered the entire application tree in the form of a large DOM structure of nested nodes. A secondary goal of the rewrite was to avoid rendering unnecessary nodes by using a windowing library (specifically [react-window](https://github.com/bvaughn/react-window)). @@ -24,7 +24,7 @@ The string table is encoded right after the first two numbers. It consists of: -1. the total length of next items that belong to string table +1. the total length of the next items that belong to the string table 2. for each string in a table: * encoded size * a list of its UTF encoded codepoints @@ -136,7 +136,7 @@ For example: #### Updating tree base duration -While profiling is in progress, we send an extra operation any time a fiber is added or a updated in a way that affects its tree base duration. This information is needed by the Profiler UI in order to render the "snapshot" and "ranked" chart views. +While profiling is in progress, we send an extra operation any time a fiber is added or updated in a way that affects its tree base duration. This information is needed by the Profiler UI in order to render the "snapshot" and "ranked" chart views. 1. tree base duration constant (`4`) 1. fiber id @@ -170,7 +170,7 @@ We only send the serialized messages as part of the `inspectElement` event. #### Removing a root -Special case of unmounting an entire root (include its descendants). This specialized message replaces what would otherwise be a series of remove-node operations. It is currently only used in one case: updating component filters. The primary motivation for this is actually to preserve fiber ids for components that are re-added to the tree after the updated filters have been applied. This preserves mappings between the Fiber (id) and things like error and warning logs. +A special case of unmounting an entire root (including its descendants). This specialized message replaces what would otherwise be a series of remove-node operations. It is currently only used in one case: updating component filters. The primary motivation for this is actually to preserve fiber ids for components that are re-added to the tree after the updated filters have been applied. This preserves mappings between the Fiber (id) and things like error and warning logs. ```js [ @@ -210,7 +210,7 @@ The frontend stores its information about the tree in a map of id to objects wit 1 The `depth` value determines how much padding/indentation to use for the element when rendering it in the Components panel. (This preserves the appearance of a nested tree, even though the view is a flat list.) -2 The `weight` of an element is the number of elements (including itself) below it in the tree. We cache this property so that we can quickly determine the total number of Components as well as to find the Nth element within that set. (This enables us to use windowing.) This value needs to be adjusted each time elements are added or removed from the tree, but we amortize this over time to avoid any big performance hits when rendering the tree. +2 The `weight` of an element is the number of elements (including itself) below it in the tree. We cache this property so that we can quickly determine the total number of Components as well as find the Nth element within that set. (This enables us to use windowing.) This value needs to be adjusted each time elements are added or removed from the tree, but we amortize this over time to avoid any big performance hits when rendering the tree. #### Finding the element at index N @@ -263,21 +263,21 @@ while (index !== currentWeight) { When an element is mounted in the tree, DevTools sends a minimal amount of information about it across the bridge. This information includes its display name, type, and key- but does _not_ include things like props or state. (These values are often expensive to serialize and change frequently, which would add a significant amount of load to the bridge.) -Instead DevTools lazily requests additional information about an element only when it is selected in the "Components" tab. At that point, the frontend requests this information by sending a special "_inspectElement_" message containing the id of the element being inspected. The backend then responds with an "_inspectedElement_" message containing the additional details. +Instead, DevTools lazily requests additional information about an element only when it is selected in the "Components" tab. At that point, the frontend requests this information by sending a special "_inspectElement_" message containing the id of the element being inspected. The backend then responds with an "_inspectedElement_" message containing the additional details. ### Polling strategy -Elements can update frequently, especially in response to things like scrolling events. Since props and state can be large, we avoid sending this information across the bridge every time the selected element is updated. Instead, the frontend polls the backend for updates about once a second. The backend tracks when the element was last "inspected" and sends a special no-op response if it has not re-rendered since then. +Elements can update frequently, especially in response to things like scrolling events. Since props and state can be large, we avoid sending this information across the bridge every time the selected element is updated. Instead, the frontend polls the backend for updates about once a second. The backend tracks when the element was last "inspected" and sends a special no-op response if it has not been re-rendered since then. ### Deeply nested properties -Even when dealing with a single component, serializing deeply nested properties can be expensive. Because of this, DevTools uses a technique referred to as "dehydration" to only send a shallow copy of the data on initial inspection. DevTools then fills in the missing data on demand as a user expands nested objects or arrays. Filled in paths are remembered (for the currently inspected element) so they are not "dehydrated" again as part of a polling update. +Even when dealing with a single component, serializing deeply nested properties can be expensive. Because of this, DevTools uses a technique referred to as "dehydration" to only send a shallow copy of the data on initial inspection. DevTools then fills in the missing data on-demand as a user expands nested objects or arrays. Filled in paths are remembered (for the currently inspected element) so they are not "dehydrated" again as part of a polling update. ### Inspecting hooks Hooks present a unique challenge for the DevTools because of the concept of _custom_ hooks. (A custom hook is essentially any function that calls at least one of the built-in hooks. By convention custom hooks also have names that begin with "use".) -So how does DevTools identify custom functions called from within third party components? It does this by temporarily overriding React's built-in hooks and shallow rendering the component in question. Whenever one of the (overridden) built-in hooks are called, it parses the call stack to spot potential custom hooks (functions between the component itself and the built-in hook). This approach enables it to build a tree structure describing all of the calls to both the built-in _and_ custom hooks, along with the values passed to those hooks. (If you're interested in learning more about this, [here is the source code](https://github.com/facebook/react/blob/main/packages/react-debug-tools/src/ReactDebugHooks.js).) +So how does DevTools identify custom functions called from within third-party components? It does this by temporarily overriding React's built-in hooks and shallow rendering the component in question. Whenever one of the (overridden) built-in hooks are called, it parses the call stack to spot potential custom hooks (functions between the component itself and the built-in hook). This approach enables it to build a tree structure describing all of the calls to both the built-in _and_ custom hooks, along with the values passed to those hooks. (If you're interested in learning more about this, [here is the source code](https://github.com/facebook/react/blob/main/packages/react-debug-tools/src/ReactDebugHooks.js).) > **Note**: DevTools obtains hooks info by re-rendering a component. > Breakpoints will be invoked during this additional (shallow) render, @@ -289,7 +289,7 @@ To mitigate the performance impact of re-rendering a component, DevTools does th * Only function components that use _at least one hook_ are rendered. (Props and state can be analyzed without rendering.) * Rendering is always shallow. * Rendering is throttled to occur, at most, once per second. -* Rendering is skipped if the component has not updated since the last time its properties were inspected. +* Rendering is skipped if the component has been not updated since the last time its properties were inspected. ## Profiler @@ -308,7 +308,7 @@ When profiling begins, the backend records the base durations of each fiber curr * Which elements were rendered during that commit * Which props and state changed (if enabled in profiler settings) -This information will eventually be required by the frontend in order to render its profiling graphs, but it will not be sent across the bridge until profiling has completed (to minimize the performance impact of profiling). +This information will eventually be required by the frontend in order to render its profiling graphs, but it will not be sent across the bridge until profiling has been completed (to minimize the performance impact of profiling). ### Timeline profiler @@ -318,7 +318,7 @@ Timeline profiling data can come from one of two places: ### Combining profiling data -Once profiling is finished, the frontend requests profiling data from the backend one renderer at a time by sending a "_getProfilingData_" message. The backend responds with a "_profilingData_" message that contains per-root commit timing and duration information. The frontend then combines this information with its own snapshots to form a complete picture of the profiling session. Using this data, charts and graphs are lazily computed (and incrementally cached) on demand, based on which commits and views are selected in the Profiler UI. +Once profiling is finished, the frontend requests profiling data from the backend one renderer at a time by sending a "_getProfilingData_" message. The backend responds with a "_profilingData_" message that contains per-root commit timing and duration information. The frontend then combines this information with its own snapshots to form a complete picture of the profiling session. Using this data, charts and graphs are lazily computed (and incrementally cached) on-demand, based on which commits and views are selected in the Profiler UI. ### Importing/exporting data