Skip to content

Commit 07534da

Browse files
Merge branch 'main' into react-reconciler/remove-unused-paramaters
2 parents 7ab3bbb + 7b0642b commit 07534da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1122
-1083
lines changed

packages/react-cache/src/__tests__/ReactCacheOld-test.internal.js

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ let textResourceShouldFail;
2121
let waitForAll;
2222
let assertLog;
2323
let waitForThrow;
24+
let act;
2425

2526
describe('ReactCache', () => {
2627
beforeEach(() => {
@@ -40,6 +41,7 @@ describe('ReactCache', () => {
4041
waitForAll = InternalTestUtils.waitForAll;
4142
assertLog = InternalTestUtils.assertLog;
4243
waitForThrow = InternalTestUtils.waitForThrow;
44+
act = InternalTestUtils.act;
4345

4446
TextResource = createResource(
4547
([text, ms = 0]) => {
@@ -145,11 +147,14 @@ describe('ReactCache', () => {
145147
await waitForAll(['Suspend! [Hi]', 'Loading...']);
146148

147149
textResourceShouldFail = true;
148-
jest.advanceTimersByTime(100);
149-
assertLog(['Promise rejected [Hi]']);
150-
151-
await waitForThrow('Failed to load: Hi');
152-
assertLog(['Error! [Hi]', 'Error! [Hi]']);
150+
let error;
151+
try {
152+
await act(() => jest.advanceTimersByTime(100));
153+
} catch (e) {
154+
error = e;
155+
}
156+
expect(error.message).toMatch('Failed to load: Hi');
157+
assertLog(['Promise rejected [Hi]', 'Error! [Hi]', 'Error! [Hi]']);
153158

154159
// Should throw again on a subsequent read
155160
root.update(<App />);
@@ -217,9 +222,8 @@ describe('ReactCache', () => {
217222
assertLog(['Promise resolved [2]']);
218223
await waitForAll([1, 2, 'Suspend! [3]']);
219224

220-
jest.advanceTimersByTime(100);
221-
assertLog(['Promise resolved [3]']);
222-
await waitForAll([1, 2, 3]);
225+
await act(() => jest.advanceTimersByTime(100));
226+
assertLog(['Promise resolved [3]', 1, 2, 3]);
223227

224228
expect(root).toMatchRenderedOutput('123');
225229

@@ -234,13 +238,17 @@ describe('ReactCache', () => {
234238

235239
await waitForAll([1, 'Suspend! [4]', 'Loading...']);
236240

237-
jest.advanceTimersByTime(100);
238-
assertLog(['Promise resolved [4]']);
239-
await waitForAll([1, 4, 'Suspend! [5]']);
240-
241-
jest.advanceTimersByTime(100);
242-
assertLog(['Promise resolved [5]']);
243-
await waitForAll([1, 4, 5]);
241+
await act(() => jest.advanceTimersByTime(100));
242+
assertLog([
243+
'Promise resolved [4]',
244+
1,
245+
4,
246+
'Suspend! [5]',
247+
'Promise resolved [5]',
248+
1,
249+
4,
250+
5,
251+
]);
244252

245253
expect(root).toMatchRenderedOutput('145');
246254

@@ -262,13 +270,18 @@ describe('ReactCache', () => {
262270
'Suspend! [2]',
263271
'Loading...',
264272
]);
265-
jest.advanceTimersByTime(100);
266-
assertLog(['Promise resolved [2]']);
267-
await waitForAll([1, 2, 'Suspend! [3]']);
268273

269-
jest.advanceTimersByTime(100);
270-
assertLog(['Promise resolved [3]']);
271-
await waitForAll([1, 2, 3]);
274+
await act(() => jest.advanceTimersByTime(100));
275+
assertLog([
276+
'Promise resolved [2]',
277+
1,
278+
2,
279+
'Suspend! [3]',
280+
'Promise resolved [3]',
281+
1,
282+
2,
283+
3,
284+
]);
272285
expect(root).toMatchRenderedOutput('123');
273286
});
274287

@@ -291,9 +304,8 @@ describe('ReactCache', () => {
291304

292305
await waitForAll(['Loading...']);
293306

294-
jest.advanceTimersByTime(1000);
295-
assertLog(['Promise resolved [B]', 'Promise resolved [A]']);
296-
await waitForAll(['Result']);
307+
await act(() => jest.advanceTimersByTime(1000));
308+
assertLog(['Promise resolved [B]', 'Promise resolved [A]', 'Result']);
297309
expect(root).toMatchRenderedOutput('Result');
298310
});
299311

packages/react-devtools-extensions/src/contentScripts/prepareInjection.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,3 @@ if (IS_FIREFOX) {
128128
}
129129
}
130130
}
131-
132-
if (typeof exportFunction === 'function') {
133-
// eslint-disable-next-line no-undef
134-
exportFunction(
135-
text => {
136-
// Call clipboard.writeText from the extension content script
137-
// (as it has the clipboardWrite permission) and return a Promise
138-
// accessible to the webpage js code.
139-
return new window.Promise((resolve, reject) =>
140-
window.navigator.clipboard.writeText(text).then(resolve, reject),
141-
);
142-
},
143-
window.wrappedJSObject.__REACT_DEVTOOLS_GLOBAL_HOOK__,
144-
{defineAs: 'clipboardCopyText'},
145-
);
146-
}

packages/react-devtools-extensions/src/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ function createPanelIfReactLoaded() {
475475

476476
chrome.devtools.panels.create(
477477
IS_CHROME || IS_EDGE ? '⚛️ Components' : 'Components',
478-
'',
478+
IS_EDGE ? 'icons/production.svg' : '',
479479
'panel.html',
480480
extensionPanel => {
481481
extensionPanel.onShown.addListener(panel => {
@@ -506,7 +506,7 @@ function createPanelIfReactLoaded() {
506506

507507
chrome.devtools.panels.create(
508508
IS_CHROME || IS_EDGE ? '⚛️ Profiler' : 'Profiler',
509-
'',
509+
IS_EDGE ? 'icons/production.svg' : '',
510510
'panel.html',
511511
extensionPanel => {
512512
extensionPanel.onShown.addListener(panel => {

packages/react-devtools-shared/src/__tests__/inspectedElement-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,7 @@ describe('InspectedElement', () => {
18011801
jest.runOnlyPendingTimers();
18021802
expect(global.mockClipboardCopy).toHaveBeenCalledTimes(1);
18031803
expect(global.mockClipboardCopy).toHaveBeenCalledWith(
1804-
JSON.stringify(nestedObject),
1804+
JSON.stringify(nestedObject, undefined, 2),
18051805
);
18061806

18071807
global.mockClipboardCopy.mockReset();
@@ -1811,7 +1811,7 @@ describe('InspectedElement', () => {
18111811
jest.runOnlyPendingTimers();
18121812
expect(global.mockClipboardCopy).toHaveBeenCalledTimes(1);
18131813
expect(global.mockClipboardCopy).toHaveBeenCalledWith(
1814-
JSON.stringify(nestedObject.a.b),
1814+
JSON.stringify(nestedObject.a.b, undefined, 2),
18151815
);
18161816
});
18171817

@@ -1894,7 +1894,7 @@ describe('InspectedElement', () => {
18941894
jest.runOnlyPendingTimers();
18951895
expect(global.mockClipboardCopy).toHaveBeenCalledTimes(1);
18961896
expect(global.mockClipboardCopy).toHaveBeenCalledWith(
1897-
JSON.stringify('123n'),
1897+
JSON.stringify('123n', undefined, 2),
18981898
);
18991899

19001900
global.mockClipboardCopy.mockReset();
@@ -1904,7 +1904,7 @@ describe('InspectedElement', () => {
19041904
jest.runOnlyPendingTimers();
19051905
expect(global.mockClipboardCopy).toHaveBeenCalledTimes(1);
19061906
expect(global.mockClipboardCopy).toHaveBeenCalledWith(
1907-
JSON.stringify({0: 100, 1: -100, 2: 0}),
1907+
JSON.stringify({0: 100, 1: -100, 2: 0}, undefined, 2),
19081908
);
19091909
});
19101910

packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('InspectedElementContext', () => {
2626

2727
async function read(
2828
id: number,
29-
path?: Array<string | number> = null,
29+
path: Array<string | number> = null,
3030
): Promise<Object> {
3131
const rendererID = ((store.getRendererIDForElement(id): any): number);
3232
const promise = backendAPI
@@ -826,7 +826,7 @@ describe('InspectedElementContext', () => {
826826
jest.runOnlyPendingTimers();
827827
expect(global.mockClipboardCopy).toHaveBeenCalledTimes(1);
828828
expect(global.mockClipboardCopy).toHaveBeenCalledWith(
829-
JSON.stringify(nestedObject),
829+
JSON.stringify(nestedObject, undefined, 2),
830830
);
831831

832832
global.mockClipboardCopy.mockReset();
@@ -842,7 +842,7 @@ describe('InspectedElementContext', () => {
842842
jest.runOnlyPendingTimers();
843843
expect(global.mockClipboardCopy).toHaveBeenCalledTimes(1);
844844
expect(global.mockClipboardCopy).toHaveBeenCalledWith(
845-
JSON.stringify(nestedObject.a.b),
845+
JSON.stringify(nestedObject.a.b, undefined, 2),
846846
);
847847
});
848848

@@ -932,7 +932,7 @@ describe('InspectedElementContext', () => {
932932
jest.runOnlyPendingTimers();
933933
expect(global.mockClipboardCopy).toHaveBeenCalledTimes(1);
934934
expect(global.mockClipboardCopy).toHaveBeenCalledWith(
935-
JSON.stringify({0: 100, 1: -100, 2: 0}),
935+
JSON.stringify({0: 100, 1: -100, 2: 0}, undefined, 2),
936936
);
937937
});
938938
});

packages/react-devtools-shared/src/backend/agent.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,13 @@ export default class Agent extends EventEmitter<{
300300
if (renderer == null) {
301301
console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`);
302302
} else {
303-
renderer.copyElementPath(id, path);
303+
const value = renderer.getSerializedElementValueByPath(id, path);
304+
305+
if (value != null) {
306+
this._bridge.send('saveToClipboard', value);
307+
} else {
308+
console.warn(`Unable to obtain serialized value for element "${id}"`);
309+
}
304310
}
305311
};
306312

packages/react-devtools-shared/src/backend/legacy/renderer.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import {
1717
import {getUID, utfEncodeString, printOperationsArray} from '../../utils';
1818
import {
1919
cleanForBridge,
20-
copyToClipboard,
2120
copyWithDelete,
2221
copyWithRename,
2322
copyWithSet,
23+
serializeToString,
2424
} from '../utils';
2525
import {
2626
deletePathInObject,
@@ -701,10 +701,15 @@ export function attach(
701701
}
702702
}
703703

704-
function copyElementPath(id: number, path: Array<string | number>): void {
704+
function getSerializedElementValueByPath(
705+
id: number,
706+
path: Array<string | number>,
707+
): ?string {
705708
const inspectedElement = inspectElementRaw(id);
706709
if (inspectedElement !== null) {
707-
copyToClipboard(getInObject(inspectedElement, path));
710+
const valueToCopy = getInObject(inspectedElement, path);
711+
712+
return serializeToString(valueToCopy);
708713
}
709714
}
710715

@@ -1105,7 +1110,7 @@ export function attach(
11051110
clearErrorsForFiberID,
11061111
clearWarningsForFiberID,
11071112
cleanup,
1108-
copyElementPath,
1113+
getSerializedElementValueByPath,
11091114
deletePath,
11101115
flushInitialOperations,
11111116
getBestMatchForTrackedPath,

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ import {
3838
utfEncodeString,
3939
} from 'react-devtools-shared/src/utils';
4040
import {sessionStorageGetItem} from 'react-devtools-shared/src/storage';
41-
import {gt, gte} from 'react-devtools-shared/src/backend/utils';
41+
import {
42+
gt,
43+
gte,
44+
serializeToString,
45+
} from 'react-devtools-shared/src/backend/utils';
4246
import {
4347
cleanForBridge,
44-
copyToClipboard,
4548
copyWithDelete,
4649
copyWithRename,
4750
copyWithSet,
@@ -809,7 +812,7 @@ export function attach(
809812
name: string,
810813
fiber: Fiber,
811814
parentFiber: ?Fiber,
812-
extraString?: string = '',
815+
extraString: string = '',
813816
): void => {
814817
if (__DEBUG__) {
815818
const displayName =
@@ -3544,14 +3547,17 @@ export function attach(
35443547
}
35453548
}
35463549

3547-
function copyElementPath(id: number, path: Array<string | number>): void {
3550+
function getSerializedElementValueByPath(
3551+
id: number,
3552+
path: Array<string | number>,
3553+
): ?string {
35483554
if (isMostRecentlyInspectedElement(id)) {
3549-
copyToClipboard(
3550-
getInObject(
3551-
((mostRecentlyInspectedElement: any): InspectedElement),
3552-
path,
3553-
),
3555+
const valueToCopy = getInObject(
3556+
((mostRecentlyInspectedElement: any): InspectedElement),
3557+
path,
35543558
);
3559+
3560+
return serializeToString(valueToCopy);
35553561
}
35563562
}
35573563

@@ -4494,7 +4500,7 @@ export function attach(
44944500
clearErrorsAndWarnings,
44954501
clearErrorsForFiberID,
44964502
clearWarningsForFiberID,
4497-
copyElementPath,
4503+
getSerializedElementValueByPath,
44984504
deletePath,
44994505
findNativeNodesForFiberID,
45004506
flushInitialOperations,

packages/react-devtools-shared/src/backend/types.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ export type RendererInterface = {
350350
clearErrorsAndWarnings: () => void,
351351
clearErrorsForFiberID: (id: number) => void,
352352
clearWarningsForFiberID: (id: number) => void,
353-
copyElementPath: (id: number, path: Array<string | number>) => void,
354353
deletePath: (
355354
type: Type,
356355
id: number,
@@ -367,6 +366,10 @@ export type RendererInterface = {
367366
getProfilingData(): ProfilingDataBackend,
368367
getOwnersList: (id: number) => Array<SerializedElement> | null,
369368
getPathForElement: (id: number) => Array<PathFrame> | null,
369+
getSerializedElementValueByPath: (
370+
id: number,
371+
path: Array<string | number>,
372+
) => ?string,
370373
handleCommitFiberRoot: (fiber: Object, commitPriority?: number) => void,
371374
handleCommitFiberUnmount: (fiber: Object) => void,
372375
handlePostCommitFiberRoot: (fiber: Object) => void,

0 commit comments

Comments
 (0)