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): disable automatic by default #27615

Merged
merged 1 commit into from
Oct 23, 2020

Conversation

wardpeet
Copy link
Contributor

@wardpeet wardpeet commented Oct 23, 2020

Description

Disable automatic react runtime option by default. The ecosystem hasn't adapted yet, projects like theme-ui, mdx, .. haven't adopted it yet. When people us react@17, their site might break

#27468 (comment)

You can test it by adding the following to a page and using react, react-dom

/** @jsx createElement */
import React, { createElement } from "react"

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Oct 23, 2020
@wardpeet wardpeet merged commit 18c182a into gatsbyjs:master Oct 23, 2020
@wardpeet wardpeet deleted the chore/disable-automatic branch October 23, 2020 10:07
@LekoArts LekoArts removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Oct 26, 2020
@t2ca
Copy link
Contributor

t2ca commented Oct 26, 2020

Emotion will support it very soon. emotion-js/emotion#1970

@frontendphil
Copy link

frontendphil commented Nov 21, 2020

This should have been a major version bump. I've upgrade my whole site already and now need to undo all the configurations again if I want to be able to upgrade gatsby. No way to opt-in.


Not just undo actually. Because the new things I've added later never had React imported.

@Bartmr
Copy link

Bartmr commented Dec 16, 2020

@KyleAMathews you can't go around selling that Gatsby has the new JSX Transform and actually having this stated in the React docs and then disable without any warning.

Gatsby is not a personal blog framework. Big companies depend on it

@Bartmr
Copy link

Bartmr commented Dec 16, 2020

@frontendphil add this to your gatsby-node.js and you should be fine

exports.onCreateBabelConfig = ({ actions }) => {
  actions.setBabelPlugin({
    name: '@babel/plugin-transform-react-jsx',
    options: {
      runtime: 'automatic',
    },
  });
};

@armandoborge
Copy link

Unfortunately @Bartmr solution doesn't works for me on Gatsby 3

@wardpeet
Copy link
Contributor Author

create a babelrc file in your gatsby root with the following

{
  "presets": [["babel-preset-gatsby", {
     "reactRuntime": "automatic"
   }]]
}

@bryndyment
Copy link
Contributor

create a babelrc file in your gatsby root with the following

{
  "presets": [["babel-preset-gatsby", {
     "reactRuntime": "automatic"
   }]]
}

This worked for me. I created .babelrc.js with the following single line:

module.exports = { presets: [['babel-preset-gatsby', { reactRuntime: 'automatic' }]] }

@filiptammergard
Copy link

module.exports = { presets: [['babel-preset-gatsby', { reactRuntime: 'automatic' }]] }

Not sure why, but this didn't work for me. However, this worked:

module.exports = {
  plugins: [["@babel/plugin-transform-react-jsx", { runtime: "automatic" }]],
}

I.e. exactly like #27615 (comment) but in a babel config file instead of gatsby-node.js.

@angeloashmore
Copy link
Contributor

For anyone coming across this now, you can enable the automatic JSX transform with the jsxRuntime gatsby-config.js option:

// gatsby-config.js
module.exports = {
	jsxRuntime: "automatic",
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants