Auto minify html and react hydrate


I have issue with autominify html in react ssr apps. The same as described here:

Example is showed here:
necessarily make sure you’re viewing source, not via devtools.

I know I can disable it via header, from cf ui, via page rule.
But ideally I would like to prepare data as minify html makes it - before sending it to browser I could wrap string, minify it, and return to the client.

and here is my question - do you know any npm library which in the same way can prepare html as cf is doing it? or at least how could I prepare html in the same way?

more technical:
I’m using nextjs and this function sends json (which is not minified) in inline script tag.

export const getServerSideProps = () => {
  const { test } = {
    test: '7\t100 słoni, 1,1\tmiliarda ziarenek piasku.  ',

  const foo = {
    props: {
  return JSON.parse(
    JSON.stringify(foo) # <- I can modify it here