-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Server render fork for react-dom #25436
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/react-dom-server-rendering-stub.production.min.js'); | ||
} else { | ||
module.exports = require('./cjs/react-dom-server-rendering-stub.development.js'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
// Export all exports so that they're available in tests. | ||
// We can't use export * from in Flow for some reason. | ||
|
||
import ReactVersion from 'shared/ReactVersion'; | ||
export {ReactVersion as version}; | ||
|
||
export {default as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} from './src/ReactDOMSharedInternals'; | ||
|
||
export { | ||
createPortal, | ||
flushSync, | ||
} from './src/server/ReactDOMServerRenderingStub'; | ||
export {preinit, preload} from 'react-dom-bindings/src/shared/ReactDOMFloat'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
// Export all exports so that they're available in tests. | ||
// We can't use export * from in Flow for some reason. | ||
|
||
import ReactVersion from 'shared/ReactVersion'; | ||
export {ReactVersion as version}; | ||
|
||
export {default as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} from './src/ReactDOMSharedInternals'; | ||
|
||
export { | ||
createPortal, | ||
flushSync, | ||
} from './src/server/ReactDOMServerRenderingStub'; |
74 changes: 74 additions & 0 deletions
74
packages/react-dom/src/__tests__/react-dom-server-rendering-stub-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
let React; | ||
let ReactDOM; | ||
let ReactDOMFizzServer; | ||
|
||
describe('react-dom-server-rendering-stub', () => { | ||
beforeEach(() => { | ||
jest.mock('react-dom', () => require('react-dom/server-rendering-stub')); | ||
|
||
React = require('react'); | ||
ReactDOM = require('react-dom'); | ||
ReactDOMFizzServer = require('react-dom/server'); | ||
}); | ||
|
||
it('exports a version', () => { | ||
expect(ReactDOM.version).toBeTruthy(); | ||
}); | ||
|
||
it('exports that are expected to be client only in the future are not exported', () => { | ||
expect(ReactDOM.createRoot).toBe(undefined); | ||
expect(ReactDOM.hydrateRoot).toBe(undefined); | ||
expect(ReactDOM.findDOMNode).toBe(undefined); | ||
expect(ReactDOM.hydrate).toBe(undefined); | ||
expect(ReactDOM.render).toBe(undefined); | ||
expect(ReactDOM.unmountComponentAtNode).toBe(undefined); | ||
expect(ReactDOM.unstable_batchedUpdates).toBe(undefined); | ||
expect(ReactDOM.unstable_createEventHandle).toBe(undefined); | ||
expect(ReactDOM.unstable_flushControlled).toBe(undefined); | ||
expect(ReactDOM.unstable_isNewReconciler).toBe(undefined); | ||
expect(ReactDOM.unstable_renderSubtreeIntoContainer).toBe(undefined); | ||
expect(ReactDOM.unstable_runWithPriority).toBe(undefined); | ||
}); | ||
|
||
// @gate enableFloat | ||
it('provides preload and preinit exports', async () => { | ||
function App() { | ||
ReactDOM.preload('foo', {as: 'style'}); | ||
ReactDOM.preinit('bar', {as: 'style'}); | ||
return <div>foo</div>; | ||
} | ||
const html = ReactDOMFizzServer.renderToString(<App />); | ||
expect(html).toEqual( | ||
'<link href="foo" rel="preload" as="style"/><link rel="stylesheet" href="bar" data-rprec="default"/><div>foo</div>', | ||
); | ||
}); | ||
|
||
it('provides a stub for createPortal', async () => { | ||
expect(() => { | ||
ReactDOM.createPortal(); | ||
}).toThrow( | ||
'createPortal was called on the server. Portals are not currently supported on the server. Update your program to conditionally call createPortal on the client only.', | ||
); | ||
}); | ||
|
||
it('provides a stub for flushSync', async () => { | ||
let x = false; | ||
expect(() => { | ||
ReactDOM.flushSync(() => (x = true)); | ||
}).toThrow( | ||
'flushSync was called on the server. This is likely caused by a function being called during render or in module scope that was intended to be called from an effect or event handler. Update your to not call flushSync no the server.', | ||
); | ||
expect(x).toBe(false); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/react-dom/src/server/ReactDOMServerRenderingStub.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
export function createPortal() { | ||
throw new Error( | ||
'createPortal was called on the server. Portals are not currently' + | ||
' supported on the server. Update your program to conditionally call' + | ||
' createPortal on the client only.', | ||
); | ||
} | ||
|
||
export function flushSync() { | ||
throw new Error( | ||
'flushSync was called on the server. This is likely caused by a' + | ||
' function being called during render or in module scope that was' + | ||
' intended to be called from an effect or event handler. Update your' + | ||
' to not call flushSync no the server.', | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we remove the legacy stuff from
react-dom/index
we'll still have a few exports remaining.While you shouldn't call these functions, they would still exist as exports but not do anything. Maybe we can add empty stubs that warn if you call them.
version
should probably just work.