Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: v1
Choose a base branch
from

Conversation

KaioFelps
Copy link

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

@reinink reinink changed the base branch from master to v1 October 9, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant