@samitouri / QOS-React-2 / commits / 3ad17ecd31

Remove enableComponentStackLocations (#31764)

This has landed everywhere

Ricky committed Dec 13, 2024 at 15:52 UTC 3ad17ecd313a8e53b339adf8052e35b3d73f8c62
9 files changed +22 -192
packages/shared/ReactComponentStackFrame.js
+21 -47
@@ -9,8 +9,6 @@
9
10 import type {LazyComponent} from 'react/src/ReactLazy';
11
12 -import {enableComponentStackLocations} from 'shared/ReactFeatureFlags';
13 -
12 import {
13 REACT_SUSPENSE_TYPE,
14 REACT_SUSPENSE_LIST_TYPE,
@@ -28,30 +26,26 @@ import DefaultPrepareStackTrace from 'shared/DefaultPrepareStackTrace';
26 let prefix;
27 let suffix;
28 export function describeBuiltInComponentFrame(name: string): string {
31 - if (enableComponentStackLocations) {
32 - if (prefix === undefined) {
33 - // Extract the VM specific prefix used by each line.
34 - try {
35 - throw Error();
36 - } catch (x) {
37 - const match = x.stack.trim().match(/\n( *(at )?)/);
38 - prefix = (match && match[1]) || '';
39 - suffix =
40 - x.stack.indexOf('\n at') > -1
41 - ? // V8
42 - ' (<anonymous>)'
43 - : // JSC/Spidermonkey
44 - x.stack.indexOf('@') > -1
45 - ? '@unknown:0:0'
46 - : // Other
47 - '';
48 - }
29 + if (prefix === undefined) {
30 + // Extract the VM specific prefix used by each line.
31 + try {
32 + throw Error();
33 + } catch (x) {
34 + const match = x.stack.trim().match(/\n( *(at )?)/);
35 + prefix = (match && match[1]) || '';
36 + suffix =
37 + x.stack.indexOf('\n at') > -1
38 + ? // V8
39 + ' (<anonymous>)'
40 + : // JSC/Spidermonkey
41 + x.stack.indexOf('@') > -1
42 + ? '@unknown:0:0'
43 + : // Other
44 + '';
45 }
50 - // We use the prefix to ensure our stacks line up with native stack frames.
51 - return '\n' + prefix + name + suffix;
52 - } else {
53 - return describeComponentFrame(name);
46 }
47 + // We use the prefix to ensure our stacks line up with native stack frames.
48 + return '\n' + prefix + name + suffix;
49 }
50
51 export function describeDebugInfoFrame(name: string, env: ?string): string {
@@ -296,28 +290,12 @@ export function describeNativeComponentFrame(
290 return syntheticFrame;
291 }
292
299 -function describeComponentFrame(name: null | string) {
300 - return '\n in ' + (name || 'Unknown');
301 -}
302 -
293 export function describeClassComponentFrame(ctor: Function): string {
304 - if (enableComponentStackLocations) {
305 - return describeNativeComponentFrame(ctor, true);
306 - } else {
307 - return describeFunctionComponentFrame(ctor);
308 - }
294 + return describeNativeComponentFrame(ctor, true);
295 }
296
297 export function describeFunctionComponentFrame(fn: Function): string {
312 - if (enableComponentStackLocations) {
313 - return describeNativeComponentFrame(fn, false);
314 - } else {
315 - if (!fn) {
316 - return '';
317 - }
318 - const name = fn.displayName || fn.name || null;
319 - return describeComponentFrame(name);
320 - }
298 + return describeNativeComponentFrame(fn, false);
299 }
300
301 function shouldConstruct(Component: Function) {
@@ -334,11 +312,7 @@ export function describeUnknownElementTypeFrameInDEV(type: any): string {
312 return '';
313 }
314 if (typeof type === 'function') {
337 - if (enableComponentStackLocations) {
338 - return describeNativeComponentFrame(type, shouldConstruct(type));
339 - } else {
340 - return describeFunctionComponentFrame(type);
341 - }
315 + return describeNativeComponentFrame(type, shouldConstruct(type));
316 }
317 if (typeof type === 'string') {
318 return describeBuiltInComponentFrame(type);
packages/shared/ReactFeatureFlags.js
+1 -1
@@ -13,7 +13,7 @@
13 // Flags that can likely be deleted or landed without consequences
14 // -----------------------------------------------------------------------------
15
16 -export const enableComponentStackLocations = true;
16 +// None
17
18 // -----------------------------------------------------------------------------
19 // Killswitch
packages/shared/__tests__/describeComponentFrame-test.js deleted
-137
@@ -1,137 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @emails react-core
8 - */
9 -
10 -'use strict';
11 -
12 -let React;
13 -let ReactDOMClient;
14 -let act;
15 -let jsxDEV;
16 -
17 -describe('Component stack trace displaying', () => {
18 - beforeEach(() => {
19 - React = require('react');
20 - ReactDOMClient = require('react-dom/client');
21 - act = require('internal-test-utils').act;
22 - jsxDEV = require('react/jsx-dev-runtime').jsxDEV;
23 - });
24 -
25 - // @gate !enableComponentStackLocations
26 - // @gate __DEV__
27 - it('should provide filenames in stack traces', async () => {
28 - class Component extends React.Component {
29 - render() {
30 - return [<span>a</span>, <span>b</span>];
31 - }
32 - }
33 -
34 - spyOnDev(console, 'error');
35 - const container = document.createElement('div');
36 - const fileNames = {
37 - '': '',
38 - '/': '',
39 - '\\': '',
40 - Foo: 'Foo',
41 - 'Bar/Foo': 'Foo',
42 - 'Bar\\Foo': 'Foo',
43 - 'Baz/Bar/Foo': 'Foo',
44 - 'Baz\\Bar\\Foo': 'Foo',
45 -
46 - 'Foo.js': 'Foo.js',
47 - 'Foo.jsx': 'Foo.jsx',
48 - '/Foo.js': 'Foo.js',
49 - '/Foo.jsx': 'Foo.jsx',
50 - '\\Foo.js': 'Foo.js',
51 - '\\Foo.jsx': 'Foo.jsx',
52 - 'Bar/Foo.js': 'Foo.js',
53 - 'Bar/Foo.jsx': 'Foo.jsx',
54 - 'Bar\\Foo.js': 'Foo.js',
55 - 'Bar\\Foo.jsx': 'Foo.jsx',
56 - '/Bar/Foo.js': 'Foo.js',
57 - '/Bar/Foo.jsx': 'Foo.jsx',
58 - '\\Bar\\Foo.js': 'Foo.js',
59 - '\\Bar\\Foo.jsx': 'Foo.jsx',
60 - 'Bar/Baz/Foo.js': 'Foo.js',
61 - 'Bar/Baz/Foo.jsx': 'Foo.jsx',
62 - 'Bar\\Baz\\Foo.js': 'Foo.js',
63 - 'Bar\\Baz\\Foo.jsx': 'Foo.jsx',
64 - '/Bar/Baz/Foo.js': 'Foo.js',
65 - '/Bar/Baz/Foo.jsx': 'Foo.jsx',
66 - '\\Bar\\Baz\\Foo.js': 'Foo.js',
67 - '\\Bar\\Baz\\Foo.jsx': 'Foo.jsx',
68 - 'C:\\funny long (path)/Foo.js': 'Foo.js',
69 - 'C:\\funny long (path)/Foo.jsx': 'Foo.jsx',
70 -
71 - 'index.js': 'index.js',
72 - 'index.jsx': 'index.jsx',
73 - '/index.js': 'index.js',
74 - '/index.jsx': 'index.jsx',
75 - '\\index.js': 'index.js',
76 - '\\index.jsx': 'index.jsx',
77 - 'Bar/index.js': 'Bar/index.js',
78 - 'Bar/index.jsx': 'Bar/index.jsx',
79 - 'Bar\\index.js': 'Bar/index.js',
80 - 'Bar\\index.jsx': 'Bar/index.jsx',
81 - '/Bar/index.js': 'Bar/index.js',
82 - '/Bar/index.jsx': 'Bar/index.jsx',
83 - '\\Bar\\index.js': 'Bar/index.js',
84 - '\\Bar\\index.jsx': 'Bar/index.jsx',
85 - 'Bar/Baz/index.js': 'Baz/index.js',
86 - 'Bar/Baz/index.jsx': 'Baz/index.jsx',
87 - 'Bar\\Baz\\index.js': 'Baz/index.js',
88 - 'Bar\\Baz\\index.jsx': 'Baz/index.jsx',
89 - '/Bar/Baz/index.js': 'Baz/index.js',
90 - '/Bar/Baz/index.jsx': 'Baz/index.jsx',
91 - '\\Bar\\Baz\\index.js': 'Baz/index.js',
92 - '\\Bar\\Baz\\index.jsx': 'Baz/index.jsx',
93 - 'C:\\funny long (path)/index.js': 'funny long (path)/index.js',
94 - 'C:\\funny long (path)/index.jsx': 'funny long (path)/index.jsx',
95 - };
96 -
97 - const root = ReactDOMClient.createRoot(container);
98 -
99 - let i = 0;
100 - for (const fileName in fileNames) {
101 - Component.displayName = 'Component ' + i;
102 -
103 - await act(() => {
104 - root.render(
105 - // Intentionally inlining a manual jsxDEV() instead of relying on the
106 - // compiler so that we can pass a custom source location.
107 - jsxDEV(
108 - Component,
109 - {},
110 - undefined,
111 - false,
112 - {fileName, lineNumber: i},
113 - this,
114 - ),
115 - );
116 - });
117 -
118 - i++;
119 - }
120 - if (__DEV__) {
121 - i = 0;
122 - expect(console.error).toHaveBeenCalledTimes(
123 - Object.keys(fileNames).length,
124 - );
125 - for (const fileName in fileNames) {
126 - if (!fileNames.hasOwnProperty(fileName)) {
127 - continue;
128 - }
129 - const args = console.error.mock.calls[i];
130 - const stack = args[args.length - 1];
131 - const expected = fileNames[fileName];
132 - expect(stack).toContain(`at ${expected}:`);
133 - i++;
134 - }
135 - }
136 - });
137 -});
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -45,7 +45,6 @@ export const disableTextareaChildren = false;
45 export const enableAsyncDebugInfo = false;
46 export const enableAsyncIterableChildren = false;
47 export const enableCache = true;
48 -export const enableComponentStackLocations = true;
48 export const enableCPUSuspense = true;
49 export const enableCreateEventHandleAPI = false;
50 export const enableDebugTracing = false;
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -32,7 +32,6 @@ export const disableTextareaChildren = false;
32 export const enableAsyncDebugInfo = false;
33 export const enableAsyncIterableChildren = false;
34 export const enableCache = true;
35 -export const enableComponentStackLocations = true;
35 export const enableCPUSuspense = false;
36 export const enableCreateEventHandleAPI = false;
37 export const enableDebugTracing = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -40,7 +40,6 @@ export const enableUseMemoCacheHook = true;
40 export const enableNoCloningMemoCache = false;
41 export const enableUseEffectEventHook = false;
42 export const favorSafetyOverHydrationPerf = true;
43 -export const enableComponentStackLocations = true;
43 export const enableLegacyFBSupport = false;
44 export const enableFilterEmptyStringAttributesDOM = true;
45 export const enableMoveBefore = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js
-1
@@ -24,7 +24,6 @@ export const disableTextareaChildren = false;
24 export const enableAsyncDebugInfo = false;
25 export const enableAsyncIterableChildren = false;
26 export const enableCache = true;
27 -export const enableComponentStackLocations = true;
27 export const enableCPUSuspense = true;
28 export const enableCreateEventHandleAPI = false;
29 export const enableDebugTracing = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -42,7 +42,6 @@ export const enableUseMemoCacheHook = true;
42 export const enableNoCloningMemoCache = false;
43 export const enableUseEffectEventHook = false;
44 export const favorSafetyOverHydrationPerf = true;
45 -export const enableComponentStackLocations = true;
45 export const enableLegacyFBSupport = false;
46 export const enableFilterEmptyStringAttributesDOM = true;
47 export const enableMoveBefore = false;
packages/shared/forks/ReactFeatureFlags.www.js
-2
@@ -99,8 +99,6 @@ export const enableSuspenseCallback = true;
99
100 export const enableLegacyHidden = true;
101
102 -export const enableComponentStackLocations = true;
103 -
102 export const disableTextareaChildren = __EXPERIMENTAL__;
103
104 export const enableFizzExternalRuntime = true;