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(babel): Babel plugin: debug-label #697

Merged
merged 18 commits into from
Sep 13, 2021
Merged

Conversation

Thisen
Copy link
Collaborator

@Thisen Thisen commented Sep 9, 2021

This change adds a Babel plugin to Jotai for adding debug labels automatically to atoms.

Partially fixes #487, as I want to split the PRs as much as possible.

The plan is to create the following plugins:

  • jotai/babel/plugin-debug-label - Handles debug label
  • jotai/babel/plugin-react-refresh - Handles React refresh support

And the following preset to compose the plugins:

  • jotai/babel/preset

EDIT:

If you wanna try it out, use the new sandbox or install the CSB build and add the following to your .babelrc:

{
  "presets": [],
  "plugins": ["jotai/babel/plugin-debug-label"]
}

@vercel
Copy link

vercel bot commented Sep 9, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pmndrs/jotai/89DWimBFRM4SqtcTzNZy3irW7utX
✅ Preview: https://jotai-git-babel-plugin-debug-label-pmndrs.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 9, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit efff15c:

Sandbox Source
React Configuration
React Typescript Configuration
React Browserify Configuration
React Snowpack Configuration
Next.js Configuration
Next.js with custom Babel config Configuration
React with custom Babel config Configuration

@dai-shi
Copy link
Member

dai-shi commented Sep 10, 2021

Is this ready to play with? How can we try?

@Thisen
Copy link
Collaborator Author

Thisen commented Sep 10, 2021

Is this ready to play with? How can we try?

If you want to try it, you can use the CSB build and add this to your .babelrc:

{
  "presets": [],
  "plugins": ["jotai/babel-plugin/debug-label"]
}

@dai-shi
Copy link
Member

dai-shi commented Sep 11, 2021

https://codesandbox.io/s/jotai-nextjs-babel-plugin-kc8sd
Is this something you expected? Got "Internal Server Error"

package.json Outdated Show resolved Hide resolved
@dai-shi
Copy link
Member

dai-shi commented Sep 12, 2021

It works well in codesandbox. nextjs with babel config.
The screenshot with react devtools, using <Provider>:
unknown

@Thisen
Copy link
Collaborator Author

Thisen commented Sep 12, 2021

I think it's getting close to ready. Please review and try it.

Happy to get more test cases.

@Thisen Thisen marked this pull request as ready for review September 12, 2021 13:04
Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

I think this is good for the initial version.
There could be many edge cases that need to be covered later, but it's more important to let it go.
Let's label this as "experimental" in the release note.

).toMatchInlineSnapshot(`
"export const countAtom = atom(0);
countAtom.debugLabel = \\"countAtom\\";
const atoms = atom(0);
Copy link
Member

Choose a reason for hiding this comment

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

How does this resolve naming conflict?

Copy link
Collaborator Author

@Thisen Thisen Sep 13, 2021

Choose a reason for hiding this comment

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

Good catch. If someone has an atom called atoms, it would break - Do you have a good idea how to guard against it?

Copy link
Member

Choose a reason for hiding this comment

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

It can be any variable or even a function declaration function atom() { return 1 }.
I would simply ignore if it finds a conflict.

.codesandbox/ci.json Outdated Show resolved Hide resolved
@dai-shi
Copy link
Member

dai-shi commented Sep 13, 2021

Yay, it works in non-container codesandbox.

image

@dai-shi dai-shi merged commit 155e8ca into main Sep 13, 2021
@dai-shi dai-shi deleted the babel-plugin-debug-label branch September 13, 2021 12:29
@dai-shi dai-shi changed the title Babel plugin: debug-label feat(babel): Babel plugin: debug-label Sep 13, 2021
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.

Babel plugins: Adding debug label and fast refresh support
2 participants