Skip to content

reactOnRailsPageLoaded invoked before deferred scripts are completed #1150

@rakelley

Description

@rakelley

When Turbolinks is disabled, clientStartup.js can invoke reactOnRailsPageLoaded in a manner that appears premature and unintentional (and is causing my team no end to grief).

The offending code is the timeout declared here with the condition if (document.readyState === 'complete' || document.readyState !== 'loading' && !document.documentElement.doScroll) {. A readyState of interactive while deferred scripts are still being processed will lead to reactOnRailsPageLoaded being called before all components have been registered. From our testing, Chrome seems to be the only browser fast enough to actually trigger this behavior, but it's a serious issue for us, made worse if utilizing preloading/server-push.

By the surrounding debug messages and the choice to use DOMContentLoaded event handlers, the intention seems to be that reactOnRailsPageLoaded should not be invoked until the page is actually loaded, which is not merely readyState = interactive but post-DOMContentLoaded.

Is it intentional that reactOnRailsPageLoaded is called before DOMContentLoaded, if any only if Turbolinks is disabled?

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