mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Track Owner for Server Components in DEV (#28753)
This implements the concept of a DEV-only "owner" for Server Components. The owner concept isn't really super useful. We barely use it anymore, but we do have it as a concept in DevTools in a couple of cases so this adds it for parity. However, this is mainly interesting because it could be used to wire up future owner-based stacks. I do this by outlining the DebugInfo for a Server Component (ReactComponentInfo). Then I just rely on Flight deduping to refer to that. I refer to the same thing by referential equality so that we can associate a Server Component parent in DebugInfo with an owner. If you suspend and replay a Server Component, we have to restore the same owner. To do that, I did a little ugly hack and stashed it on the thenable state object. Felt unnecessarily complicated to add a stateful wrapper for this one dev-only case. The owner could really be anything since it could be coming from a different implementation. Because this is the first time we have an owner other than Fiber, I have to fix up a bunch of places that assumes Fiber. I mainly did the `typeof owner.tag === 'number'` to assume it's a Fiber for now. This also doesn't actually add it to DevTools / RN Inspector yet. I just ignore them there for now. Because Server Components can be async the owner isn't tracked after an await. We need per-component AsyncLocalStorage for that. This can be done in a follow up.
This commit is contained in:
committed by
GitHub
parent
e3ebcd54b9
commit
f33a6b69c6
@@ -33,10 +33,7 @@ import {
|
||||
import {disableLogs, reenableLogs} from './DevToolsConsolePatching';
|
||||
|
||||
let prefix;
|
||||
export function describeBuiltInComponentFrame(
|
||||
name: string,
|
||||
ownerFn: void | null | Function,
|
||||
): string {
|
||||
export function describeBuiltInComponentFrame(name: string): string {
|
||||
if (prefix === undefined) {
|
||||
// Extract the VM specific prefix used by each line.
|
||||
try {
|
||||
@@ -51,10 +48,7 @@ export function describeBuiltInComponentFrame(
|
||||
}
|
||||
|
||||
export function describeDebugInfoFrame(name: string, env: ?string): string {
|
||||
return describeBuiltInComponentFrame(
|
||||
name + (env ? ' (' + env + ')' : ''),
|
||||
null,
|
||||
);
|
||||
return describeBuiltInComponentFrame(name + (env ? ' (' + env + ')' : ''));
|
||||
}
|
||||
|
||||
let reentry = false;
|
||||
@@ -292,7 +286,6 @@ export function describeNativeComponentFrame(
|
||||
|
||||
export function describeClassComponentFrame(
|
||||
ctor: Function,
|
||||
ownerFn: void | null | Function,
|
||||
currentDispatcherRef: CurrentDispatcherRef,
|
||||
): string {
|
||||
return describeNativeComponentFrame(ctor, true, currentDispatcherRef);
|
||||
@@ -300,7 +293,6 @@ export function describeClassComponentFrame(
|
||||
|
||||
export function describeFunctionComponentFrame(
|
||||
fn: Function,
|
||||
ownerFn: void | null | Function,
|
||||
currentDispatcherRef: CurrentDispatcherRef,
|
||||
): string {
|
||||
return describeNativeComponentFrame(fn, false, currentDispatcherRef);
|
||||
@@ -313,7 +305,6 @@ function shouldConstruct(Component: Function) {
|
||||
|
||||
export function describeUnknownElementTypeFrameInDEV(
|
||||
type: any,
|
||||
ownerFn: void | null | Function,
|
||||
currentDispatcherRef: CurrentDispatcherRef,
|
||||
): string {
|
||||
if (!__DEV__) {
|
||||
@@ -330,15 +321,15 @@ export function describeUnknownElementTypeFrameInDEV(
|
||||
);
|
||||
}
|
||||
if (typeof type === 'string') {
|
||||
return describeBuiltInComponentFrame(type, ownerFn);
|
||||
return describeBuiltInComponentFrame(type);
|
||||
}
|
||||
switch (type) {
|
||||
case SUSPENSE_NUMBER:
|
||||
case SUSPENSE_SYMBOL_STRING:
|
||||
return describeBuiltInComponentFrame('Suspense', ownerFn);
|
||||
return describeBuiltInComponentFrame('Suspense');
|
||||
case SUSPENSE_LIST_NUMBER:
|
||||
case SUSPENSE_LIST_SYMBOL_STRING:
|
||||
return describeBuiltInComponentFrame('SuspenseList', ownerFn);
|
||||
return describeBuiltInComponentFrame('SuspenseList');
|
||||
}
|
||||
if (typeof type === 'object') {
|
||||
switch (type.$$typeof) {
|
||||
@@ -346,7 +337,6 @@ export function describeUnknownElementTypeFrameInDEV(
|
||||
case FORWARD_REF_SYMBOL_STRING:
|
||||
return describeFunctionComponentFrame(
|
||||
type.render,
|
||||
ownerFn,
|
||||
currentDispatcherRef,
|
||||
);
|
||||
case MEMO_NUMBER:
|
||||
@@ -354,7 +344,6 @@ export function describeUnknownElementTypeFrameInDEV(
|
||||
// Memo may contain any component type so we recursively resolve it.
|
||||
return describeUnknownElementTypeFrameInDEV(
|
||||
type.type,
|
||||
ownerFn,
|
||||
currentDispatcherRef,
|
||||
);
|
||||
case LAZY_NUMBER:
|
||||
@@ -366,7 +355,6 @@ export function describeUnknownElementTypeFrameInDEV(
|
||||
// Lazy may contain any component type so we recursively resolve it.
|
||||
return describeUnknownElementTypeFrameInDEV(
|
||||
init(payload),
|
||||
ownerFn,
|
||||
currentDispatcherRef,
|
||||
);
|
||||
} catch (x) {}
|
||||
|
||||
Reference in New Issue
Block a user