-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Flight] Move around the Server side a bit (#17251)
* Rename ReactFlightStreamer -> ReactFlightServer * Unify Browser/Node stream tests into one file and use the client reader * Defer to the actual ReactDOM for HTML rendering for now This will need to use a variant of Fizz to do inline SSR in Flight. However, I don't want to build the whole impl right now but also don't want to exclude the use case yet. So I outsource it to the existing renderer. Ofc, this doesn't work with Suspense atm.
- Loading branch information
1 parent
fadc971
commit f4148b2
Showing
15 changed files
with
154 additions
and
114 deletions.
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
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,92 @@ | ||
/** | ||
* 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 | ||
* @jest-environment node | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// Polyfills for test environment | ||
global.ReadableStream = require('@mattiasbuelens/web-streams-polyfill/ponyfill/es6').ReadableStream; | ||
global.TextDecoder = require('util').TextDecoder; | ||
|
||
let Stream; | ||
let React; | ||
let ReactFlightDOMServer; | ||
let ReactFlightDOMClient; | ||
|
||
describe('ReactFlightDOM', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
Stream = require('stream'); | ||
React = require('react'); | ||
ReactFlightDOMServer = require('react-dom/unstable-flight-server'); | ||
ReactFlightDOMClient = require('react-dom/unstable-flight-client'); | ||
}); | ||
|
||
function getTestStream() { | ||
let writable = new Stream.PassThrough(); | ||
let readable = new ReadableStream({ | ||
start(controller) { | ||
writable.on('data', chunk => { | ||
controller.enqueue(chunk); | ||
}); | ||
writable.on('end', () => { | ||
controller.close(); | ||
}); | ||
}, | ||
}); | ||
return { | ||
writable, | ||
readable, | ||
}; | ||
} | ||
|
||
async function waitForSuspense(fn) { | ||
while (true) { | ||
try { | ||
return fn(); | ||
} catch (promise) { | ||
if (typeof promise.then === 'function') { | ||
await promise; | ||
} else { | ||
throw promise; | ||
} | ||
} | ||
} | ||
} | ||
|
||
it('should resolve HTML using Node streams', async () => { | ||
function Text({children}) { | ||
return <span>{children}</span>; | ||
} | ||
function HTML() { | ||
return ( | ||
<div> | ||
<Text>hello</Text> | ||
<Text>world</Text> | ||
</div> | ||
); | ||
} | ||
|
||
function App() { | ||
let model = { | ||
html: <HTML />, | ||
}; | ||
return model; | ||
} | ||
|
||
let {writable, readable} = getTestStream(); | ||
ReactFlightDOMServer.pipeToNodeWritable(<App />, writable); | ||
let result = ReactFlightDOMClient.readFromReadableStream(readable); | ||
await waitForSuspense(() => { | ||
expect(result.model).toEqual({ | ||
html: '<div><span>hello</span><span>world</span></div>', | ||
}); | ||
}); | ||
}); | ||
}); |
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
57 changes: 0 additions & 57 deletions
57
packages/react-dom/src/__tests__/ReactFlightDOMNode-test.js
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.