Skip to content

add hints to troubleshoot NextJS + TS issues.#2703

Closed
justincorrigible wants to merge 1 commit intoemotion-js:mainfrom
justincorrigible:patch-1
Closed

add hints to troubleshoot NextJS + TS issues.#2703
justincorrigible wants to merge 1 commit intoemotion-js:mainfrom
justincorrigible:patch-1

Conversation

@justincorrigible
Copy link

@justincorrigible justincorrigible commented Mar 30, 2022

Added details to the TypeScript documentation, geared towards NextJS users.

Making these changing because of the way NextJS enforces its configs, which led me to find this workaround.
AFAIK, there's no mention of NextJS in these instructions, and adding keywords here and there may help others find the solution like I did.

hm not sure how to answer this. sorry.

  • Documentation
  • Tests N/A
  • Code complete N/A
  • Changeset N/A

Thanks for this amazing tool!

@changeset-bot
Copy link

changeset-bot bot commented Mar 30, 2022

⚠️ No Changeset found

Latest commit: dd30f9f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit dd30f9f:

Sandbox Source
Emotion Configuration

@srmagura srmagura self-requested a review March 31, 2022 01:48
Copy link
Contributor

@srmagura srmagura left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I am open to improvements to this docs page, but I don't want to recommend @jsx jsx at the top of every file unless that is really the only way.

### With the old JSX transform

If you are unable to upgrade to the `react-jsx` transform, you will need to specify the JSX factory at the top of every file:
If you are unable to upgrade to the `react-jsx` transform (e.g. while using NextJS, which enforces `"jsx": "preserve"`), you may need to specify the JSX factory at the top of every file:
Copy link
Contributor

Choose a reason for hiding this comment

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

@jsx jsx at the top of every file is not necessary to get Next, TypeScript, and Emotion to play nicely together, so I don't think we should recommend this to users. I rewrote the Emotion documentation site in Next & TypeScript (#2571) and got it to work with jsxImportSource in tsconfig.json and @emotion/babel-plugin — though I'm pretty sure the Babel plugin is not truly necessary here.

Copy link
Author

@justincorrigible justincorrigible Mar 31, 2022

Choose a reason for hiding this comment

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

thank you!
I also find that instruction to "add this everywhere" a bit odd, and wholeheartedly agree with you about it... however, as you may realise, it is not part of my changes. As you will notice in the existing docs, they already had that statement before my PR.

image

In fact, I'm suggesting to modify "will need" to "may need", so it doesn't sound as mandatory.
I tried to change as little as possible in the existing verbiage, but you're right: that line needn't be added everywhere, and I'd like to improve that too.

Naturally, I'm willing to improve this PR if you can advise better phrasing for those other sentences/words I didn't add/change. Any suggestions? I'm also ok closing this PR if your rewrite handles the issue I had.

Copy link
Author

@justincorrigible justincorrigible Mar 31, 2022

Choose a reason for hiding this comment

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

side note, you mention you got it to work with just the babel plugin and jsxImportSource? for some reason I wasn't able to get css props going correctly until I also added the /// declaration.
will give your rewrite a good read, and maybe you'll let me pick your brain if I cannot manage to make it work that way?

edit: just went through your rewrite (awesome amounts of work, btw), and could not find any other differences in config, apart from the NextJS version itself (I'm on ^12.1.2). I wonder if that (or any other package's version difference) is what didn't let the css props work? 🤷
Additionally, I see you're removing the pragma from all the docs, but I'm not sure I recall what you will recommend for people not using babel (or the emotion babel plugin, for that matter)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you @caravinci 😊

  • The reason I commented on your change to this line is because, by mentioning Next.js in this way, it sounds like we are recommending @jsx jsx for all Next.js users.
  • I'm not sure why you needed the /// declaration to get TypeScript to recognize the css prop. I believe jsxImportSource in tsconfig.json is all that's needed to tell TypeScript about the extra prop.
  • I removed the @jsx pragma from all of the code samples because, some of those are live examples and the pragma was messing them up, and also I want the docs to be focused on the react-jsx transform which does not require the pragma.
  • I think the Emotion docs could be improved by adding an "Integration Guides" heading to the navigation menu on the right. It would be below the "Advanced" heading. The nav items under the new heading would be "Create React App / CodeSandbox", "Next.js", .etc. If you would like to work on this, I can create a new issue and reach out to Andarist for approval.

Copy link
Author

@justincorrigible justincorrigible Mar 31, 2022

Choose a reason for hiding this comment

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

The reason I commented on your change to this line is because, by mentioning Next.js in this way, it sounds like we are recommending @jsx jsx for all Next.js users.

Though I'm not sure I would read it that way, I see what you mean and how others may indeed read it that way too. Those not using babel, in particular, may be led to misunderstand my changes.
Your comment makes sense to me now. Thanks for pointing that out 🙏

jsxImportSource in tsconfig.json is all that's needed to tell TypeScript about the extra prop

yeah, it seems reasonable to me too, but for some reason it didn't work in my project/setup. There may be something else going on here that's not obvious to me right now. I'll run some tests this weekend, see if I can at least figure out what the root issue is, and document it.

the Emotion docs could be improved by adding an "Integration Guides"

oh, that would be awesome, and very useful... especially as the NextJS team are actively working on better integration for their SWC. I will gladly help if possible, pending availability at my job, of course.

That said, this PR is not necessary.

@justincorrigible
Copy link
Author

Closing this PR in favour of an eventual new "integration" section in the docs.

@justincorrigible justincorrigible deleted the patch-1 branch March 31, 2022 18:55
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.

2 participants