100
SERVER_CONTEXT_SYMBOL_STRING,
101
} from '../shared/ReactSymbols';
102
import {enableStyleXFeatures} from 'react-devtools-feature-flags';
103
+
104
+import {componentInfoToComponentLogsMap} from '../shared/DevToolsServerComponentLogs';
105
+
106
import is from 'shared/objectIs';
107
import hasOwnProperty from 'shared/hasOwnProperty';
108
998
// Note, this only clears logs for Fibers that have instances. If they're filtered
999
// and then mount, the logs are there. Ensuring we only clear what you've seen.
1000
// If we wanted to clear the whole set, we'd replace fiberToComponentLogsMap with a
998
- // new WeakMap.
1001
+ // new WeakMap. It's unclear whether we should clear componentInfoToComponentLogsMap
1002
+ // since it's shared by other renderers but presumably it would.
1003
1004
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
1005
for (const devtoolsInstance of idToDevToolsInstanceMap.values()) {
1010
fiberToComponentLogsMap.delete(fiber.alternate);
1011
}
1012
} else {
1009
- // TODO: Handle VirtualInstance.
1013
+ componentInfoToComponentLogsMap.delete(devtoolsInstance.data);
1014
}
1015
const changed = recordConsoleLogs(devtoolsInstance, undefined);
1016
if (changed) {
1023
function clearConsoleLogsHelper(instanceID: number, type: 'error' | 'warn') {
1024
const devtoolsInstance = idToDevToolsInstanceMap.get(instanceID);
1025
if (devtoolsInstance !== undefined) {
1026
+ let componentLogsEntry;
1027
if (devtoolsInstance.kind === FIBER_INSTANCE) {
1028
const fiber = devtoolsInstance.data;
1024
- const componentLogsEntry = fiberToComponentLogsMap.get(fiber);
1025
- if (componentLogsEntry !== undefined) {
1026
- if (type === 'error') {
1027
- componentLogsEntry.errors.clear();
1028
- componentLogsEntry.errorsCount = 0;
1029
- } else {
1030
- componentLogsEntry.warnings.clear();
1031
- componentLogsEntry.warningsCount = 0;
1032
- }
1033
- const changed = recordConsoleLogs(
1034
- devtoolsInstance,
1035
- componentLogsEntry,
1036
- );
1037
- if (changed) {
1038
- flushPendingEvents();
1039
- updateMostRecentlyInspectedElementIfNecessary(devtoolsInstance.id);
1040
- }
1041
- }
1029
+ componentLogsEntry = fiberToComponentLogsMap.get(fiber);
1030
} else {
1043
- // TODO: Handle VirtualInstance.
1031
+ const componentInfo = devtoolsInstance.data;
1032
+ componentLogsEntry = componentInfoToComponentLogsMap.get(componentInfo);
1033
+ }
1034
+ if (componentLogsEntry !== undefined) {
1035
+ if (type === 'error') {
1036
+ componentLogsEntry.errors.clear();
1037
+ componentLogsEntry.errorsCount = 0;
1038
+ } else {
1039
+ componentLogsEntry.warnings.clear();
1040
+ componentLogsEntry.warningsCount = 0;
1041
+ }
1042
+ const changed = recordConsoleLogs(devtoolsInstance, componentLogsEntry);
1043
+ if (changed) {
1044
+ flushPendingEvents();
1045
+ updateMostRecentlyInspectedElementIfNecessary(devtoolsInstance.id);
1046
+ }
1047
}
1048
}
1049
}
2191
pushOperation(ownerID);
2192
pushOperation(displayNameStringID);
2193
pushOperation(keyStringID);
2194
+
2195
+ const componentLogsEntry =
2196
+ componentInfoToComponentLogsMap.get(componentInfo);
2197
+ recordConsoleLogs(instance, componentLogsEntry);
2198
}
2199
2200
function recordUnmount(fiberInstance: FiberInstance): void {
2864
) {
2865
recordResetChildren(virtualInstance);
2866
}
2867
+ // Update the errors/warnings count. If this Instance has switched to a different
2868
+ // ReactComponentInfo instance, such as when refreshing Server Components, then
2869
+ // we replace all the previous logs with the ones associated with the new ones rather
2870
+ // than merging. Because deduping is expected to happen at the request level.
2871
+ const componentLogsEntry = componentInfoToComponentLogsMap.get(
2872
+ virtualInstance.data,
2873
+ );
2874
+ recordConsoleLogs(virtualInstance, componentLogsEntry);
2875
// Must be called after all children have been appended.
2876
recordVirtualProfilingDurations(virtualInstance);
2877
} finally {
4308
stylex: null,
4309
};
4310
4311
+ const componentLogsEntry =
4312
+ componentInfoToComponentLogsMap.get(componentInfo);
4313
+
4314
return {
4315
id: virtualInstance.id,
4316
4344
hooks: null,
4345
props: props,
4346
state: null,
4329
- errors: [], // TODO: Handle errors on Virtual Instances.
4330
- warnings: [], // TODO: Handle warnings on Virtual Instances.
4347
+ errors:
4348
+ componentLogsEntry === undefined
4349
+ ? []
4350
+ : Array.from(componentLogsEntry.errors.entries()),
4351
+ warnings:
4352
+ componentLogsEntry === undefined
4353
+ ? []
4354
+ : Array.from(componentLogsEntry.warnings.entries()),
4355
// List of owners
4356
owners,
4357