From ac43bf6870a15566507477a4504f22160835c8d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Mon, 10 Apr 2023 21:41:53 -0400 Subject: [PATCH] Move validation of text nesting into ReactDOMComponent (#26594) Extract validateTextNesting from validateDOMNesting. We only need the parent tag when validating text nodes. Then validate it in setProp. --- .../src/client/ReactDOMComponent.js | 7 ++ .../src/client/ReactFiberConfigDOM.js | 41 +++--------- .../src/client/validateDOMNesting.js | 67 +++++++++---------- .../src/__tests__/ReactDOMComponent-test.js | 51 ++++++++++++++ 4 files changed, 102 insertions(+), 64 deletions(-) diff --git a/packages/react-dom-bindings/src/client/ReactDOMComponent.js b/packages/react-dom-bindings/src/client/ReactDOMComponent.js index e9398cf076f61..e2ba29ceb3aed 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMComponent.js +++ b/packages/react-dom-bindings/src/client/ReactDOMComponent.js @@ -45,6 +45,7 @@ import { updateTextarea, restoreControlledTextareaState, } from './ReactDOMTextarea'; +import {validateTextNesting} from './validateDOMNesting'; import {track} from './inputValueTracking'; import setInnerHTML from './setInnerHTML'; import setTextContent from './setTextContent'; @@ -279,6 +280,9 @@ function setProp( switch (key) { case 'children': { if (typeof value === 'string') { + if (__DEV__) { + validateTextNesting(value, tag); + } // Avoid setting initial textContent when the text is empty. In IE11 setting // textContent on a