From 5f9e4ff198f73a856bdfb79731663e1465d01353 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Mon, 6 Feb 2023 12:07:19 +0100 Subject: [PATCH] attribute-fixture: Render valid meta tags --- .../attribute-behavior/AttributeTableSnapshot.md | 8 ++++---- fixtures/attribute-behavior/src/App.js | 8 ++++++++ fixtures/attribute-behavior/src/attributes.js | 16 +++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/fixtures/attribute-behavior/AttributeTableSnapshot.md b/fixtures/attribute-behavior/AttributeTableSnapshot.md index c4cc94f8d9ac9..ee01bc2a0d679 100644 --- a/fixtures/attribute-behavior/AttributeTableSnapshot.md +++ b/fixtures/attribute-behavior/AttributeTableSnapshot.md @@ -1,4 +1,4 @@ -## `about` (on `
` inside `
`) +## `about` (on `
` inside `
`) | Test Case | Flags | Result | | --- | --- | --- | | `about=(string)`| (changed)| `"a string"` | @@ -1998,7 +1998,7 @@ | `colSpan=(null)`| (initial, ssr error, ssr mismatch)| `` | | `colSpan=(undefined)`| (initial, ssr error, ssr mismatch)| `` | -## `content` (on `` inside `
`) +## `content` (on `` inside ``) | Test Case | Flags | Result | | --- | --- | --- | | `content=(string)`| (changed)| `"a string"` | @@ -5123,7 +5123,7 @@ | `htmlFor=(null)`| (initial)| `` | | `htmlFor=(undefined)`| (initial)| `` | -## `http-equiv` (on `` inside `
`) +## `http-equiv` (on `` inside ``) | Test Case | Flags | Result | | --- | --- | --- | | `http-equiv=(string)`| (changed, warning)| `"a string"` | @@ -5148,7 +5148,7 @@ | `http-equiv=(null)`| (initial, warning)| `` | | `http-equiv=(undefined)`| (initial, warning)| `` | -## `httpEquiv` (on `` inside `
`) +## `httpEquiv` (on `` inside ``) | Test Case | Flags | Result | | --- | --- | --- | | `httpEquiv=(string)`| (changed)| `"a string"` | diff --git a/fixtures/attribute-behavior/src/App.js b/fixtures/attribute-behavior/src/App.js index 98194f76c79c7..5f1bac46e4887 100644 --- a/fixtures/attribute-behavior/src/App.js +++ b/fixtures/attribute-behavior/src/App.js @@ -237,6 +237,8 @@ function getRenderedAttributeValue( return document.createElementNS('http://www.w3.org/2000/svg', 'svg'); } else if (containerTagName === 'document') { return document.implementation.createHTMLDocument(''); + } else if (containerTagName === 'head') { + return document.implementation.createHTMLDocument('').head; } else { return document.createElement(containerTagName); } @@ -308,6 +310,12 @@ function getRenderedAttributeValue( ); container = createContainer(); container.innerHTML = html; + } else if (containerTagName === 'head') { + const html = serverRenderer.renderToString( + react.createElement(tagName, props) + ); + container = createContainer(); + container.innerHTML = html; } else { const html = serverRenderer.renderToString( react.createElement( diff --git a/fixtures/attribute-behavior/src/attributes.js b/fixtures/attribute-behavior/src/attributes.js index c0e5a133f1dce..3f90bfa9409d8 100644 --- a/fixtures/attribute-behavior/src/attributes.js +++ b/fixtures/attribute-behavior/src/attributes.js @@ -356,7 +356,12 @@ const attributes = [ }, {name: 'cols', tagName: 'textarea'}, {name: 'colSpan', containerTagName: 'tr', tagName: 'td'}, - {name: 'content', tagName: 'meta'}, + { + name: 'content', + containerTagName: 'head', + tagName: 'meta', + extraProps: {name: 'description'}, + }, {name: 'contentEditable'}, { name: 'contentScriptType', @@ -934,8 +939,13 @@ const attributes = [ {name: 'href', tagName: 'a', overrideStringValue: 'https://reactjs.com'}, {name: 'hrefLang', read: getAttribute('hreflang')}, {name: 'htmlFor', tagName: 'label'}, - {name: 'http-equiv', tagName: 'meta', read: getProperty('httpEquiv')}, - {name: 'httpEquiv', tagName: 'meta'}, + { + name: 'http-equiv', + containerTagName: 'head', + tagName: 'meta', + read: getProperty('httpEquiv'), + }, + {name: 'httpEquiv', containerTagName: 'head', tagName: 'meta'}, {name: 'icon', tagName: 'command', read: getAttribute('icon')}, {name: 'id'}, {name: 'ID', read: getProperty('id')},