Skip to content

fix: added EventsOffAll to windows.runtime and updated the frontend runtime wrapper#4254

Merged
leaanthony merged 5 commits into
wailsapp:masterfrom
FrancescoLuzzi:bugfix/3136_export_EventsOffAll
Aug 2, 2025
Merged

fix: added EventsOffAll to windows.runtime and updated the frontend runtime wrapper#4254
leaanthony merged 5 commits into
wailsapp:masterfrom
FrancescoLuzzi:bugfix/3136_export_EventsOffAll

Conversation

@FrancescoLuzzi

@FrancescoLuzzi FrancescoLuzzi commented Apr 29, 2025

Copy link
Copy Markdown
Contributor

Description

Add EventsOffAll to window.runtime and fix the relative frontend bindings

Fixes #3136

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • New Features

    • Added a new function to the runtime API that allows removal of all event listeners at once.
  • Documentation

    • Updated the changelog to document the addition of the new function to the runtime API.

@coderabbitai

coderabbitai Bot commented Apr 29, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce the EventsOffAll function into the runtime API, making it available for import and use. This involves updating the desktop runtime to export the function, adding a wrapper for external access, documenting the change in the changelog, and refactoring the internal implementation for style consistency.

Changes

Cohort / File(s) Change Summary
Expose EventsOffAll in Desktop Runtime
v2/internal/frontend/runtime/desktop/main.js
Imported and exported EventsOffAll in the runtime API; minor formatting and indentation updates.
Wrapper Export for EventsOffAll
v2/internal/frontend/runtime/wrapper/runtime.js
Added an exported EventsOffAll() function that calls the runtime's EventsOffAll.
Changelog Update
website/src/pages/changelog.mdx
Added entry for EventsOffAll in the v2.10.2 changelog, referencing issue #3136 and contributor.
Refactor EventsOffAll Implementation
v2/internal/frontend/runtime/desktop/events.js
Refactored EventsOffAll to use forEach instead of a for loop for listener removal; no logic change.
Comprehensive Desktop Runtime Refactor
v2/internal/frontend/runtime/runtime_prod_desktop.js
Reorganized and renamed internal runtime functions and variables; added EventsOffAll method; preserved API and logic.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application Code
    participant Wrapper as runtime.js Wrapper
    participant Desktop as Desktop Runtime (main.js)
    participant Events as Events Module (events.js)

    App->>Wrapper: import { EventsOffAll } from "runtime"
    App->>Wrapper: EventsOffAll()
    Wrapper->>Desktop: window.runtime.EventsOffAll()
    Desktop->>Events: EventsOffAll()
    Events->>Events: Remove all event listeners
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Assessment against linked issues

Objective Addressed Explanation
Export EventsOffAll function in the runtime API for external import and use (#3136)
Ensure EventsOffAll can be imported alongside other runtime functions without error (#3136)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found.

Poem

A bunny hops with nimble grace,
"EventsOffAll" now finds its place!
No more import woes at all,
Listeners gone at your call.
The changelog sings, the wrapper's neat—
This patch is truly quite a treat!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6fa22d5 and 71aa8a5.

📒 Files selected for processing (1)
  • v2/internal/frontend/runtime/runtime_prod_desktop.js (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (3)
website/src/pages/changelog.mdx (1)

19-20: Fill in the placeholder PR link before merging

??? should be replaced with the actual pull-request number (4254).
Leaving placeholders in the changelog reduces traceability for users who rely on the document to navigate to the relevant discussions.

- - Added EventsOffAll to `windows.runtime`, fixes [#3136](https://github.com/wailsapp/wails/issues/3136) [PR](https://github.com/wailsapp/wails/pull/???) by [@FrancescoLuzzi](https://github.com/FrancescoLuzzi)
+ - Added EventsOffAll to `windows.runtime`, fixes [#3136](https://github.com/wailsapp/wails/issues/3136) [PR](https://github.com/wailsapp/wails/pull/4254) by [@FrancescoLuzzi](https://github.com/FrancescoLuzzi)
v2/internal/frontend/runtime/wrapper/runtime.js (1)

59-62: Minor slice-usage quirk can be simplified

let args = [eventName].slice.call(arguments); works, but the eventName array element is discarded immediately. Using Array.prototype.slice is clearer and avoids the superfluous allocation.

-    let args = [eventName].slice.call(arguments);
+    let args = Array.prototype.slice.call(arguments);
v2/internal/frontend/runtime/desktop/main.js (1)

91-99: Replace delete with undefined-assignment to avoid hidden perf costs

Static-analysis flagged two delete operations. In V8 (Chromium/WebView2) delete triggers dictionary-mode transitions and de-opts hidden classes. Setting the property to undefined preserves performance while achieving the same result.

-    delete window.wails.SetBindings;
+    window.wails.SetBindings = undefined;

 ...

-    delete window.wailsbindings;
+    window.wailsbindings = undefined;
🧰 Tools
🪛 Biome (1.9.4)

[error] 93-93: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 98-98: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d1838f4 and 49de19c.

📒 Files selected for processing (4)
  • v2/internal/frontend/runtime/desktop/main.js (1 hunks)
  • v2/internal/frontend/runtime/runtime_prod_desktop.js (1 hunks)
  • v2/internal/frontend/runtime/wrapper/runtime.js (1 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
v2/internal/frontend/runtime/desktop/main.js

[error] 93-93: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 98-98: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

v2/internal/frontend/runtime/runtime_prod_desktop.js

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments (3)
v2/internal/frontend/runtime/wrapper/runtime.js (1)

51-53: API surface extended correctly – remember to update typings

EventsOffAll is now exposed through the wrapper – great!
Please ensure the corresponding TypeScript declaration file (runtime.d.ts) is updated, otherwise TS consumers will not “see” the new function.

No functional issues spotted.

v2/internal/frontend/runtime/desktop/main.js (1)

55-61: EventsOffAll correctly wired into the runtime object

Import + export chain looks consistent with the other event helpers. Nice work.

v2/internal/frontend/runtime/runtime_prod_desktop.js (1)

1-1: Minified build artefact – no source changes to review

This file is the generated, minified production bundle. Manual edits will be overwritten by the build pipeline, so no review feedback is required here.

🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

@FrancescoLuzzi FrancescoLuzzi force-pushed the bugfix/3136_export_EventsOffAll branch from 49de19c to c576cb4 Compare April 29, 2025 17:46
@FrancescoLuzzi FrancescoLuzzi force-pushed the bugfix/3136_export_EventsOffAll branch from c576cb4 to 1de61fb Compare April 29, 2025 17:51

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (5)
v2/internal/frontend/runtime/desktop/main.js (3)

16-18: Import of EventsOffAll looks correct – minor ordering nit

The new symbol is imported right after EventsOff, which is semantically fine.
If you keep the list roughly alphabetical (or grouped by “Off/OffAll/On/Once”) it becomes easier to scan when adding/removing future helpers.


55-61: Clarify the distinction between EventsOff and EventsOffAll

EventsOffAll is now exposed alongside EventsOff. Note that EventsOff() without arguments previously acted as a “remove-all” helper in several client snippets. Introducing a dedicated EventsOffAll may create two different public ways of clearing listeners or, worse, break older code that relied on the empty-arg behaviour of EventsOff.

  1. Verify how EventsOff behaves when called with no arguments in events.js.
  2. If both APIs coexist, consider:
    • Deprecating the empty-arg variant of EventsOff and documenting EventsOffAll as the canonical helper, or
    • Keeping only one public method and aliasing the other for backward compatibility (EventsOffAll = EventsOff).

This avoids confusion for downstream users and reduces surface area.


91-99: Avoid the delete operator for hot-path globals

Biome flags both delete calls as a performance hit. Replacing them with an undefined assignment prevents the hidden-class de-opt in V8 while achieving the same GC behaviour.

-    window.wails.SetBindings(window.wailsbindings);
-    delete window.wails.SetBindings;
+    window.wails.SetBindings(window.wailsbindings);
+    window.wails.SetBindings = undefined;
...
-    delete window.wailsbindings;
+    window.wailsbindings = undefined;

Because this runs at startup it’s not critical, yet it’s a free micro-optimisation and silences the linter.

🧰 Tools
🪛 Biome (1.9.4)

[error] 93-93: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 98-98: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

v2/internal/frontend/runtime/runtime_prod_desktop.js (2)

1-1: EventsOffAll correctly wired, but confirm listener-addition race

EventsOffAll (z) iterates over Object.keys(w) once and then calls p() to unregister each event.
If new listeners are registered during the loop they will survive because Object.keys was taken before the loop.
That’s fine for most use-cases, but if callers expect a strict “no listener survives” guarantee, you may want to:

function z() {
  // keep draining until empty – protects against races
  let names;
  while ((names = Object.keys(w)).length) {
    for (const n of names) p(n);
  }
}

Only worth changing if your runtime allows listener registration from inside EventsOff/OffAll callbacks.

🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


1-1: Same delete pattern as in main.js

For consistency and micro-perf reasons, consider the undefined assignment approach here as well (e.g. the two delete statements right after SetBindings).

🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 49de19c and c576cb4.

📒 Files selected for processing (4)
  • v2/internal/frontend/runtime/desktop/main.js (1 hunks)
  • v2/internal/frontend/runtime/runtime_prod_desktop.js (1 hunks)
  • v2/internal/frontend/runtime/wrapper/runtime.js (1 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • website/src/pages/changelog.mdx
🚧 Files skipped from review as they are similar to previous changes (1)
  • v2/internal/frontend/runtime/wrapper/runtime.js
🧰 Additional context used
🪛 Biome (1.9.4)
v2/internal/frontend/runtime/desktop/main.js

[error] 93-93: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 98-98: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

v2/internal/frontend/runtime/runtime_prod_desktop.js

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
v2/internal/frontend/runtime/runtime_prod_desktop.js (1)

1-1: Consider using optional chaining for safer property access.

The static analysis identified several instances where optional chaining could be used to make property access safer, particularly when checking for existence of properties before accessing nested ones.

For example, in places where you check for window.chrome?.webview?.postMessageWithAdditionalObjects, using the optional chaining operator consistently would make the code more robust.

🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c576cb4 and 1de61fb.

📒 Files selected for processing (4)
  • v2/internal/frontend/runtime/desktop/main.js (6 hunks)
  • v2/internal/frontend/runtime/runtime_prod_desktop.js (1 hunks)
  • v2/internal/frontend/runtime/wrapper/runtime.js (1 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • website/src/pages/changelog.mdx
  • v2/internal/frontend/runtime/wrapper/runtime.js
  • v2/internal/frontend/runtime/desktop/main.js
🧰 Additional context used
🪛 Biome (1.9.4)
v2/internal/frontend/runtime/runtime_prod_desktop.js

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments (4)
v2/internal/frontend/runtime/runtime_prod_desktop.js (4)

50-52: The new EventsOffAll function is correctly implemented.

This new function properly iterates through all event keys in the event store and calls the event removal function on each key, effectively removing all registered event listeners at once.


281-281: Correctly exported the new EventsOffAll function in the runtime API.

The EventsOffAll function (function z() in the minified code) is properly exposed in the window.runtime object, making it available to consumers of the runtime API.


1-2: Overall implementation of the EventsOffAll feature is complete and consistent.

The PR successfully implements the EventsOffAll function to remove all event listeners at once, as required by issue #3136. The implementation is consistent with the existing event system pattern and correctly integrates with the runtime API.

🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


280-280:

Details

✅ Verification successful

Verify that the changed Environment function maintains backward compatibility.

The implementation of the Environment function appears to have changed from returning a direct promise to invoking a Wails command. Ensure this change doesn't break existing code that depends on the previous behavior.


🏁 Script executed:

#!/bin/bash
# Search for usages of the Environment function in the codebase
rg -A 3 "runtime\.Environment\(" --type js

Length of output: 4929


🏁 Script executed:

#!/bin/bash
echo "Files in v2/internal/frontend/runtime:"
ls v2/internal/frontend/runtime

echo -e "\n--- runtime_prod_desktop.js (lines 260-300) ---"
sed -n '260,300p' v2/internal/frontend/runtime/runtime_prod_desktop.js

echo -e "\n--- runtime_dev_desktop.js (lines 260-300) ---"
if [ -f v2/internal/frontend/runtime/runtime_dev_desktop.js ]; then
  sed -n '260,300p' v2/internal/frontend/runtime/runtime_dev_desktop.js
else
  echo "runtime_dev_desktop.js not found"
fi

Length of output: 812


🏁 Script executed:

#!/bin/bash
# Show all lines containing "Environment" in runtime_prod_desktop.js with context
grep -n -C3 "Environment" v2/internal/frontend/runtime/runtime_prod_desktop.js || echo "No occurrences found"

Length of output: 11683


Verify Environment Backward Compatibility
The Environment API still returns a Promise, now via the internal a(":wails:Environment") call. All existing calls through the wrapper (wrapper/runtime.js: export function Environment() { return window.runtime.Environment() }) remain unchanged, so code depending on .then(...) or await Environment() will behave identically.

No code changes are required. Please ensure any custom typing or documentation expecting a Promise is in place.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
v2/internal/frontend/runtime/runtime_prod_desktop.js (1)

1-1: Consider switching to optional chaining in future refactors.

There are multiple instances in the code where optional chaining could be used to improve readability and robustness, according to the static analysis hints.

-w[t]?.slice()||[]
+w[t]?.slice()??[]

-window.chrome?.webview?.postMessageWithAdditionalObjects!=null
+window.chrome?.webview?.postMessageWithAdditionalObjects!=null

-window.chrome?.webview?.postMessageWithAdditionalObjects
+window.chrome?.webview?.postMessageWithAdditionalObjects
🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eaad54c and d12721b.

📒 Files selected for processing (2)
  • v2/internal/frontend/runtime/desktop/events.js (1 hunks)
  • v2/internal/frontend/runtime/runtime_prod_desktop.js (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
v2/internal/frontend/runtime/runtime_prod_desktop.js

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments (3)
v2/internal/frontend/runtime/desktop/events.js (2)

193-193: The loop condition is now more conventional.

Changing from i !== eventNames.length to i < eventNames.length makes the iteration pattern more standard and easier to understand at a glance.


191-196: Well-implemented EventsOffAll function.

This function properly unregisters all event listeners by iterating through all event names and calling removeListener on each one. The implementation is clean and follows the same pattern used in other event-related functions in this file.

v2/internal/frontend/runtime/runtime_prod_desktop.js (1)

1-1: The EventsOffAll function is successfully exposed in the runtime API.

The EventsOffAll function (implemented as z()) is now correctly exposed in the window.runtime object alongside other event management functions, which satisfies the PR objective.

🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

@FrancescoLuzzi FrancescoLuzzi force-pushed the bugfix/3136_export_EventsOffAll branch from d12721b to 21e0bfa Compare May 12, 2025 20:50
@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (3)
v2/internal/frontend/runtime/runtime_prod_desktop.js (3)

353-358: Consider performance impact of using delete operator

The static analysis hints suggest avoiding the delete operator for performance reasons. In functions like g(e) that use delete w[e], consider using an assignment to undefined instead (e.g., w[e] = undefined).

This change is optional but might offer a slight performance improvement, especially in performance-sensitive event handling code.

function g(e){
-  delete w[e],
+  w[e] = undefined,
   window.WailsInvoke("EX"+e)
}

240-242: Optional chaining opportunity for better readability

Multiple places in the code check for the existence of objects before accessing their properties. Consider using optional chaining for cleaner code, which is supported in modern browsers.

- function V(){return window.chrome?.webview?.postMessageWithAdditionalObjects!=null}
+ function V(){return window.chrome?.webview?.postMessageWithAdditionalObjects != null}

- function Me(e,t,n){window.chrome?.webview?.postMessageWithAdditionalObjects&&chrome.webview.postMessageWithAdditionalObjects(`file:drop:${e}:${t}`,n)}
+ function Me(e,t,n){window.chrome?.webview?.postMessageWithAdditionalObjects?.(`file:drop:${e}:${t}`,n)}

Also applies to: 257-257


1-1: Consider adding JSDoc comments for the new EventsOffAll function

While the implementation is correct, consider adding JSDoc comments to document the purpose and behavior of the new EventsOffAll function. This would improve maintainability and help other developers understand its intended use.

🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d12721b and 21e0bfa.

📒 Files selected for processing (2)
  • v2/internal/frontend/runtime/desktop/events.js (1 hunks)
  • v2/internal/frontend/runtime/runtime_prod_desktop.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • v2/internal/frontend/runtime/desktop/events.js
🧰 Additional context used
🪛 Biome (1.9.4)
v2/internal/frontend/runtime/runtime_prod_desktop.js

[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1-1: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1-1: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1-1: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments (3)
v2/internal/frontend/runtime/runtime_prod_desktop.js (3)

52-52: Addition of EventsOffAll function implements requested functionality

The new function z() implements the EventsOffAll functionality correctly by iterating through all registered event keys and removing each event listener. This properly addresses issue #3136 mentioned in the PR objectives.


376-376: EventsOffAll is properly exposed in the runtime API

The function is correctly exported as part of the window.runtime object, making it available for public use alongside other event-related methods.


52-52:

Details

✅ Verification successful

Verify integration with other components

The implementation looks correct, but let's ensure it works properly with other components that might rely on the events system.

Also applies to: 376-376


🏁 Script executed:

#!/bin/bash
# Check if the EventsOffAll function is used anywhere else in the codebase
echo "Searching for any usage of EventsOffAll across the codebase..."
rg "EventsOffAll" --type js

# Check if there are any tests for this functionality
echo "Checking for tests related to EventsOffAll..."
rg "EventsOffAll" --type js --glob "*test*"

Length of output: 13289


Integration of EventsOffAll Verified

  • EventsOffAll is referenced in:
    • v2/internal/frontend/runtime/wrapper/runtime.js
    • v2/internal/frontend/runtime/desktop/events.js
    • v2/internal/frontend/runtime/desktop/main.js
    • Both runtime_debug_desktop.js and runtime_prod_desktop.js
  • Covered by unit tests in v2/internal/frontend/runtime/desktop/events.test.js

All integration points are exercised and tested; no further action required.

…_export_EventsOffAll

# Conflicts:
#	v2/internal/frontend/runtime/runtime_debug_desktop.js
#	v2/internal/frontend/runtime/runtime_prod_desktop.js
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 2, 2025
@leaanthony leaanthony enabled auto-merge (squash) August 2, 2025 07:15
@sonarqubecloud

sonarqubecloud Bot commented Aug 2, 2025

Copy link
Copy Markdown

@leaanthony leaanthony merged commit ebe377f into wailsapp:master Aug 2, 2025
6 of 9 checks passed
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 2, 2025
@leaanthony

Copy link
Copy Markdown
Member

@FrancescoLuzzi - Thanks for this! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

does not provide an export named 'EventsOffAll'

2 participants