Skip to content
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

feat: global vars #1039

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open

feat: global vars #1039

wants to merge 3 commits into from

Conversation

kellyjosephprice
Copy link
Collaborator

@kellyjosephprice kellyjosephprice commented Dec 9, 2024

PR App Fix RM-11562

🧰 Changes

Allows user variables in esm code.

Prior to this, user variables (eg {user.email}) were being replaced with a JSX component (<Variable name="email" />) opaquely. The actual values were provided by the VariableContext. This mimiced how they were handled in pre-mdx versions of the library. This PR undoes that, and provides the user object as a top level import. The following was not possible before, but is possible now:

export const HelloWorld = () => {
  return <div>{user.email}</div>
}

We had talked about implementing it this way, and I somehow ignored/forgot that. Oops.


The VariableContext is still being used, because our custom wrapper around code blocks will also insert the user object into the scope of the code block. eg:

```
Why do we support this? {user.email}
```

Also, I've left the variable transformer processor/transform/variable in place, because it's still being used by the editor. When calling mdast, user variables such as {user.email} should show up as a readme-variable node type.

🧬 QA & Testing

@kellyjosephprice kellyjosephprice marked this pull request as ready for review December 9, 2024 21:12
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.

1 participant