From 66dc44e7760d0f75b6845b7fa71f2f1e4e5f20d3 Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Wed, 19 Apr 2023 19:45:35 -0400 Subject: [PATCH] Fix logic around attribute seralization (#26526) This reverts commit ea499ef92869240c02ca2888ed6f4e9a866adfad. --- .../src/server/ReactDOMServerFormatConfig.js | 84 ++++++++++--------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js b/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js index 4168b40cb7afc..60d53197bd44a 100644 --- a/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js +++ b/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js @@ -3926,48 +3926,51 @@ 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': { + value = sanitizeURL(value); if (__DEV__) { checkAttributeStringCoercion(value, attributeName); } - value = sanitizeURL(value); + attributeValue = '' + (value: any); break; } default: { + if ( + // 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') + ) { + 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, @@ -4119,48 +4122,53 @@ 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': case 'href': { + value = sanitizeURL(value); if (__DEV__) { checkAttributeStringCoercion(value, attributeName); } - value = sanitizeURL(value); + attributeValue = '' + (value: any); break; } default: { + if ( + // 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') + ) { + 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,