From f7304696a1a33c8d482d072de6cb4f20e192e449 Mon Sep 17 00:00:00 2001 From: Josh Story Date: Thu, 30 Mar 2023 20:27:36 -0700 Subject: [PATCH 1/2] fix logic around attribute seralization --- .../src/server/ReactDOMServerFormatConfig.js | 70 ++++++++++--------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js b/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js index 4168b40cb7afc..2dd5e5ba1c311 100644 --- a/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js +++ b/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js @@ -3928,6 +3928,10 @@ function writeStyleResourceAttributeInJS( // Attribute renames case 'className': attributeName = 'class'; + if (__DEV__) { + checkAttributeStringCoercion(value, attributeName); + } + attributeValue = '' + (value: any); break; // Booleans @@ -3941,33 +3945,32 @@ function writeStyleResourceAttributeInJS( // Santized URLs case 'src': case 'href': { + value = sanitizeURL(value); if (__DEV__) { checkAttributeStringCoercion(value, attributeName); } - value = sanitizeURL(value); + attributeValue = '' + (value: any); break; } default: { + if ( + // shouldIgnoreAttribute + // We have already filtered out null/undefined and reserved words. + name.length > 2 && + (name[0] === 'o' || name[0] === 'O') && + (name[1] === 'n' || name[1] === 'N') + ) { + return; + } if (!isAttributeNameSafe(name)) { return; } + if (__DEV__) { + checkAttributeStringCoercion(value, attributeName); + } + attributeValue = '' + (value: any); } } - - if ( - // shouldIgnoreAttribute - // We have already filtered out null/undefined and reserved words. - name.length > 2 && - (name[0] === 'o' || name[0] === 'O') && - (name[1] === 'n' || name[1] === 'N') - ) { - return; - } - - if (__DEV__) { - checkAttributeStringCoercion(value, attributeName); - } - attributeValue = '' + (value: any); writeChunk(destination, arrayInterstitial); writeChunk( destination, @@ -4121,6 +4124,10 @@ function writeStyleResourceAttributeInAttr( // Attribute renames case 'className': attributeName = 'class'; + if (__DEV__) { + checkAttributeStringCoercion(value, attributeName); + } + attributeValue = '' + (value: any); break; // Booleans @@ -4134,33 +4141,32 @@ function writeStyleResourceAttributeInAttr( // Santized URLs case 'src': case 'href': { + value = sanitizeURL(value); if (__DEV__) { checkAttributeStringCoercion(value, attributeName); } - value = sanitizeURL(value); + attributeValue = '' + (value: any); break; } default: { + if ( + // shouldIgnoreAttribute + // We have already filtered out null/undefined and reserved words. + name.length > 2 && + (name[0] === 'o' || name[0] === 'O') && + (name[1] === 'n' || name[1] === 'N') + ) { + return; + } if (!isAttributeNameSafe(name)) { return; } + if (__DEV__) { + checkAttributeStringCoercion(value, attributeName); + } + attributeValue = '' + (value: any); } } - - if ( - // shouldIgnoreAttribute - // We have already filtered out null/undefined and reserved words. - name.length > 2 && - (name[0] === 'o' || name[0] === 'O') && - (name[1] === 'n' || name[1] === 'N') - ) { - return; - } - - if (__DEV__) { - checkAttributeStringCoercion(value, attributeName); - } - attributeValue = '' + (value: any); writeChunk(destination, arrayInterstitial); writeChunk( destination, From f3b9f31783328ee85cd3739e206b559835c7e09f Mon Sep 17 00:00:00 2001 From: Josh Story Date: Thu, 30 Mar 2023 20:41:32 -0700 Subject: [PATCH 2/2] cleanup --- .../src/server/ReactDOMServerFormatConfig.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js b/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js index 2dd5e5ba1c311..60d53197bd44a 100644 --- a/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js +++ b/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js @@ -3926,22 +3926,22 @@ function writeStyleResourceAttributeInJS( return; // Attribute renames - case 'className': + case 'className': { attributeName = 'class'; if (__DEV__) { checkAttributeStringCoercion(value, attributeName); } attributeValue = '' + (value: any); break; - + } // Booleans - case 'hidden': + case 'hidden': { if (value === false) { return; } attributeValue = ''; break; - + } // Santized URLs case 'src': case 'href': { @@ -3954,8 +3954,8 @@ function writeStyleResourceAttributeInJS( } default: { if ( - // shouldIgnoreAttribute - // We have already filtered out null/undefined and reserved words. + // unrecognized event handlers are not SSR'd and we (apparently) + // use on* as hueristic for these handler props name.length > 2 && (name[0] === 'o' || name[0] === 'O') && (name[1] === 'n' || name[1] === 'N') @@ -4122,21 +4122,23 @@ function writeStyleResourceAttributeInAttr( return; // Attribute renames - case 'className': + case 'className': { attributeName = 'class'; if (__DEV__) { checkAttributeStringCoercion(value, attributeName); } attributeValue = '' + (value: any); break; + } // Booleans - case 'hidden': + case 'hidden': { if (value === false) { return; } attributeValue = ''; break; + } // Santized URLs case 'src': @@ -4150,8 +4152,8 @@ function writeStyleResourceAttributeInAttr( } default: { if ( - // shouldIgnoreAttribute - // We have already filtered out null/undefined and reserved words. + // unrecognized event handlers are not SSR'd and we (apparently) + // use on* as hueristic for these handler props name.length > 2 && (name[0] === 'o' || name[0] === 'O') && (name[1] === 'n' || name[1] === 'N')