inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.56k stars 435 forks source link

Fix Inertia Head rendering error when tags contain dynamic value #1997

Open KaioFelps opened 1 month ago

KaioFelps commented 1 month ago

When putting dynamic value or javascript in a tag's content inside Inertia's Head component, it compiles to a jsx element containing an any[] children. renderTag function from Head will recursively render every children, and in this case, trying to access a string node.props will throw an uncatched exception and will break rendering:

Taking as example the React playground from Inertia repository,

dynamic values in Head elements

Would break rendering and just return the template html to the client:

wont render because tried to access props field from a string node
Note that nor the tags inside of Head have been rendered.

Making the following change at Head components (in Vue and React packages) avoid trying to access node.props from the node if it is a string and fixes the issue:

// Head.ts (react package) and head.ts (vue packages)
function renderTag(node) {
    if (typeof node === "string") {
        return node
    }
    // ...
}
started to work after the fix