Skip to content

Conversation

@saierd
Copy link

@saierd saierd commented Dec 11, 2025

It was not possible to disable the behavior at the moment. Browsers understanding preventDefault() would always show the dialog as long as the plugin is enabled.

Broken in commit 166df01.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed web platform window close and reload behavior to more precisely handle when default browser unload prevention should be applied, improving reliability of these operations.

✏️ Tip: You can customize this high-level summary in your review settings.

…by setWebReturnValue

It was not possible to disable the behavior at the moment. Browsers understanding preventDefault() would always show the dialog as long as the plugin is enabled.

Broken in commit 166df01.
@coderabbitai
Copy link

coderabbitai bot commented Dec 11, 2025

Walkthrough

Modified the web beforeunload handler to conditionally invoke preventDefault() only when _returnValue is non-null, rather than unconditionally. The returnValue assignment logic remains unchanged, but the control flow for preventing default unload behavior is now gated behind the same null check.

Changes

Cohort / File(s) Summary
Web beforeunload handler update
lib/flutter_window_close_web.dart
Moved preventDefault() call inside the _returnValue null check to prevent the default unload behavior only when a return value is explicitly set.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify the conditional logic correctly gates preventDefault() behind the _returnValue check
  • Confirm this change aligns with intended beforeunload behavior on web platforms
  • Check for any test coverage updates needed for this control flow change

Poem

A rabbit hops through the web so bright,
"Prevent less eagerly—only when right!"
The unload now waits for the signal to go,
A conditional dance, not a hasty preventDefault() show. 🐰✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: calling preventDefault() conditionally based on setWebReturnValue enablement, which aligns with the changeset's control flow modification and the PR's objective to fix browser dialog behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @saierd, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug in the web implementation of the window close plugin. Previously, the browser's default unload behavior was always prevented, leading to an inability to disable the 'stay on page' dialog. The change ensures that this prevention mechanism is only activated when the plugin has been explicitly configured to provide a return value for the unload event, restoring the intended control over the browser's behavior.

Highlights

  • Conditional preventDefault() Call: The preventDefault() method on the BeforeUnloadEvent is now only invoked if a return value has been explicitly set via setWebReturnValue. This resolves an issue where the browser's 'stay on page' dialog would always appear, even when not intended.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an issue where the 'before unload' confirmation dialog was always being shown on the web, regardless of whether it was configured. The change correctly moves the preventDefault() call inside the conditional check for _returnValue != null. This ensures that the confirmation dialog is only triggered when setWebReturnValue has been explicitly called with a non-null value, effectively fixing the bug and giving developers the expected control over this behavior. The implementation is correct and I approve of the change.

Copy link

@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)
lib/flutter_window_close_web.dart (1)

12-13: Docstring plugin name nit

The doc comment still says “FlutterHi plugin”, which doesn’t match the current plugin name. Consider updating it for clarity when you next touch this file.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce4a7a6 and 4ea282f.

📒 Files selected for processing (1)
  • lib/flutter_window_close_web.dart (1 hunks)
🔇 Additional comments (1)
lib/flutter_window_close_web.dart (1)

26-37: Behavior change correctly gates preventDefault() on explicit _returnValue

Moving unloadEvent.preventDefault() inside the _returnValue != null guard ensures the unload dialog is only triggered when the plugin has been explicitly enabled via setWebReturnValue. This matches the PR description and avoids the previous “always show dialog when plugin is active” behavior, while preserving the existing returnValue logic.

Looks good and should be safe given _returnValue is only set through setWebReturnValue.

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.

1 participant