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

feat(gatsby): Support React 17's new JSX Transform #26652

Merged
merged 17 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/babel-preset-gatsby/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ export default function preset(_, options = {}) {
resolve(`@babel/preset-react`),
{
useBuiltIns: true,
pragma: `React.createElement`,
pragma:
options.runtime === `automatic` ? null : `React.createElement`,
blainekasten marked this conversation as resolved.
Show resolved Hide resolved
development: stage === `develop`,
runtime: options.runtime || `classic`,
},
],
],
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"pretty-error": "^2.1.1",
"progress": "^2.0.3",
"prompts": "^2.3.2",
"react": "^16.8.0",
"redux": "^4.0.5",
"resolve-cwd": "^3.0.0",
"semver": "^7.3.2",
Expand All @@ -60,6 +59,9 @@
"rimraf": "^3.0.2",
"typescript": "^3.9.5"
},
"peerDependencies": {
"react": ">=16.8.0"
},
blainekasten marked this conversation as resolved.
Show resolved Hide resolved
"files": [
"lib/",
"scripts/",
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby/src/utils/babel-loader-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const getCustomOptions = stage => {
const prepareOptions = (babel, options = {}, resolve = require.resolve) => {
const pluginBabelConfig = loadCachedConfig()

const { stage } = options
const { stage, runtime } = options

// Required plugins/presets
const requiredPlugins = [
Expand Down Expand Up @@ -67,6 +67,7 @@ const prepareOptions = (babel, options = {}, resolve = require.resolve) => {
resolve(`babel-preset-gatsby`),
{
stage,
runtime,
},
],
{
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby/src/utils/babel-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ const {
module.exports = babelLoader.custom(babel => {
const toReturn = {
// Passed the loader options.
customOptions({ stage = `test`, ...options }) {
customOptions({ stage = `test`, runtime = `classic`, ...options }) {
return {
custom: {
stage,
runtime,
},
loader: {
sourceType: `unambiguous`,
Expand Down
10 changes: 10 additions & 0 deletions packages/gatsby/src/utils/webpack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MiniCssExtractPlugin from "mini-css-extract-plugin"
import OptimizeCssAssetsPlugin from "optimize-css-assets-webpack-plugin"
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin"
import isWsl from "is-wsl"
import semver from "semver"
import { getBrowsersList } from "./browserslist"

import { GatsbyWebpackStatsExtractor } from "./gatsby-webpack-stats-extractor"
Expand Down Expand Up @@ -270,9 +271,18 @@ export const createWebpackUtils = (
},

js: options => {
let reactMajorVersion = 0

try {
const react = require(`react`)
reactMajorVersion = semver.major(react.version)
} catch (e) {
// no-op.
}
blainekasten marked this conversation as resolved.
Show resolved Hide resolved
return {
options: {
stage,
runtime: reactMajorVersion >= 17 ? `automatic` : `classic`,
blainekasten marked this conversation as resolved.
Show resolved Hide resolved
// TODO add proper cache keys
cacheDirectory: path.join(
program.directory,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19856,7 +19856,7 @@ react-typography@^0.16.19:
resolved "https://registry.yarnpkg.com/react-typography/-/react-typography-0.16.19.tgz#5736b47961dcf6b9605b6fa38d41980db2588e28"
integrity sha512-kV2qLEsdm0x9P4YXQEDVc88tDb4Vg0h/vdVZGgbqaRn8ERvNzV76JHUeOby3vvcUYU5MPd5Kz5DPH9Bhp4I/iw==

react@^16.12.0, react@^16.8.0:
react@^16.12.0:
version "16.12.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.12.0.tgz#0c0a9c6a142429e3614834d5a778e18aa78a0b83"
integrity sha512-fglqy3k5E+81pA8s+7K0/T3DBCF0ZDOher1elBFzF7O6arXJgzyu/FW+COxFvAWXJoJN9KIZbT2LXlukwphYTA==
Expand Down