Web: Call preventDefault only when the plugin was enabled explicitly 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 166df017c8d050e5dcb58a92e189ce177dde6477.
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.
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_returnValuecheck - 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.
Comment @coderabbitai help to get the list of available commands and usage tips.
Summary of Changes
Hello @saierd, I'm Gemini Code Assist[^1]! 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 theBeforeUnloadEventis now only invoked if a return value has been explicitly set viasetWebReturnValue. 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 :thumbsup: and :thumbsdown: 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.
[^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.