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.
-->
This commit is contained in:
Jiachi Liu 2023-02-28 23:27:16 +01:00 committed by GitHub
parent b2ae9ddb3b
commit 38509cce9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -18,6 +18,8 @@ export {default as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} from './s
export {
createPortal,
flushSync,
prefetchDNS,
preconnect,
preload,
preinit,
} from './src/server/ReactDOMServerRenderingStub';

View File

@ -53,6 +53,18 @@ describe('react-dom-server-rendering-stub', () => {
);
});
it('provides preconnect and prefetchDNS exports', async () => {
function App() {
ReactDOM.preconnect('foo', {crossOrigin: 'use-credentials'});
ReactDOM.prefetchDNS('bar');
return <div>foo</div>;
}
const html = ReactDOMFizzServer.renderToString(<App />);
expect(html).toEqual(
'<link rel="preconnect" href="foo" crossorigin="use-credentials"/><link href="bar" rel="dns-prefetch"/><div>foo</div>',
);
});
it('provides a stub for createPortal', async () => {
expect(() => {
ReactDOM.createPortal();

View File

@ -7,7 +7,12 @@
* @flow
*/
export {preinit, preload} from 'react-dom-bindings/src/shared/ReactDOMFloat';
export {
preinit,
preload,
preconnect,
prefetchDNS,
} from 'react-dom-bindings/src/shared/ReactDOMFloat';
export function createPortal() {
throw new Error(