Skip to content

Conversation

@Romex91
Copy link
Contributor

@Romex91 Romex91 commented Apr 11, 2025

Summary

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

Pull Request checklist

Remove this line after checking all the items here. If the item is not applicable to the PR, both check it out and wrap it by ~.

  • Add/update test to cover these changes
  • Update documentation
  • Update CHANGELOG file

Add the CHANGELOG entry at the top of the file.

Other Information

Remove this paragraph and mention any other important and relevant information such as benchmarks.


This change is Reviewable

Summary by CodeRabbit

  • Bug Fixes
    • Adjusted the page readiness sequence to improve compatibility with Safari, ensuring consistent and reliable page behavior upon load.
    • Documented a fix for the load event not firing in Safari in the CHANGELOG.
  • Version Updates
    • Updated the version of the ReactOnRails module and the react-on-rails package from "14.2.0" to "14.2.1".

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 11, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request modifies the onPageReady function in the client startup module to adjust the timing of the callback execution when the document's readyState is "complete". The implementation now uses setTimeout(callback, 0) to delay the callback until after the load event, addressing an issue specific to Safari's handling of the load event during React hydration. Additionally, a comment has been added to clarify this adjustment. The versioning for the ReactOnRails module and the react-on-rails package has been updated to reflect this change.

Changes

File Change Summary
node_package/.../clientStartup.ts Updated the onPageReady function to use setTimeout(callback, 0) for delaying callback invocation when document is "complete", with an added comment about Safari skipping the load event.
CHANGELOG.md Added a new section for version [14.2.1] dated 2025-04-11, documenting a bug fix for the load event not firing in Safari, attributed to PR 1729 by Romex91.
lib/react_on_rails/version.rb Updated the version number from "14.2.0" to "14.2.1" in the ReactOnRails module.
package.json Updated the package version from "14.2.0" to "14.2.1" for the react-on-rails package.

Sequence Diagram(s)

sequenceDiagram
    participant Doc as Document
    participant Startup as clientStartup
    participant Callback as Callback

    Note over Startup: Document readyState is "complete"
    Doc->>Startup: onPageReady(callback)
    Startup->>Callback: setTimeout(callback, 0)
    Note right of Callback: Execution deferred until after the load event
Loading

Poem

In the code where events delay,
I, a rabbit, hop and play.
With setTimeout's gentle sway,
Safari issues fade away.
Hoppy changes light the way 🐇✨!


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
CHANGELOG.md (1)

21-24: Suggestion: Enhance Changelog Entry for Clarity
The entry currently states that the bug where the load event was not firing in Safari has been fixed. Since the underlying fix involves postponing hydration to the next JavaScript task (using setTimeout(callback, 0)), it might be helpful to mention that detail for added clarity. This additional context can provide valuable insight for users and maintainers reviewing the changelog entry.

Optional diff suggestion:

- - Fixed a bug where the `load` event was not firing in Safari. [PR 1729](https://github.com/shakacode/react_on_rails/pull/1729) by [Romex91](https://github.com/Romex91).
+ - 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).
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dbf4c0e and 7f3a0cb.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)

@Romex91 Romex91 changed the base branch from master to patch/14.2.1 April 11, 2025 09:33
@Romex91 Romex91 changed the base branch from patch/14.2.1 to master April 11, 2025 09:35
@Romex91 Romex91 changed the base branch from master to patch/14.2.1 April 11, 2025 09:35
@Romex91 Romex91 merged commit f8773fc into patch/14.2.1 Apr 11, 2025
11 checks passed
@Romex91 Romex91 deleted the roman-kuksin/fix-firefox-missing-load-event branch April 11, 2025 12:06
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.

3 participants