-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support React __source
prop
#2035
Comments
|
I found a bit more info in the React RFC for the automatic runtime. So basically in the classic runtime, we need to compile to: React.createElement(
Component,
{
...props,
__source={{ fileName, lineNumber, columnNumber }}
__self={this}
},
...children
) And in the automatic runtime, we need to compile to the following, where import { jsxDEV as _jsxDEV } from 'react/jsx-runtime'
_jsxDEV(
Component,
props,
key,
isStaticChildren,
{ fileName, lineNumber, columnNumber },
this
) I still need to figure out when the I also believe this shows this functionality belongs in core, especially for the automatic runtime. |
We generate JSX. Because otherwise each step needs to know which runtime the user wants, and sometimes they don‘t want to compile it away. I think we need to do the same here: add that prop to JSX. On the receiving end, we can see from Preact and React, that they optionally expect For the classic runtime, as you linked before, as I don’t support |
Maybe we should only focus on the automatic runtime. The main difference is the automatic runtime actually supports a specific dev transform, whereas in the classic runtime some React specific props are used.
For comparison, TypeScript basically supports 3 types of JSX transforms:
Babel supports 2 runtime types in their JSX plugin: It uses a |
Maybe I don’t see a need for an extra I’m under the impression that TS is a bit messy with everything it supports for JSX, compared to the comments that we, Babel, and SWC support. I’d focus on modelling Babel! Sounds like we have a plan?! |
I believe we need the file contents, because estree uses offsets which we need to map to lines and columns. Depending on that we need either a vfile or just the file path. I'll figure that out on the go. Apart from that, we have a plan! 👍 |
Aren't the positions on nodes enough? 🤔 |
AST explorer only attaches start and end offsets, but apparently the estree format produced by MDX attaches |
Closes GH-2. Related-to: mdx-js/mdx#2035. Reviewed-by: Titus Wormer <[email protected]>
The JSX dev runtime exposes more debugging information to users. For example, React exposes positional information through React Devtools. Although GH-2035 started off as an issue to support the `__source` prop, I have refrained from actually supporting the `__source` prop, as it’s specific to React. The automatic dev runtime supports this information without patching props. Closes GH-2035. Closes GH-2045. Reviewed-by: Titus Wormer <[email protected]>
Initial checklist
Problem
React uses the
__source
prop display where components originate in the React devtools.Babel supports this in
@babel/babel-plugin-transform-react-jsx-source
.Solution
Inject this prop in a similar way as
@babel/babel-plugin-transform-react-jsx-source
. This should only happen in development and only for React, but optionally supporting alternative runtimes.Also I’m willing to implement this.
Alternatives
It could be an external recma plugin, but I think it’s useful to include in core.
The text was updated successfully, but these errors were encountered: