Skip to content

Commit 38509cc

Browse files
authored
Add preconnect and prefetchDNS to rendering-stub (#26265)
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The three fields below are mandatory. Before submitting a pull request, please make sure the following is done: 1. Fork [the repository](https://github.com/facebook/react) and create your branch from `main`. 2. Run `yarn` in the repository root. 3. If you've fixed a bug or added code that should be tested, add tests! 4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development. 5. Run `yarn test --prod` to test in the production environment. It supports the same options as `yarn test`. 6. If you need a debugger, run `yarn test --debug --watch TestName`, open `chrome://inspect`, and press "Inspect". 7. Format your code with [prettier](https://github.com/prettier/prettier) (`yarn prettier`). 8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files. 9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`). 10. If you haven't already, complete the CLA. Learn more about contributing: https://reactjs.org/docs/how-to-contribute.html --> ## Summary Adding `preconnect` and `prefetchDNS` to rendering-stub build <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> ## How did you test this change? <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. How exactly did you verify that your PR solves the issue you wanted to solve? If you leave this empty, your PR will very likely be closed. -->
1 parent b2ae9dd commit 38509cc

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

packages/react-dom/server-rendering-stub.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export {default as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} from './s
1818
export {
1919
createPortal,
2020
flushSync,
21+
prefetchDNS,
22+
preconnect,
2123
preload,
2224
preinit,
2325
} from './src/server/ReactDOMServerRenderingStub';

packages/react-dom/src/__tests__/react-dom-server-rendering-stub-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ describe('react-dom-server-rendering-stub', () => {
5353
);
5454
});
5555

56+
it('provides preconnect and prefetchDNS exports', async () => {
57+
function App() {
58+
ReactDOM.preconnect('foo', {crossOrigin: 'use-credentials'});
59+
ReactDOM.prefetchDNS('bar');
60+
return <div>foo</div>;
61+
}
62+
const html = ReactDOMFizzServer.renderToString(<App />);
63+
expect(html).toEqual(
64+
'<link rel="preconnect" href="foo" crossorigin="use-credentials"/><link href="bar" rel="dns-prefetch"/><div>foo</div>',
65+
);
66+
});
67+
5668
it('provides a stub for createPortal', async () => {
5769
expect(() => {
5870
ReactDOM.createPortal();

packages/react-dom/src/server/ReactDOMServerRenderingStub.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
* @flow
88
*/
99

10-
export {preinit, preload} from 'react-dom-bindings/src/shared/ReactDOMFloat';
10+
export {
11+
preinit,
12+
preload,
13+
preconnect,
14+
prefetchDNS,
15+
} from 'react-dom-bindings/src/shared/ReactDOMFloat';
1116

1217
export function createPortal() {
1318
throw new Error(

0 commit comments

Comments
 (0)