Skip to content

Add support for the automatic dev runtime #2

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

Merged
merged 14 commits into from
May 18, 2022
Merged

Add support for the automatic dev runtime #2

merged 14 commits into from
May 18, 2022

Conversation

remcohaszing
Copy link
Member

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

This was discussed in mdx-js/mdx#2035. The only difference that wasn’t discussed is that the automatic runtime import is also changed from /jsx-runtime to /jsx-dev-runtime.

The source parameter is still missing, as its meaning is not clear to me. It’s not required anyway, so this should be fine.

@remcohaszing remcohaszing requested a review from wooorm May 17, 2022 16:49
@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels May 17, 2022
Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

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

source is a reference to this right? Not sure what it’s used for either but presumably it’s something, so if it’s easy to add?

Otherwise: can be a bit more spacious with blank lines between statements but everything looks good!

@wooorm
Copy link
Member

wooorm commented May 17, 2022

Oh before we forget: this also needs some docs!

@wooorm wooorm added 🦋 type/enhancement This is great to have 🗄 area/interface This affects the public interface 🧒 semver/minor This is backwards-compatible change 👍 phase/yes Post is accepted and can be worked on 🙆 yes/confirmed This is confirmed and ready to be worked on and removed 🤞 phase/open Post is being triaged manually labels May 17, 2022
@github-actions

This comment has been minimized.

@remcohaszing
Copy link
Member Author

source is a reference to this right? Not sure what it’s used for either but presumably it’s something, so if it’s easy to add?

Babel does add it conditionally, but it’s added most of the time. If it’s defined, it’s always this. I don’t think it hurts to just always add it. It mostly bothers me that I don’t know what it’s for. Should I just add it anyway?

readme.md Outdated
Comment on lines 118 to 119
If the automatic runtime is used, this compiles JSX into automatic runtime
development mode (`boolean`, default: `false`).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
If the automatic runtime is used, this compiles JSX into automatic runtime
development mode (`boolean`, default: `false`).
Add location info on where a component originated from (`boolean`, default:
`false`).
This helps debugging but adds a lot of code that you don’t want in production.
Only used when `filePath` is and in the automatic runtime.

Btw: does React still show somewhat useful info without a filePath? Maybe we could still do something with line/column without and lift the restriction? Maybe more confusing but potentially we could default to '<source.js>' or so even?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is what React Devtools shows if filePath is missing.

image

So let’s not add it in this case.

If positional information is missing, it’s rendered as undefined, which I think is ok.

Copy link
Member

Choose a reason for hiding this comment

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

So it doesn’t show anything?
And what if we use '<source.js>'

Copy link
Member Author

Choose a reason for hiding this comment

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

My screenshot was a bit unclear. This error view replaces what would normally be the part that display component details.

Anyway, showing <source.js> looks fine. 👍

Copy link
Member

Choose a reason for hiding this comment

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

Now I’m interested whether you have a screenshot that shows this, because I haven’t seen it yet!
Glad a fake name is somewhat useful!

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure!

I created the following Next.js page in recma-nextjs-static-props, then tweaked the source parameters:

import { jsxDEV } from 'react/jsx-dev-runtime'

export default function Foo() {
  return jsxDEV(
    'p',
    { children: 'Hello world!' },
    'key',
    false,
    {
      fileName: '/home/remco/Projects/recma-nextjs-static-props/pages/foo.jsx',
      lineNumber: 35,
      columnNumber: 42,
    },
    this,
  )
}

Using the React devtools chrome extension, it looks like this:

Complete information

The source copy button copies /home/remco/Projects/recma-nextjs-static-props/pages/foo.jsx:35 to the clipboard. This format can be copied directly into the VSCode file search for example

The Log this component data to the console button logs the following positional data to the console:

Component data logged to console

With removed positional information, it looks like this:

missing positional information

With a removed filename, it looks like this:

missing filename

With source set to undefined, it looks like this:

source undefined

And just for you, a screenshot with fileName set to <source.js>. 😄

image

@wooorm
Copy link
Member

wooorm commented May 17, 2022

[on source] I don’t think it hurts to just always add it

Same, if its not too hard, I’m 👍

remcohaszing and others added 6 commits May 17, 2022 22:05
Co-authored-by: Titus <tituswormer@gmail.com>
Co-authored-by: Titus <tituswormer@gmail.com>
Co-authored-by: Titus <tituswormer@gmail.com>
Co-authored-by: Titus <tituswormer@gmail.com>
This way positional info is still present.
Co-authored-by: Titus <tituswormer@gmail.com>
@wooorm wooorm changed the title Support the automatic dev runtime Add support for the automatic dev runtime May 18, 2022
@wooorm wooorm merged commit c346fbf into syntax-tree:main May 18, 2022
@wooorm wooorm added the 💪 phase/solved Post is done label May 18, 2022
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed 👍 phase/yes Post is accepted and can be worked on 🙆 yes/confirmed This is confirmed and ready to be worked on labels May 18, 2022
@wooorm
Copy link
Member

wooorm commented May 18, 2022

Released in https://github.com/syntax-tree/estree-util-build-jsx/releases/tag/2.1.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

2 participants