GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Convert ReactServerRenderingHydration-test to createRoot (partially) … · react/react@f161cea

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/react-dom/src/__tests__
    • ReactServerRenderingHydration-test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js‎

Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js
+15-6Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe('ReactDOMServerHydration', () => {
122122
// We have a polyfill for autoFocus on the client, but we intentionally don't
123123
// want it to call focus() when hydrating because this can mess up existing
124124
// focus before the JS has loaded.
125-
it('should emit autofocus on the server but not focus() when hydrating', () => {
125+
it('should emit autofocus on the server but not focus() when hydrating', async () => {
126126
const element = document.createElement('div');
127127
element.innerHTML = ReactDOMServer.renderToString(
128128
<input autoFocus={true} />,
@@ -131,26 +131,35 @@ describe('ReactDOMServerHydration', () => {
131131

132132
// It should not be called on mount.
133133
element.firstChild.focus = jest.fn();
134-
ReactDOM.hydrate(<input autoFocus={true} />, element);
134+
const root = await act(() =>
135+
ReactDOMClient.hydrateRoot(element, <input autoFocus={true} />),
136+
);
135137
expect(element.firstChild.focus).not.toHaveBeenCalled();
136138

137139
// Or during an update.
138-
ReactDOM.render(<input autoFocus={true} />, element);
140+
await act(() => {
141+
root.render(<input autoFocus={true} />);
142+
});
139143
expect(element.firstChild.focus).not.toHaveBeenCalled();
140144
});
141145

142-
it('should not focus on either server or client with autofocus={false}', () => {
146+
it('should not focus on either server or client with autofocus={false}', async () => {
143147
const element = document.createElement('div');
144148
element.innerHTML = ReactDOMServer.renderToString(
145149
<input autoFocus={false} />,
146150
);
147151
expect(element.firstChild.autofocus).toBe(false);
148152

149153
element.firstChild.focus = jest.fn();
150-
ReactDOM.hydrate(<input autoFocus={false} />, element);
154+
const root = await act(() =>
155+
ReactDOMClient.hydrateRoot(element, <input autoFocus={false} />),
156+
);
157+
151158
expect(element.firstChild.focus).not.toHaveBeenCalled();
152159

153-
ReactDOM.render(<input autoFocus={false} />, element);
160+
await act(() => {
161+
root.render(<input autoFocus={false} />);
162+
});
154163
expect(element.firstChild.focus).not.toHaveBeenCalled();
155164
});
156165

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.