Skip to content

Commit

Permalink
Add preconnect and prefetchDNS to rendering-stub (#26265)
Browse files Browse the repository at this point in the history
<!--
  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.
-->
  • Loading branch information
huozhi committed Feb 28, 2023
1 parent b2ae9dd commit 38509cc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/react-dom/server-rendering-stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion packages/react-dom/src/server/ReactDOMServerRenderingStub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 38509cc

Please sign in to comment.