Skip to content

Commit 0983ea8

Browse files
committed
Pre tags innerHTML needs to be prefixed
This is because if you do the equivalent on the client using innerHTML, this is the effect you'd get.
1 parent 4d67fd4 commit 0983ea8

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,15 +1100,39 @@ function pushStartPreformattedElement(
11001100
responseState: ResponseState,
11011101
assignID: null | SuspenseBoundaryID,
11021102
): ReactNodeList {
1103-
const children = pushStartGenericElement(
1104-
target,
1105-
props,
1106-
tag,
1107-
responseState,
1108-
assignID,
1109-
);
1103+
target.push(startChunkForTag(tag));
1104+
1105+
let children = null;
1106+
let innerHTML = null;
1107+
for (const propKey in props) {
1108+
if (hasOwnProperty.call(props, propKey)) {
1109+
const propValue = props[propKey];
1110+
if (propValue == null) {
1111+
continue;
1112+
}
1113+
switch (propKey) {
1114+
case 'children':
1115+
children = propValue;
1116+
break;
1117+
case 'dangerouslySetInnerHTML':
1118+
innerHTML = propValue;
1119+
break;
1120+
default:
1121+
pushAttribute(target, responseState, propKey, propValue);
1122+
break;
1123+
}
1124+
}
1125+
}
1126+
if (assignID !== null) {
1127+
pushID(target, responseState, assignID, props.id);
1128+
}
1129+
1130+
target.push(endOfStartTag);
11101131

1111-
if (typeof children === 'string' && children[0] === '\n') {
1132+
if (
1133+
(typeof children === 'string' && children[0] === '\n') ||
1134+
(typeof innerHTML === 'string' && innerHTML[0] === '\n')
1135+
) {
11121136
// text/html ignores the first character in these tags if it's a newline
11131137
// Prefer to break application/xml over text/html (for now) by adding
11141138
// a newline specifically to get eaten by the parser. (Alternately for
@@ -1124,6 +1148,7 @@ function pushStartPreformattedElement(
11241148
target.push(leadingNewline);
11251149
}
11261150

1151+
pushInnerHTML(target, innerHTML, children);
11271152
return children;
11281153
}
11291154

0 commit comments

Comments
 (0)