Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
arav-ind authored Feb 9, 2023
2 parents b13fdb7 + 78d2e9e commit cc2c487
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages/react-devtools-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
"@reach/menu-button": "^0.16.1",
"@reach/tooltip": "^0.16.0",
"clipboard-js": "^0.3.6",
"compare-versions": "^5.0.3",
"json5": "^2.1.3",
"local-storage-fallback": "^4.1.1",
"lodash.throttle": "^4.1.1",
"memoize-one": "^3.1.1",
"react-virtualized-auto-sizer": "^1.0.6",
"semver": "^6.3.0"
"react-virtualized-auto-sizer": "^1.0.6"
}
}
16 changes: 16 additions & 0 deletions packages/react-devtools-shared/src/__tests__/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {stackToComponentSources} from 'react-devtools-shared/src/devtools/utils'
import {
format,
formatWithStyles,
gt,
gte,
} from 'react-devtools-shared/src/backend/utils';
import {
REACT_SUSPENSE_LIST_TYPE as SuspenseList,
Expand Down Expand Up @@ -252,4 +254,18 @@ describe('utils', () => {
]);
});
});

describe('semver comparisons', () => {
it('gte should compare versions correctly', () => {
expect(gte('1.2.3', '1.2.1')).toBe(true);
expect(gte('1.2.1', '1.2.1')).toBe(true);
expect(gte('1.2.1', '1.2.2')).toBe(false);
});

it('gt should compare versions correctly', () => {
expect(gt('1.2.3', '1.2.1')).toBe(true);
expect(gt('1.2.1', '1.2.1')).toBe(false);
expect(gt('1.2.1', '1.2.2')).toBe(false);
});
});
});
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @flow
*/

import {gt, gte} from 'semver';
import {
ComponentFilterDisplayName,
ComponentFilterElementType,
Expand Down Expand Up @@ -39,6 +38,7 @@ import {
utfEncodeString,
} from 'react-devtools-shared/src/utils';
import {sessionStorageGetItem} from 'react-devtools-shared/src/storage';
import {gt, gte} from 'react-devtools-shared/src/backend/utils';
import {
cleanForBridge,
copyToClipboard,
Expand Down
9 changes: 9 additions & 0 deletions packages/react-devtools-shared/src/backend/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import {copy} from 'clipboard-js';
import {compareVersions} from 'compare-versions';
import {dehydrate} from '../hydration';
import isArray from 'shared/isArray';

Expand Down Expand Up @@ -275,3 +276,11 @@ export function isSynchronousXHRSupported(): boolean {
window.document.featurePolicy.allowsFeature('sync-xhr')
);
}

export function gt(a: string = '', b: string = ''): boolean {
return compareVersions(a, b) === 1;
}

export function gte(a: string = '', b: string = ''): boolean {
return compareVersions(a, b) > -1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {gte} from 'semver';
import ListApp from '../e2e-apps/ListApp';
import ListAppLegacy from '../e2e-apps/ListAppLegacy';
import {gte} from 'react-devtools-shared/src/backend/utils';

const version = process.env.E2E_APP_REACT_VERSION;

function mountApp(App: () => React$Node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let JSDOM;
let Stream;
let Scheduler;
let React;
let ReactDOM;
let ReactDOMClient;
let ReactDOMFizzServer;
let document;
Expand All @@ -28,6 +29,7 @@ describe('ReactDOM HostSingleton', () => {
JSDOM = require('jsdom').JSDOM;
Scheduler = require('scheduler');
React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
ReactDOMFizzServer = require('react-dom/server');
Stream = require('stream');
Expand Down Expand Up @@ -1007,4 +1009,19 @@ describe('ReactDOM HostSingleton', () => {
</html>,
);
});

// https://github.com/facebook/react/issues/26128
it('(#26128) does not throw when rendering at body', async () => {
ReactDOM.render(<div />, document.body);
});

// https://github.com/facebook/react/issues/26128
it('(#26128) does not throw when rendering at <html>', async () => {
ReactDOM.render(<body />, document.documentElement);
});

// https://github.com/facebook/react/issues/26128
it('(#26128) does not throw when rendering at document', async () => {
ReactDOM.render(<html />, document);
});
});
17 changes: 11 additions & 6 deletions packages/react-dom/src/__tests__/ReactMount-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,17 @@ describe('ReactMount', () => {
const iFrame = document.createElement('iframe');
document.body.appendChild(iFrame);

expect(() =>
ReactDOM.render(<div />, iFrame.contentDocument.body),
).toErrorDev(
'Rendering components directly into document.body is discouraged',
{withoutStack: true},
);
if (gate(flags => flags.enableHostSingletons)) {
// HostSingletons make the warning for document.body unecessary
ReactDOM.render(<div />, iFrame.contentDocument.body);
} else {
expect(() =>
ReactDOM.render(<div />, iFrame.contentDocument.body),
).toErrorDev(
'Rendering components directly into document.body is discouraged',
{withoutStack: true},
);
}
});

it('should account for escaping on a checksum mismatch', () => {
Expand Down
18 changes: 9 additions & 9 deletions packages/react-dom/src/__tests__/validateDOMNesting-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ function expectWarnings(tags, warnings = [], withoutStack = 0) {
element = <Tag>{element}</Tag>;
}

expect(() => ReactDOM.render(element, container)).toErrorDev(warnings, {
withoutStack,
});
if (warnings.length) {
expect(() => ReactDOM.render(element, container)).toErrorDev(warnings, {
withoutStack,
});
}
}

describe('validateDOMNesting', () => {
Expand All @@ -39,8 +41,10 @@ describe('validateDOMNesting', () => {
expectWarnings(
['body', 'datalist', 'option'],
[
'render(): Rendering components directly into document.body is discouraged',
],
gate(flags => !flags.enableHostSingletons)
? 'render(): Rendering components directly into document.body is discouraged'
: null,
].filter(Boolean),
1,
);
expectWarnings(['div', 'a', 'object', 'a']);
Expand Down Expand Up @@ -106,13 +110,9 @@ describe('validateDOMNesting', () => {
expectWarnings(
['body', 'body'],
[
'render(): Rendering components directly into document.body is discouraged',
'validateDOMNesting(...): <body> cannot appear as a child of <body>.\n' +
' in body (at **)',
'Warning: You are mounting a new body component when a previous one has not first unmounted. It is an error to render more than one body component at a time and attributes and children of these components will likely fail in unpredictable ways. Please only render a single instance of <body> and if you need to mount a new one, ensure any previous ones have unmounted first.\n' +
' in body (at **)',
],
1,
);
} else {
expectWarnings(
Expand Down
8 changes: 4 additions & 4 deletions packages/react-dom/src/client/ReactDOMLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
import type {ReactNodeList} from 'shared/ReactTypes';

import {clearContainer} from 'react-dom-bindings/src/client/ReactDOMHostConfig';
import {
getInstanceFromNode,
isContainerMarkedAsRoot,
Expand Down Expand Up @@ -42,6 +43,7 @@ import {LegacyRoot} from 'react-reconciler/src/ReactRootTags';
import getComponentNameFromType from 'shared/getComponentNameFromType';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {has as hasInstance} from 'shared/ReactInstanceMap';
import {enableHostSingletons} from '../../../shared/ReactFeatureFlags';

const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;

Expand Down Expand Up @@ -79,6 +81,7 @@ if (__DEV__) {
}

if (
!enableHostSingletons &&
container.nodeType === ELEMENT_NODE &&
((container: any): Element).tagName &&
((container: any): Element).tagName.toUpperCase() === 'BODY'
Expand Down Expand Up @@ -152,10 +155,7 @@ function legacyCreateRootFromDOMContainer(
return root;
} else {
// First clear any existing content.
let rootSibling;
while ((rootSibling = container.lastChild)) {
container.removeChild(rootSibling);
}
clearContainer(container);

if (typeof callback === 'function') {
const originalCallback = callback;
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5458,6 +5458,11 @@ commondir@^1.0.1:
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=

compare-versions@^5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-5.0.3.tgz#a9b34fea217472650ef4a2651d905f42c28ebfd7"
integrity sha512-4UZlZP8Z99MGEY+Ovg/uJxJuvoXuN4M6B3hKaiackiHrgzQFEe3diJi1mf1PNHbFujM7FvLrK2bpgIaImbtZ1A==

component-emitter@^1.2.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"
Expand Down

0 comments on commit cc2c487

Please sign in to comment.