Mitigate XSS when serializing for server-side rendering
mainWhen serializing state to be embedded in an HTML <script> tag, JSON.stringify is vulnerable to XSS attacks if the data contains strings like </script>. devalue.stringify and devalue.uneval automatically escape these characters (e.g., converting < to \u003C), making them safe for use in templates.
// Safe way to embed state in a template
const template = `
<script>
var preloaded = ${uneval(state)};
</script>`;