-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DevTools] Add Map for Server Component Logs (#30905)
Stacked on #30899. This adds another map to store Server Components logs. When they're replayed with an owner we can associate them with a DevToolsInstance. The replaying should happen before they can mount in Fiber so they'll always have all logs when they mount. There can be more than one Instance associated with any particular ReactComponentInfo. It can also be unmounted and restored later. One thing that's interesting about these is that when a Server Component tree refreshes a new set of ReactComponentInfo will update through the tree and the VirtualInstances will update with new instances. This means that the old errors/warnings are no longer associated with the VirtualInstance. I.e. it's not continually appended like updates do for Fiber backed instances. On the client we dedupe errors/warnings for the life time of the page. On the server that doesn't work well because it would mean that when you refresh the page, you miss out on warnings so we dedupe them per request instead. If we just appended on refresh it would keep adding them. If ever add a deduping mechanism that spans longer than a request, we might need to do more of a merge when these updates. Nothing actually adds logs to this map yet. That will need an integration with Flight in a follow up.
- Loading branch information
1 parent
f4b3a1f
commit fa3cf50
Showing
2 changed files
with
76 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/react-devtools-shared/src/backend/shared/DevToolsServerComponentLogs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
// This keeps track of Server Component logs which may come from. | ||
// This is in a shared module because Server Component logs don't come from a specific renderer | ||
// but can become associated with a Virtual Instance of any renderer. | ||
|
||
import type {ReactComponentInfo} from 'shared/ReactTypes'; | ||
|
||
type ComponentLogs = { | ||
errors: Map<string, number>, | ||
errorsCount: number, | ||
warnings: Map<string, number>, | ||
warningsCount: number, | ||
}; | ||
|
||
// This keeps it around as long as the ComponentInfo is alive which | ||
// lets the Fiber get reparented/remounted and still observe the previous errors/warnings. | ||
// Unless we explicitly clear the logs from a Fiber. | ||
export const componentInfoToComponentLogsMap: WeakMap< | ||
ReactComponentInfo, | ||
ComponentLogs, | ||
> = new WeakMap(); |