Why doesn't React on Rails hydrate at the DOMContentLoaded
event?
#1665
Replies: 1 comment 1 reply
-
As it happens, I was looking into this as well. It used to be on And that mentions 7b301f9 which changed it the other way around earlier... @Judahmeek @justin808 Do you remember what exactly "the race condition revealed by #1539" was? And was the intention actually "after
I don't think that's correct; when the state changes to |
Beta Was this translation helpful? Give feedback.
-
In React on Rails, hydration and rendering sometimes occur at the
load
event. This happens because of the current implementation of theonPageReady
function.react_on_rails/node_package/src/clientStartup.ts
Lines 310 to 337 in 4339d30
If=> WhenclientStartup
is executed whenreadyState
isloading
, hydration occurs at theinteractive
state (DOMContentLoaded
event). However, ifclientStartup
runs whenreadyState
is alreadyinteractive
, hydration is delayed until thecomplete
state (load
event).clientStartup
is executed, hydration always occurs when readyState iscomplete
.This behavior causes hydration to wait until all sub-resources, such as third-party JavaScript or Google Fonts, are fully loaded, potentially delaying the user’s interaction readiness.
Would it be possible to allow hydration at the
DOMContentLoaded
event when thereadyState
is alreadyinteractive
? For example, the following update toonPageReady
could address this:This adjustment ensures hydration begins as soon as the
DOMContentLoaded
event fires, even ifclientStartup
is executed after theinteractive
state.Are there any reasons or side effects that might prevent this change from being implemented? If this approach is acceptable, I’d be happy to submit a PR for it.
Beta Was this translation helpful? Give feedback.
All reactions