diff --git a/Changelog.md b/Changelog.md index 956948efcc..a207547614 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,21 @@ ## vNext +## 2.3.2 + +### Improvements + +### Bug Fixes + +- This package no longer imports `react-dom/server` unconditionally at the + top level, making `react-apollo` safer to use in environments like React + Native that are neither browser-like nor Node-like, and thus struggle to + import `react-dom/server` and its dependencies. Additionally, the React + Native bundler has been instructed to ignore all `react-dom/server` + dependencies within `react-apollo`, so `react-dom` will not be bundled + in React Native apps simply because they import `react-apollo`. + [PR #2627](https://github.com/apollographql/react-apollo/pull/2627) + ## 2.3.1 (November 15, 2018) ### Improvements diff --git a/package-lock.json b/package-lock.json index f2772be037..29905a4d05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-apollo", - "version": "2.3.1", + "version": "2.3.2-beta.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a1ee3c0e8a..4649f6c684 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-apollo", - "version": "2.3.1", + "version": "2.3.2-beta.4", "author": "opensource@apollographql.com", "private": true, "browser": "lib/react-apollo.browser.umd.js", @@ -12,6 +12,9 @@ ], "license": "MIT", "main": "lib/react-apollo.umd.js", + "react-native": { + "react-dom/server": false + }, "module": "src/index.ts", "typings": "lib/index.d.ts", "repository": { diff --git a/src/getDataFromTree.ts b/src/getDataFromTree.ts index 6745fe8b66..b76d0371c5 100755 --- a/src/getDataFromTree.ts +++ b/src/getDataFromTree.ts @@ -1,6 +1,5 @@ import * as React from 'react'; import * as PropTypes from 'prop-types'; -import { renderToStaticMarkup } from 'react-dom/server'; import Query from './Query'; // Like a Set, but for tuples. In practice, this class is used to store @@ -93,14 +92,14 @@ export default function getDataFromTree( context, // If you need to configure this renderFunction, call getMarkupFromTree // directly instead of getDataFromTree. - renderFunction: renderToStaticMarkup, + renderFunction: require("react-dom/server").renderToStaticMarkup, }); } export type GetMarkupFromTreeOptions = { tree: React.ReactNode; context?: { [key: string]: any }; - renderFunction?: typeof renderToStaticMarkup; + renderFunction?: (tree: React.ReactElement) => string; }; export function getMarkupFromTree({ @@ -109,7 +108,7 @@ export function getMarkupFromTree({ // The rendering function is configurable! We use renderToStaticMarkup as // the default, because it's a little less expensive than renderToString, // and legacy usage of getDataFromTree ignores the return value anyway. - renderFunction = renderToStaticMarkup, + renderFunction = require("react-dom/server").renderToStaticMarkup, }: GetMarkupFromTreeOptions): Promise { const renderPromises = new RenderPromises(); diff --git a/src/renderToStringWithData.ts b/src/renderToStringWithData.ts index f373ff93b7..647939c592 100755 --- a/src/renderToStringWithData.ts +++ b/src/renderToStringWithData.ts @@ -1,8 +1,9 @@ import { ReactElement } from 'react'; -import * as ReactDOM from 'react-dom/server'; - -import { default as getDataFromTree } from './getDataFromTree'; +import { getMarkupFromTree } from './getDataFromTree'; export function renderToStringWithData(component: ReactElement): Promise { - return getDataFromTree(component).then(() => ReactDOM.renderToString(component)); + return getMarkupFromTree({ + tree: component, + renderFunction: require("react-dom/server").renderToString, + }); }