Skip to content

Commit f8773fc

Browse files
authored
Postpone hydration to the next JS task to fix a bug in safari (#1729)
When hydrating React from the `readystatechange` listener, Safari skips the `load` event. Not sure why, but looks like a bug in the browser. This issue caused the Web Builder to load infinitely in Popmenu
1 parent a8b8c03 commit f8773fc

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
1818
### [Unreleased]
1919
Changes since the last non-beta release.
2020

21+
### [14.2.1] - 2025-04-11
22+
23+
#### Fixed
24+
- Fixed a bug where the `load` event was not firing in Safari by postponing hydration to the next JavaScript task using `setTimeout(callback, 0)`. [PR 1729](https://github.com/shakacode/react_on_rails/pull/1729) by [Romex91](https://github.com/Romex91).
25+
2126
### [14.2.0] - 2025-03-03
2227

2328
#### Added

lib/react_on_rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module ReactOnRails
4-
VERSION = "14.2.0"
4+
VERSION = "14.2.1"
55
end

node_package/src/clientStartup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ function isWindow(context: Context): context is Window {
309309

310310
function onPageReady(callback: () => void) {
311311
if (document.readyState === "complete") {
312-
callback();
312+
// When hydrating React from the `readystatechange` listener, Safari skips the `load` event.
313+
// To avoid this, we use a timeout to postpone the callback until after the `load` event.
314+
setTimeout(callback, 0);
313315
} else {
314316
document.addEventListener("readystatechange", function onReadyStateChange() {
315317
onPageReady(callback);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-on-rails",
3-
"version": "14.2.0",
3+
"version": "14.2.1",
44
"description": "react-on-rails JavaScript for react_on_rails Ruby gem",
55
"main": "node_package/lib/ReactOnRails.full.js",
66
"exports": {

spec/dummy/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ../..
33
specs:
4-
react_on_rails (14.2.0)
4+
react_on_rails (14.2.1)
55
addressable
66
connection_pool
77
execjs (~> 2.5)

0 commit comments

Comments
 (0)