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

fix(gatsby-plugin-emotion): allow for React.Fragment shorthand syntax #10291

Merged
merged 1 commit into from
Dec 5, 2018
Merged

fix(gatsby-plugin-emotion): allow for React.Fragment shorthand syntax #10291

merged 1 commit into from
Dec 5, 2018

Conversation

wKovacs64
Copy link
Contributor

This change resolves the following error thrown by @babel/plugin-transform-react-jsx when using the React.Fragment shorthand syntax (<> </>) in conjunction with emotion v10 and gatsby-plugin-emotion v3:

Error: transform-react-jsx: pragma has been set but pragmafrag has not been set
@wKovacs64 wKovacs64 requested a review from DSchau December 4, 2018 21:30
Copy link
Contributor

@DSchau DSchau left a comment

Choose a reason for hiding this comment

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

I'll check this out in further detail, but are you sure this is the fix? Per the documentation this is apparently the default?

{
  "plugins": [
    ["@babel/plugin-transform-react-jsx", {
      "pragma": "dom", // default pragma is React.createElement
      "pragmaFrag": "DomFrag", // default is React.Fragment
      "throwIfNamespace": false // defaults to true
    }]
  ]
}
@wKovacs64
Copy link
Contributor Author

The error went away and it started working when I made this change locally. 🤷‍♂️ I mentioned in the Emotion RFC for their upcoming Babel preset and Mitchell included it there.

@janicduplessis
Copy link
Contributor

I've also hit this issue when upgrading and can confirm that it fixes it. Kind of weird that babel forces you to specify both instead of keeping the default value.

@t2ca
Copy link
Contributor

t2ca commented Dec 5, 2018

Since the update to V10, the code below stopped working. Any ideas how to fix this?

const getNavItemStyles = ({ isCurrent }) =>
  isCurrent
    ? {
        className: css({
          ...styles.link.default,
          ...styles.link.active,
        }),
      }
    : {
        className: css({
          ...styles.link.default,
        }),
      }

const MobileNavItem = ({ linkTo, label, icon }) => (
  <Link to={linkTo} getProps={getNavItemStyles}>
    <span>{icon}</span>
    <div>{label}</div>
  </Link>
)

Im getting this as a result

<a aria-current="page" class="[object Object]" href="/">

Update

So i resolved the issue by changing

import { css } from '@emotion/core'

to

import { css } from 'emotion'

@DSchau
Copy link
Contributor

DSchau commented Dec 5, 2018

@t2ca that's due to a change in emotion. className isn't produced from that css call any longer.

See this document for more info.

@t2ca
Copy link
Contributor

t2ca commented Dec 5, 2018

Thank you @DSchau, I was able to find a solution!

@DSchau DSchau merged commit 3c902fc into gatsbyjs:master Dec 5, 2018
@wKovacs64 wKovacs64 deleted the gatsby-plugin-emotion/fragments branch December 5, 2018 21:36
@DSchau
Copy link
Contributor

DSchau commented Dec 5, 2018

Successfully published:
 - gatsby-plugin-emotion@3.0.1
m-allanson added a commit to Bouncey/gatsby that referenced this pull request Dec 7, 2018
* master: (1595 commits)
  chore: update link for react-gatsby-firebase-authentication (gatsbyjs#10314)
  fix(www): Awesome Gatsby sidebar link (gatsbyjs#10313)
  Add thijs koerselman to creators list (gatsbyjs#10303)
  chore(release): Publish
  fix(gatsby-plugin-emotion): allow for React.Fragment shorthand syntax (gatsbyjs#10291)
  feat(www): Update starter cards (gatsbyjs#10258)
  Update index.md (gatsbyjs#10307)
  Update index.md (gatsbyjs#10306)
  Add thijs koerselman portfolio to sites list (gatsbyjs#10304)
  chore(release): Publish
  fix(gatsby): don't remount matchPath pages (gatsbyjs#10261)
  chore(release): Publish
  feat(gatsby-source-contentful): enable RichText for all users (gatsbyjs#10301)
  docs(tutorial): update 404 screenshot (gatsbyjs#10295)
  feat(gatsby-plugin-typescript): allow specifying babel preset options (gatsbyjs#10248)
  docs(gatsby-plugin-sass): fix typo in docs (gatsbyjs#10292)
  fix(ci): actually only run tests on non-docs changes (gatsbyjs#10287)
  fix(blog): rename for correct date in link (gatsbyjs#10290)
  Adds a more descriptive link purpose (gatsbyjs#9266)
  fix(www): comment out down showcase site
  ...
m-allanson added a commit to kaoDev/gatsby that referenced this pull request Dec 7, 2018
* master: (870 commits)
  fix(graphql-skip-limit): declare `graphql` peer dependency (gatsbyjs#10305)
  fix(gatsby-plugin-offline): gracefully degrade if appshell isn't precached (gatsbyjs#10329)
  Service workers note (gatsbyjs#10276)
  fix(docs): link fixes, podcast addition (gatsbyjs#10332)
  feat(docs): Create clearer pathways in docs (gatsbyjs#9898)
  feat(www): Rename community section to creators (gatsbyjs#10312)
  docs(graphql-reference): clarify filtering using comma/and operator (gatsbyjs#10321)
  chore(release): Publish
  feat(gatsby-plugin-sass): Support Dart SASS (gatsbyjs#10159)
  fix(gatsby-source-drupal): use basic auth credentials to fetch remote files as well. (gatsbyjs#10302)
  fix(gatsby-source-filesystem): allow empty password for basic auth in createRemoteFileNode (gatsbyjs#10280)
  docs(gatsby-remark-prismjs): Use Gatsby V2 project structure (gatsbyjs#10059)
  chore: update link for react-gatsby-firebase-authentication (gatsbyjs#10314)
  fix(www): Awesome Gatsby sidebar link (gatsbyjs#10313)
  Add thijs koerselman to creators list (gatsbyjs#10303)
  chore(release): Publish
  fix(gatsby-plugin-emotion): allow for React.Fragment shorthand syntax (gatsbyjs#10291)
  feat(www): Update starter cards (gatsbyjs#10258)
  Update index.md (gatsbyjs#10307)
  Update index.md (gatsbyjs#10306)
  ...
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
…gatsbyjs#10291)

This change resolves the following error thrown by `@babel/plugin-transform-react-jsx` when using the React.Fragment shorthand syntax (`<> </>`) in conjunction with emotion v10 and `gatsby-plugin-emotion` v3:

```
Error: transform-react-jsx: pragma has been set but pragmafrag has not been set
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants