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

Remove conditional require()s from SSR #9975

Merged

Conversation

MrDoomBringer
Copy link
Contributor

@MrDoomBringer MrDoomBringer commented Aug 2, 2022

Gets rid of some conditional require()s from getDataFromTree and renderToStringWithData, which won't get bundled properly by webpack.

Checklist:

See #9952 for more information

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

@MrDoomBringer MrDoomBringer self-assigned this Aug 2, 2022
@MrDoomBringer MrDoomBringer marked this pull request as draft August 2, 2022 18:08
@MrDoomBringer MrDoomBringer marked this pull request as ready for review August 9, 2022 15:35
@MrDoomBringer MrDoomBringer linked an issue Aug 9, 2022 that may be closed by this pull request
/** @jest-environment node */
// We run this in a node environment because:
// A) JSDOM doesn't yet support the TextEncoder/TextDecoder elements, meaning certain imports will fail (See https://github.com/jsdom/jsdom/issues/2524)
// B) We're just testing imports/exports, so we don't need to slow down the test with a browser environment.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a side note, if we did still want to run this with JSDOM, we can manually add TextEncoder to the jest environment in the config/jest/setup.ts file like so:

if (typeof global.TextEncoder === 'undefined') {
    const { TextEncoder, TextDecoder } = require('util');
    global.TextEncoder = TextEncoder;
    global.TextDecoder = TextDecoder;
}

Given the scope of this it seemed unnecessary to me, but let me know if you think otherwise.

@hwillson
Copy link
Member

Just dropping this here: apollographql/react-apollo#2627 - it shows that one of the original motivations for the conditional require was to work around issues with React Native.

@benjamn
Copy link
Member

benjamn commented Aug 15, 2022

Looking at apollographql/react-apollo#2627 (thanks @hwillson), I see the "react-dom/server": false trick never made it from the old react-apollo/package.json to the current @apollo/client/package.json (now that React Apollo has been fully merged into the @apollo/client/react package).

@MrDoomBringer I wonder if that "react-dom/server": false in package.json technique might be enough to prevent React Native from mistakenly trying to bundle react-dom/server?

@MrDoomBringer
Copy link
Contributor Author

@benjamn Thanks for the callout! I was actually just looking at the commit that we lost it in here - apollographql/react-apollo@29a4536. Will take a look.

@MrDoomBringer MrDoomBringer merged commit 2d1cd01 into apollographql:main Sep 22, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrong type in package.json
4 participants