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

Running prettier via the pre-commit hook creates invalid mdx #369

Open
AlexanderZeilmann opened this issue Jan 31, 2022 · 4 comments
Open
Labels
bug Something isn't working

Comments

@AlexanderZeilmann
Copy link
Contributor

Describe the bug
Running husky creates invalid mdx.

To Reproduce
Steps to reproduce the behavior:

  1. Standard setup
  2. Create blog post containing Press <kbd><kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd></kbd> and
  3. Blog post works fine.
  4. Run husky by committing the blog post.
  5. The code snippet above is converted to
Press <kbd>
    <kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>
</kbd>
and

Which generates the following error

Error: Build failed with 1 error:
_mdx_bundler_entry_point-526e1ca1-0ac1-4cfd-bcc7-534cd64daa30.mdx:20:0: ERROR: [plugin: esbuild-xdm] Expected a closing tag for `</kbd>` (20:7-20:12) before the end of `paragraph`

Expected behavior
Husky should not generate invalid mdx.

System Info (if dev / build issue):

  • OS: Mac OS 10.15.4
  • Node version: 16.9.1
  • Npm version: 8.3.0

Additional context
The problem appears also with other html tags.
A workaround is to disable husky temporarily by renaming the .husky folder to something else.
According to the mdx playground the markup is really invalid, i.e., it is not a problem with the mdx setup here.
This is probably an upstream bug, but I wanted to report this here as well.

@AlexanderZeilmann AlexanderZeilmann added the bug Something isn't working label Jan 31, 2022
@timlrx
Copy link
Owner

timlrx commented Jan 31, 2022

Husky just runs lint-staged which runs prettier. Here's the line in package.json. Looks like prettier might not be that smart in formatting HTML in mdx. Try removing md|mdx and see if that works?

It could also be the case that the current prettier version is slightly outdated and maybe upgrading would fix the issue. Let me know if upgrading prettier helps?

@AlexanderZeilmann
Copy link
Contributor Author

I created an upstream bug with prettier, until this is fixed I am keeping husky disabled.

@AlexanderZeilmann
Copy link
Contributor Author

The bug is now tracked in prettier/prettier#12209. I'm closing this issue until the bug is fixed as we can't do anything right now.

@timlrx timlrx changed the title husky creates invalid mdx Running prettier via the pre-commit hook creates invalid mdx Feb 2, 2022
@timlrx timlrx reopened this Feb 2, 2022
@timlrx
Copy link
Owner

timlrx commented Feb 2, 2022

Re-opening the issue for awareness and to avoid similar issues being posted. Have also changed the title to more accurately reflect the bug.

If you encounter the issue, currently the best approach would be to exclude md/mdx files from being linted by prettier. You can do that by removing md|mdx in this line in package.json

Jeff-Russ added a commit to Jeff-Russ/next-markdown-journal that referenced this issue Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants