Skip to content

Commit 7f22980

Browse files
committed
toString children of title
1 parent 13681aa commit 7f22980

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

packages/react-dom-bindings/src/client/ReactDOMFloatClient.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -587,17 +587,27 @@ export function getResource(
587587
return null;
588588
}
589589
case 'title': {
590-
let child = pendingProps.children;
591-
if (Array.isArray(child) && child.length === 1) {
592-
child = child[0];
590+
const children = pendingProps.children;
591+
let child;
592+
if (Array.isArray(children) && children.length === 1) {
593+
child = children[0];
594+
} else {
595+
child = children;
593596
}
594-
if (typeof child === 'string' || typeof child === 'number') {
597+
if (
598+
typeof child !== 'function' &&
599+
typeof child !== 'symbol' &&
600+
child !== null &&
601+
child !== undefined
602+
) {
603+
// eslint-disable-next-line react-internal/safe-string-coercion
604+
const childString = '' + (child: any);
595605
const headRoot: Document = getDocumentFromRoot(resourceRoot);
596606
const headResources = getResourcesFromRoot(headRoot).head;
597-
const key = getTitleKey(child);
607+
const key = getTitleKey(childString);
598608
let resource = headResources.get(key);
599609
if (!resource) {
600-
const titleProps = titlePropsFromRawProps(child, pendingProps);
610+
const titleProps = titlePropsFromRawProps(childString, pendingProps);
601611
resource = {
602612
type: 'title',
603613
props: titleProps,

packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,8 +1463,14 @@ function pushTitleImpl(
14631463
Array.isArray(children) && children.length < 2
14641464
? children[0] || null
14651465
: children;
1466-
if (typeof child === 'string' || typeof child === 'number') {
1467-
target.push(stringToChunk(escapeTextForBrowser(child)));
1466+
if (
1467+
typeof child !== 'function' &&
1468+
typeof child !== 'symbol' &&
1469+
child !== null &&
1470+
child !== undefined
1471+
) {
1472+
// eslint-disable-next-line react-internal/safe-string-coercion
1473+
target.push(stringToChunk(escapeTextForBrowser('' + child)));
14681474
}
14691475
target.push(endTag1, stringToChunk('title'), endTag2);
14701476
return null;

0 commit comments

Comments
 (0)