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
Delete React debugging props __self and __source #1690
Delete React debugging props __self and __source #1690
Conversation
The @babel/preset-react preset includes two plugins which add `__source` and `__self` attributes to every element included development, which React uses for debugging. This muddles up the DOM and is pretty annoying. For users of preact/compat, it is hard two remove these plugins as Babel does not allow disabling plugins included in a preset (see babel/babel#3016 (comment)), and forking `babel-preset-react-app` would mean having to keep updating it with upstream changes. This is a tiny patch that, in development only, deletes these two attributes from every VNode if they exist. This should not impact production bundle size or performance, but would be a big win for the DX for our project.
Hey @mxstbr 👋! Thanks for taking the time to look and come up with a solution for this! 💯 Have you seen the The import { options } from "preact";
const old = options.vnode;
options.vnode = vnode => {
// Call the previous 'hook'
old(vnode);
// Do the changes here
delete vnode.props.__self;
delete vnode.props.__source;
} What do you think? We do have a wip for integration with the devtools from React, @marvinhagemeister is working on that. Thanks again for opening this! 👍 |
Ohh that works amazingly well, thank you, that solves my problem 100%! 🎉
Does that mean the |
Really happy that works for you 😄 Umm, I just checked with @marvinhagemeister, and seems like it's not part of the devtools integration. So, no, these won't be filtered by that, but the |
@mxstbr Very cool too see you here 👍 💯 Yup, in the long-term we'd like to use both Both properties should be only added during development, because from my understanding those babel plugins are not used in production. For that we stuff everything development related into cc @developit |
Oh I see, I had not been using So the right fix would be to add a filter for |
Implemented in the latest commit @marvinhagemeister—let me know if that looks better! |
Nice work all, thanks for the PR @mxstbr! btw I think you make a good point - we need to clarify that the "elevator pitch" for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Thank you so much for the PR 👍 💯
The @babel/preset-react preset includes two plugins which add
__source
and__self
attributes to every element included development, which React uses for debugging. This muddles up the DOM and is pretty annoying.For users of preact/compat, it is hard two remove these plugins as Babel does not allow disabling plugins included in a preset (see babel/babel#3016 (comment)). We could fork it, but unfortunately these plugins are included two levels deep so we would have to fork
babel-preset-react-app
and@babel/preset-react
, and then keep updating them with upstream changes, which is a bit too much work for such a small change.Instead, this is a tiny patch that (in development only) deletes these two attributes from every VNode if they exist. This should not impact production bundle size or performance, but would be a big win for the DX for our project.
Questions:
preact/compat
instead?preact/debug
, so I am not sure if that does what we need it to do.Closes #1058