Skip to content
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

Use renderToPipeableStream wired up to a ReadableStream to add streaming support #2

Closed
wants to merge 2 commits into from

Conversation

maxshirshin
Copy link

This is a first MVP that uses renderToPipeableStream wired up to a ReadableStream instance.

Unlike directly using renderToReadableStream, this still streams (the throbber rotates on the page) but doesn't throw a stream close error and doesn't break HTML markup.

src/delays.js Outdated Show resolved Hide resolved
Comment on lines +20 to +21
// We have this in Oxygen and can expose it
globalThis.Buffer = globalThis.Buffer || {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, perhaps we could get react to not depend on it. If not, another approach would be to have hydrogen polyfill it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have Buffer in Oxygen, because it was a dependency of some other polyfill, it's just not exposed. So we can expose it and it will work.

@@ -3,8 +3,7 @@ import { DataProvider } from "./data";
import { ABORT_DELAY, API_DELAY } from "./delays";
import {
renderToPipeableStream,
renderToReadableStream,
} from "react-dom/server";
} from "react-dom/cjs/react-dom-server.node.development";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is using node specific code. Actually, that looks like that was already the case with renderToPipeableStream.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to provide a very specific path because we set the target to webworker, and so yarn imports browser-specific stuff but we need the node implementation.

As for the node-specific code, it only uses setImmediate and Buffer.from so far, we have Buffer and setImmediate is easy to polyfill (or can be implemented natively in Oxygen). The renderToReadableStream implementation didn't use any specific node stuff but it sits in react-dom-server.browser.development.js which suggests it might be eventually using browser-specific APIs. React doesn't target workers as a platform yet, but if we get React streaming to production quality in Oxygen, this can change.

Co-authored-by: Dylan Thacker-Smith <dylan.smith@shopify.com>
@jplhomer
Copy link
Owner

This has since been fixed upstream in React facebook/react#23342

@jplhomer jplhomer closed this Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants