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

Suggestion: Use Prettier to format the HTML #22

Open
arthurdenner opened this issue Dec 21, 2023 · 6 comments
Open

Suggestion: Use Prettier to format the HTML #22

arthurdenner opened this issue Dec 21, 2023 · 6 comments

Comments

@arthurdenner
Copy link

arthurdenner commented Dec 21, 2023

At work, I've built a solution to display server-side errors on the client using the onRecoverableError callback from React 18.
I've extended that solution to display a diff on hydration errors based on this package, so thank you very much for sharing it.

A different approach I used was to format the HTML using prettier instead of beautify. I was getting a lot of false positives with beautify due to different things like HTML comments (<!--$-->), semicolons... So my diff was always huge. Using prettier, it's much smaller and there are only some false positives involving inline style attributes.

It might be good to explore this approach for the library itself. Here is a code snippet:

import prettier from 'prettier';
import parserHtml from 'prettier/parser-html';

const prettierHtmlOptions: prettier.Options = {
  parser: 'html',
  plugins: [parserHtml],
  tabWidth: 2,
};

prettier.format(value, prettierHtmlOptions);
@samijaber
Copy link
Contributor

Yeah, could be a useful change to make! If you're feeling up for it, would love for you to make that contribution in a PR.

Otherwise, I will try to take a stab at it down the line when I have some time.

@lucaliebenberg
Copy link

@samijaber Hi, would this be a good first issue/beginner issue? Wouldn't attempting it and try to help out!

@samijaber
Copy link
Contributor

@lucaliebenberg go for it!

@lucaliebenberg
Copy link

@samijaber thanks, I shall give it a go!

@lucaliebenberg
Copy link

@samijaber hi Sam, I have cloned the repo and branched off. I have swapped out the beuatify usages and have replaced it with the prettier implementation similar to what @arthurdenner previously said.

How am I able to open the PR, as it seems my git is denied

@samijaber
Copy link
Contributor

not sure what issue you're facing, you should be able to use this view https://github.com/BuilderIO/hydration-overlay/compare

to take your fork's branch and make a PR against the main branch of this project.

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

No branches or pull requests

3 participants