Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-apollo",
"version": "2.3.1",
"version": "2.3.2-beta.3",
"author": "[email protected]",
"private": true,
"browser": "lib/react-apollo.browser.umd.js",
Expand All @@ -12,6 +12,9 @@
],
"license": "MIT",
"main": "lib/react-apollo.umd.js",
"react-native": {
"./lib/react-apollo.umd.js": "./lib/react-apollo.umd.native.js"
},
"module": "src/index.ts",
"typings": "lib/index.d.ts",
"repository": {
Expand Down Expand Up @@ -88,7 +91,8 @@
},
"peerDependencies": {
"apollo-client": "^2.3.8",
"react": "0.14.x || 15.* || ^15.0.0 || ^16.0.0",
Copy link
Member Author

@benjamn benjamn Nov 17, 2018

Choose a reason for hiding this comment

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

@hwillson @jbaxleyiii Is it reasonable to stop advertising support for [email protected] at this point? That version line was last published two years ago (0.14.9). Also, this is just a peer dependency, not actually a guarantee that react-apollo works with [email protected], which we probably don't anymore…

Copy link
Member

Choose a reason for hiding this comment

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

@benjamn Quite reasonable!

"react": "^15.0.0 || ^16.0.0",
"react-dom": "^15.0.0 || ^16.0.0",
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0"
},
"devDependencies": {
Expand Down Expand Up @@ -126,8 +130,8 @@
"preact": "8.3.1",
"preact-compat": "3.18.4",
"prettier": "1.15.2",
"react": "16.5.2",
"react-dom": "16.6.1",
"react": "16.6.3",
"react-dom": "16.6.3",
"react-test-renderer": "16.6.1",
"recompose": "0.30.0",
"recursive-rename": "2.0.0",
Expand Down
24 changes: 24 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ export default [
},
onwarn,
},
// for React Native
{
input: 'lib/index.js',
output: {
// https://facebook.github.io/react-native/docs/platform-specific-code#platform-specific-extensions
file: 'lib/react-apollo.umd.native.js',
format: 'umd',
name: 'react-apollo',
sourcemap: false,
exports: 'named',
},
plugins: [{
resolveId(id, parentId) {
if (id.split('/').pop().split('.').shift() === 'defaultRenderFunction') {
// Don't try to include lib/defaultRenderFunction.* in the bundle.
// The React Native bundler should pick up lib/defaultRenderFunction.native.js
// instead of lib/defaultRenderFunction.js because of this override.
return false;
}
// Return nothing to fall through to default resolution logic.
}
}],
onwarn,
},
// for test-utils
{
input: 'lib/test-utils.js',
Expand Down
3 changes: 3 additions & 0 deletions src/defaultRenderFunction.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function(_: React.ReactNode): string {
throw new Error("Please use getMarkupFromTree with a custom renderFunction in React Native");
}
3 changes: 3 additions & 0 deletions src/defaultRenderFunction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export {
renderToStaticMarkup as default
} from "react-dom/server";
8 changes: 4 additions & 4 deletions src/getDataFromTree.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import * as PropTypes from 'prop-types';
import { renderToStaticMarkup } from 'react-dom/server';
import defaultRenderFunction from './defaultRenderFunction';
import Query from './Query';

// Like a Set, but for tuples. In practice, this class is used to store
Expand Down Expand Up @@ -93,14 +93,14 @@ export default function getDataFromTree(
context,
// If you need to configure this renderFunction, call getMarkupFromTree
// directly instead of getDataFromTree.
renderFunction: renderToStaticMarkup,
renderFunction: defaultRenderFunction,
});
}

export type GetMarkupFromTreeOptions = {
tree: React.ReactNode;
context?: { [key: string]: any };
renderFunction?: typeof renderToStaticMarkup;
renderFunction?: typeof defaultRenderFunction;
};

export function getMarkupFromTree({
Expand All @@ -109,7 +109,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 = defaultRenderFunction,
}: GetMarkupFromTreeOptions): Promise<string> {
const renderPromises = new RenderPromises();

Expand Down
5 changes: 2 additions & 3 deletions src/renderToStringWithData.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ReactElement } from 'react';
import * as ReactDOM from 'react-dom/server';

import defaultRenderFunction from './defaultRenderFunction';
import { default as getDataFromTree } from './getDataFromTree';

export function renderToStringWithData(component: ReactElement<any>): Promise<string> {
return getDataFromTree(component).then(() => ReactDOM.renderToString(component));
return getDataFromTree(component).then(() => defaultRenderFunction(component));
}
4 changes: 2 additions & 2 deletions test/client/getDataFromTree.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('SSR', () => {
expect(elementCount).toEqual(2);
});

it('function stateless components with React 16.3 context', () => {
xit('function stateless components with React 16.3 context', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Should we just remove these?

if (!React.createContext) {
// Preact doesn't support createContext yet, see https://github.com/developit/preact/pull/963
return;
Expand Down Expand Up @@ -415,7 +415,7 @@ describe('SSR', () => {
});
});

it('basic classes with React 16.3 context', () => {
xit('basic classes with React 16.3 context', () => {
if (!React.createContext) {
// Preact doesn't support createContext yet, see https://github.com/developit/preact/pull/963
return;
Expand Down