Skip to content

Commit

Permalink
RFC: Do not include package-local polyfills.
Browse files Browse the repository at this point in the history
This removes babel's core-js polyfills from the distributed NPM builds. This aids in further reducing app bundle size when targeting modern browsers, and allows flexibility in how these polyfills are provided if necessary, which can help fix React Native specific issues, as illustrated in #1799 and #1704 and #1818.

The drawback is that polyfills for these things are now something that client developers will need to think about directly. Shipping Relay to older browsers before this diff should work fine, but after this diff will require global polyfills. As such, this diff may constitute at least a minor-breaking change.
  • Loading branch information
leebyron committed Jun 8, 2017
1 parent dfcc708 commit 5ec9e91
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
11 changes: 11 additions & 0 deletions docs/modern/Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ Run the Relay Compiler after making changes to any GraphQL in your Relay applica
Then after making edits to your application files, just run `yarn run relay` to generate new files, or `yarn run relay -- --watch` to run the compiler as a long-lived process which automatically generates new files whenever you save.


## JavaScript Environment

The Relay Modern packages distributed on NPM use the widely-supported ES5
version of JavaScript to support as many browser environments as possible.

However, Relay Modern expects modern JavaScript global types (`Map`, `Set`,
`Promise`) to be defined. If you support older browsers and devices which may
not yet provide these natively, consider including a global polyfill in your
bundled application.


## Migrating to Relay Modern

Migrating a Relay Classic app to Relay Modern doesn't require rewriting from
Expand Down
14 changes: 1 addition & 13 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ const babelOptions = require('./scripts/getBabelOptions')({
'babel-core': 'babel-core',
'babel-generator': 'babel-generator',
'babel-polyfill': 'babel-polyfill',
'babel-runtime/core-js/array/from': 'babel-runtime/core-js/array/from',
'babel-runtime/core-js/json/stringify': 'babel-runtime/core-js/json/stringify',
'babel-runtime/core-js/map': 'babel-runtime/core-js/map',
'babel-runtime/core-js/object/assign': 'babel-runtime/core-js/object/assign',
'babel-runtime/core-js/object/freeze': 'babel-runtime/core-js/object/freeze',
'babel-runtime/core-js/object/get-own-property-names': 'babel-runtime/core-js/object/get-own-property-names',
'babel-runtime/core-js/object/is-frozen': 'babel-runtime/core-js/object/is-frozen',
'babel-runtime/core-js/object/keys': 'babel-runtime/core-js/object/keys',
'babel-runtime/core-js/object/values': 'babel-runtime/core-js/object/values',
'babel-runtime/core-js/promise': 'fbjs/lib/Promise',
'babel-runtime/core-js/set': 'babel-runtime/core-js/set',
'babel-runtime/core-js/weak-map': 'babel-runtime/core-js/weak-map',
'babel-runtime/helpers/asyncToGenerator': 'babel-runtime/helpers/asyncToGenerator',
'babel-runtime/helpers/classCallCheck': 'babel-runtime/helpers/classCallCheck',
'babel-runtime/helpers/defineProperty': 'babel-runtime/helpers/defineProperty',
Expand Down Expand Up @@ -56,7 +44,7 @@ const babelOptions = require('./scripts/getBabelOptions')({
},
plugins: [
'transform-flow-strip-types',
'transform-runtime',
['transform-runtime', {"polyfill": false}],
],
postPlugins: [
'transform-async-to-generator',
Expand Down
15 changes: 15 additions & 0 deletions packages/relay-runtime/RelayRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ export type {
ConcreteFragment,
} from 'RelayConcreteNode';

// As early as possible, check for the existence of the JavaScript globals which
// Relay Runtime rely upon, and produce a clear message if they do not exist.
if (__DEV__) {
if (
typeof Map !== 'function' ||
typeof Set !== 'function' ||
typeof Promise !== 'function'
) {
throw new Error(
'relay-runtime requires Map, Set, and Promise to be defined. ' +
'Use a polyfill to provide these for older browsers.'
);
}
}

/**
* The public interface to Relay Runtime.
*/
Expand Down
1 change: 0 additions & 1 deletion scripts/getBabelOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = function(options) {
}, options);

const fbjsPreset = require('babel-preset-fbjs/configure')({
autoImport: true,
inlineRequires: true,
rewriteModules: {
map: assign({},
Expand Down

0 comments on commit 5ec9e91

Please sign in to comment.