inertia icon indicating copy to clipboard operation
inertia copied to clipboard

Fix Inertia Head rendering error when tags contain dynamic value

Open KaioFelps opened this issue 1 year ago • 0 comments

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

KaioFelps avatar Oct 07 '24 15:10 KaioFelps