Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and update attribute-behavior fixture #26114

Merged
merged 6 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 44 additions & 19 deletions fixtures/attribute-behavior/AttributeTableSnapshot.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## `about` (on `<div>` inside `<div>`)
## `about` (on `<div>` inside `<div>`)
| Test Case | Flags | Result |
| --- | --- | --- |
| `about=(string)`| (changed)| `"a string"` |
Expand Down Expand Up @@ -1998,7 +1998,7 @@
| `colSpan=(null)`| (initial, ssr error, ssr mismatch)| `<number: 1>` |
| `colSpan=(undefined)`| (initial, ssr error, ssr mismatch)| `<number: 1>` |

## `content` (on `<meta>` inside `<div>`)
## `content` (on `<meta>` inside `<head>`)
| Test Case | Flags | Result |
| --- | --- | --- |
| `content=(string)`| (changed)| `"a string"` |
Expand Down Expand Up @@ -5123,7 +5123,7 @@
| `htmlFor=(null)`| (initial)| `<empty string>` |
| `htmlFor=(undefined)`| (initial)| `<empty string>` |

## `http-equiv` (on `<meta>` inside `<div>`)
## `http-equiv` (on `<meta>` inside `<head>`)
| Test Case | Flags | Result |
| --- | --- | --- |
| `http-equiv=(string)`| (changed, warning)| `"a string"` |
Expand All @@ -5148,7 +5148,7 @@
| `http-equiv=(null)`| (initial, warning)| `<empty string>` |
| `http-equiv=(undefined)`| (initial, warning)| `<empty string>` |

## `httpEquiv` (on `<meta>` inside `<div>`)
## `httpEquiv` (on `<meta>` inside `<head>`)
| Test Case | Flags | Result |
| --- | --- | --- |
| `httpEquiv=(string)`| (changed)| `"a string"` |
Expand Down Expand Up @@ -6198,6 +6198,31 @@
| `lang=(null)`| (initial)| `<empty string>` |
| `lang=(undefined)`| (initial)| `<empty string>` |

## `lang` (on `<html>` inside `<document>`)
| Test Case | Flags | Result |
| --- | --- | --- |
| `lang=(string)`| (changed, ssr mismatch)| `"a string"` |
| `lang=(empty string)`| (initial)| `<empty string>` |
| `lang=(array with string)`| (changed, ssr mismatch)| `"string"` |
| `lang=(empty array)`| (initial)| `<empty string>` |
| `lang=(object)`| (changed, ssr mismatch)| `"result of toString()"` |
| `lang=(numeric string)`| (changed, ssr mismatch)| `"42"` |
| `lang=(-1)`| (changed, ssr mismatch)| `"-1"` |
| `lang=(0)`| (changed, ssr mismatch)| `"0"` |
| `lang=(integer)`| (changed, ssr mismatch)| `"1"` |
| `lang=(NaN)`| (changed, warning, ssr mismatch)| `"NaN"` |
| `lang=(float)`| (changed, ssr mismatch)| `"99.99"` |
| `lang=(true)`| (initial, warning)| `<empty string>` |
| `lang=(false)`| (initial, warning)| `<empty string>` |
| `lang=(string 'true')`| (changed, ssr mismatch)| `"true"` |
| `lang=(string 'false')`| (changed, ssr mismatch)| `"false"` |
| `lang=(string 'on')`| (changed, ssr mismatch)| `"on"` |
| `lang=(string 'off')`| (changed, ssr mismatch)| `"off"` |
| `lang=(symbol)`| (initial, warning)| `<empty string>` |
| `lang=(function)`| (initial, warning)| `<empty string>` |
| `lang=(null)`| (initial)| `<empty string>` |
| `lang=(undefined)`| (initial)| `<empty string>` |

## `length` (on `<div>` inside `<div>`)
| Test Case | Flags | Result |
| --- | --- | --- |
Expand Down Expand Up @@ -12526,23 +12551,23 @@
## `viewTarget` (on `<view>` inside `<svg>`)
| Test Case | Flags | Result |
| --- | --- | --- |
| `viewTarget=(string)`| (changed, ssr mismatch)| `"a string"` |
| `viewTarget=(empty string)`| (changed, ssr mismatch)| `<empty string>` |
| `viewTarget=(array with string)`| (changed, ssr mismatch)| `"string"` |
| `viewTarget=(empty array)`| (changed, ssr mismatch)| `<empty string>` |
| `viewTarget=(object)`| (changed, ssr mismatch)| `"result of toString()"` |
| `viewTarget=(numeric string)`| (changed, ssr mismatch)| `"42"` |
| `viewTarget=(-1)`| (changed, ssr mismatch)| `"-1"` |
| `viewTarget=(0)`| (changed, ssr mismatch)| `"0"` |
| `viewTarget=(integer)`| (changed, ssr mismatch)| `"1"` |
| `viewTarget=(NaN)`| (changed, warning, ssr mismatch)| `"NaN"` |
| `viewTarget=(float)`| (changed, ssr mismatch)| `"99.99"` |
| `viewTarget=(string)`| (changed)| `"a string"` |
| `viewTarget=(empty string)`| (changed)| `<empty string>` |
| `viewTarget=(array with string)`| (changed)| `"string"` |
| `viewTarget=(empty array)`| (changed)| `<empty string>` |
| `viewTarget=(object)`| (changed)| `"result of toString()"` |
| `viewTarget=(numeric string)`| (changed)| `"42"` |
| `viewTarget=(-1)`| (changed)| `"-1"` |
| `viewTarget=(0)`| (changed)| `"0"` |
| `viewTarget=(integer)`| (changed)| `"1"` |
| `viewTarget=(NaN)`| (changed, warning)| `"NaN"` |
| `viewTarget=(float)`| (changed)| `"99.99"` |
| `viewTarget=(true)`| (initial, warning)| `<null>` |
| `viewTarget=(false)`| (initial, warning)| `<null>` |
| `viewTarget=(string 'true')`| (changed, ssr mismatch)| `"true"` |
| `viewTarget=(string 'false')`| (changed, ssr mismatch)| `"false"` |
| `viewTarget=(string 'on')`| (changed, ssr mismatch)| `"on"` |
| `viewTarget=(string 'off')`| (changed, ssr mismatch)| `"off"` |
| `viewTarget=(string 'true')`| (changed)| `"true"` |
| `viewTarget=(string 'false')`| (changed)| `"false"` |
| `viewTarget=(string 'on')`| (changed)| `"on"` |
| `viewTarget=(string 'off')`| (changed)| `"off"` |
| `viewTarget=(symbol)`| (initial, warning)| `<null>` |
| `viewTarget=(function)`| (initial, warning)| `<null>` |
| `viewTarget=(null)`| (initial)| `<null>` |
Expand Down
14 changes: 11 additions & 3 deletions fixtures/attribute-behavior/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -282,12 +284,12 @@ function getRenderedAttributeValue(
try {
let container = createContainer();
renderer.render(react.createElement(tagName, baseProps), container);
defaultValue = read(container.firstChild);
defaultValue = read(container.lastChild);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent with how we read the value of server-rendered markup. firstChild returns the DOCTYPE now if we render into a document on the client.

canonicalDefaultValue = getCanonicalizedValue(defaultValue);

container = createContainer();
renderer.render(react.createElement(tagName, props), container);
result = read(container.firstChild);
result = read(container.lastChild);
canonicalResult = getCanonicalizedValue(result);
didWarn = _didWarn;
didError = false;
Expand All @@ -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(
Expand Down Expand Up @@ -764,7 +772,7 @@ class App extends React.Component {
ReactDOMStable:
'https://unpkg.com/react-dom@latest/umd/react-dom.development.js',
ReactDOMServerStable:
'https://unpkg.com/react-dom@latest/umd/react-dom-server.browser.development.js',
'https://unpkg.com/react-dom@latest/umd/react-dom-server-legacy.browser.development.js',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What caused this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renderToString is no longer included in react-dom-server.browser. Makes sense considering renderToString is considered legacy. renderToString was already excluded from the 18.0.0 UMD bundle so there was no change to the UMD bundle in a SemVer minor.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh odd, I thought that was already the case. sounds good

ReactNext: '/react.development.js',
ReactDOMNext: '/react-dom.development.js',
ReactDOMServerNext: '/react-dom-server-legacy.browser.development.js',
Expand Down
12 changes: 9 additions & 3 deletions fixtures/attribute-behavior/src/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ const attributes = [
},
{name: 'cols', tagName: 'textarea'},
{name: 'colSpan', containerTagName: 'tr', tagName: 'td'},
{name: 'content', tagName: 'meta'},
{name: 'content', containerTagName: 'head', tagName: 'meta'},
{name: 'contentEditable'},
{
name: 'contentScriptType',
Expand Down Expand Up @@ -934,8 +934,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')},
Expand Down Expand Up @@ -1076,6 +1081,7 @@ const attributes = [
{name: 'label', tagName: 'track'},
{name: 'LANG', read: getProperty('lang')},
{name: 'lang'},
{name: 'lang', containerTagName: 'document', tagName: 'html'},
{name: 'length', read: getAttribute('length')},
{
name: 'lengthAdjust',
Expand Down