Skip to content

allow changing where script tags are appended to #2781

@paperclover

Description

@paperclover

Is your feature request related to a problem?

This code for appending script tags is too smart:

const scripts = document.querySelectorAll('body > script')
if (scripts.length > 0) {
scripts[0].parentNode?.insertBefore(scriptTag, scripts[0])
} else {
// In exceptional situations this call might load before the DOM is fully ready.
document.body.appendChild(scriptTag)
}

It causes a hydration error because it interweaves with this component in tanstack router.

Describe the solution you'd like

  • allow a configuration to always document.body.appendChild(scriptTag)
  • allow a configuration to set the target element (so i can set it to document.body)
  • allow prepare_external_dependency_script to return a promise so the configuration can customize how the script is mounted instead of disabling it.

Describe alternatives you've considered

current solution is patching posthog to make the script loading simpler

Related sub-libraries

  • posthog-js (web)

Additional Notes

search keywords: hydration error, tanstack start, tanstack router, loadScript

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions