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

Simplify default Node server entry #11619

Merged
merged 4 commits into from
Jul 1, 2024

Conversation

markdalgleish
Copy link
Member

This refactor is based on the example from the official React docs: https://react.dev/reference/react-dom/server/renderToPipeableStream#waiting-for-all-content-to-load-for-crawlers-and-static-generation.

I've also been able to simplify usage of isbot since we can use this major release to prompt anyone using v3 to upgrade to v4.

Copy link

changeset-bot bot commented Jun 6, 2024

⚠️ No Changeset found

Latest commit: 692d703

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

const body = new PassThrough();
const stream = createReadableStreamFromReadable(body);
onAllReady() {
if (prohibitOutOfOrderStreaming) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

mhmm - I'd personally vote for something like this to DRY it up a tiny bit if the two paths are identical (and have been for sometime?), but not a refactor I'd fight super hard for :)

let readyOption =
  (userAgent && isbot(userAgent)) || remixContext.isSpaMode
    ? "onAllReady"
    : "onShellReady";

...

    const { pipe, abort } = renderToPipeableStream(
      <RemixServer
        context={remixContext}
        url={request.url}
        abortDelay={ABORT_DELAY}
      />,
      {
        [readyOption]() {
          shellRendered = true;
          ...
        }

Copy link
Member Author

Choose a reason for hiding this comment

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

I like the way you cleaned this up. I've also refactored it so that the readyOption var is defined as close to its usage as possible so it's a bit clearer what's going on, and also added a type annotation to ensure it's a valid option name.

Copy link
Contributor

@brophdawg11 brophdawg11 left a comment

Choose a reason for hiding this comment

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

😍

@markdalgleish markdalgleish merged commit dbf2e3d into v7 Jul 1, 2024
8 checks passed
@markdalgleish markdalgleish deleted the markdalgleish/simplify-node-server-entry branch July 1, 2024 22:16
markdalgleish added a commit that referenced this pull request Jul 1, 2024
@brophdawg11 brophdawg11 mentioned this pull request Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants