Skip to content

Suggestion: Use Prettier to format the HTML #22

@arthurdenner

Description

@arthurdenner

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions