-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Report use of MDX internals #395
Comments
We can report. Or crash. Or increment the name of our variables ( What about |
This makes me think you mistook this issue from one in the MDX repo. I’m ok with the compiler crashing, but not the language server.
IMO incrementing makes sense if the user declares a conflicting variable, not when they access it. In that case it still should be reported by the language server. Also this is more work IMO than it’s worth.
|
Indeed. Because whether these variables should be accessed affects MDX as a whole? Something could be done here, or something could be done in
I meant when MDX defines it. MDX injects variable names. It chooses these names right now. It could also check the scope and choose different names.
Yes. You did that. Because you thought it was a good idea for users to access internals / make it an API. |
Good idea @remcohaszing! |
Actually using |
Maybe, this is an interesting thought. I was also thinking of filtering these names from autocompletion results. |
(side note: the distinction isn’t about lower-case vs upper-case btw) Agree that it’s probably a bad idea to use An IIFE:
{
(() => {
// Access passed/injected component inside JS:
return <_components.H1>Hi!</_components.H1>
})()
} If we want to allow this behavior, we should probably call it
If used in the main body. MDX files can also export components. Which could reference the global scope. Someone could do something along the lines of export function WrappedContent() {
return <main><MDXContent /></main>
}
# Hi |
I get your point, but if we do so, this: <HI /> is equivalent to: <components.HI /> It would only be different if the MDX file imports or defines the Also someone could already define the <MDXContent components={{components: {HI}}} /> To introduce a new variable would be a breaking change. |
Yep, usage from |
Yes, renaming to make things public or preventing their use would both be breaking. |
On the compiler level, yes. To report bad usage in the editor is not breaking. |
Another internal variable is |
Initial checklist
Problem
MDX generates some internal variables in the compiled output. These variables are in scope and users could use them, but they they should not.
Solution
Report usage of the following identifiers:
_components
_createMdxContent
We should probably also report usage of the following variables:
MDXLayout
MDXContent
Alternatives
Consider all variables starting with an underscore to be private.
The text was updated successfully, but these errors were encountered: