Skip to content

Chore: remove dead code in CommonDB#18107

Merged
Lemonexe merged 2 commits intodevelopfrom
chore/remove-BroadcastChannel-lib
Apr 3, 2025
Merged

Chore: remove dead code in CommonDB#18107
Lemonexe merged 2 commits intodevelopfrom
chore/remove-BroadcastChannel-lib

Conversation

@Lemonexe
Copy link
Copy Markdown
Contributor

@Lemonexe Lemonexe commented Apr 3, 2025

Description

  • remove broadcast message events for Storage operations
    • they were never listened to anywhere in the repo!
      • would expect it to communicate with some iframe, web workers, or in-between Suite Web tabs
    • unclear what purpose this feature had at all? Orig PR didn't say. Maybe just code copied from internet, idk.
  • remove now-obsolete IDB workaround specifically for Firefox in Incognito mode

Related Issue

Resolve #18106

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 3, 2025

🔍🌐 Suite Web test results: View in Currents

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 3, 2025

🔍🖥️ Suite Desktop test results: View in Currents

"@trezor/env-utils": "workspace:*",
"@trezor/eslint": "workspace:*",
"@trezor/utils": "workspace:*",
"broadcast-channel": "^7.0.0",
Copy link
Copy Markdown
Contributor Author

@Lemonexe Lemonexe Apr 3, 2025

Choose a reason for hiding this comment

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

  • This lib is what led me to find this obsolete code at all (I was about to bump it)
  • It' super weird because BroadcastChannel is natively offerred by browsers, and we rely on the native implementation at multiple places!
  • only here we use this polyfill lib for old browsers – meaning Chrome & Firefox < 2016 & Safari < 2022, lol

r.onsuccess = () => {
indexedDB.deleteDatabase('test');
resolve(true);
};
Copy link
Copy Markdown
Contributor Author

@Lemonexe Lemonexe Apr 3, 2025

Choose a reason for hiding this comment

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

This workaround is not needed anymore. The bug linked in comment was marked resolved 5 yrs ago.
I also tested it myself in Firefox Private window at any https page, not about:blank or file:/// etc.:

const r = indexedDB.open('test');
r.onerror = () => console.log('NOT SUPPORTED');
r.onsuccess = () => {indexedDB.deleteDatabase('test'); console.log('WORKS'); };

onChange = (handler: (event: StorageMessageEvent<TDBStructure>) => any) => {
// listens to the channel. On receiving a message triggers the handler func
this.broadcastChannel.onmessage = handler;
return Promise.resolve(isSupported && !this.blocking && !this.blocked);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

At first I thought that removing the FF workaround can reduce this whole chain of function from async to sync.
Yes it can, but it's not practical!
In storageActions there are 37 occurrences of await db.isAccessible(). These functions have to consistently return Promise, but without await you'd have to remove async, and it would be a lot of boilerplate code to Promise.resolve() everything to ensure they always return a Promise 🤦

this.notify(store, keys);
});
);
const aggregatedPromise: Promise<void> = promisesOfItems.then(() => {});
Copy link
Copy Markdown
Contributor Author

@Lemonexe Lemonexe Apr 3, 2025

Choose a reason for hiding this comment

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

this fn is expected to return Promise<void>, not Promise<void[]> (would fail downstream in suite).
Naming the function makes this clear without code commentary

@Lemonexe
Copy link
Copy Markdown
Contributor Author

Lemonexe commented Apr 3, 2025

Failing test is confirmed to be broken (slack)

@Lemonexe Lemonexe marked this pull request as ready for review April 3, 2025 08:37
@Lemonexe Lemonexe requested a review from matejkriz as a code owner April 3, 2025 08:37
@Lemonexe Lemonexe requested a review from marekrjpolak April 3, 2025 08:39
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 3, 2025

Walkthrough

The pull request removes dependencies and simplifies functionality across the storage package. In the package configuration, the dependencies on @trezor/env-utils and broadcast-channel have been removed. In the native and web implementations of the CommonDB class, methods related to storage change notifications and broadcasting (such as notify and onChange) have been eliminated, and asynchronous checks have been streamlined to return either static values or simplified Promise structures. The modifications also include updates to TypeScript type declarations by removing interfaces related to storage messages (StorageUpdateMessage and StorageMessageEvent). Additionally, the project configuration has been updated by removing references to the eliminated dependencies, and the outdated dependencies documentation has been adjusted accordingly.


📜 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 0f0d0cf and 2bd35c9.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (8)
  • packages/suite-storage/package.json (0 hunks)
  • packages/suite-storage/src/native/index.ts (1 hunks)
  • packages/suite-storage/src/native/types/index.ts (0 hunks)
  • packages/suite-storage/src/web/index.ts (4 hunks)
  • packages/suite-storage/src/web/types/index.ts (0 hunks)
  • packages/suite-storage/tsconfig.json (0 hunks)
  • packages/suite/src/storage/definitions.ts (0 hunks)
  • scripts/list-outdated-dependencies/foundation-dependencies.txt (0 hunks)
💤 Files with no reviewable changes (6)
  • packages/suite-storage/tsconfig.json
  • scripts/list-outdated-dependencies/foundation-dependencies.txt
  • packages/suite/src/storage/definitions.ts
  • packages/suite-storage/package.json
  • packages/suite-storage/src/web/types/index.ts
  • packages/suite-storage/src/native/types/index.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/suite-storage/src/web/index.ts

[error] 192-192: void is confusing outside a return type or a type parameter.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: methods / core_in_popup
🔇 Additional comments (8)
packages/suite-storage/src/native/index.ts (3)

62-62: Method simplified to return constant value

The isDBAvailable static method has been simplified to directly return false instead of a more complex asynchronous implementation. This aligns with the PR objective of removing dead code.


64-68: Simplified return logic

The isSupported method has been updated to return a boolean directly instead of a Promise, consistent with the simplification pattern across the codebase.


70-75: Improved type safety with explicit return type

The isAccessible method now has an explicit return type Promise<boolean> and uses the synchronous isSupported result to create a resolved promise, maintaining the expected API contract while simplifying the implementation.

packages/suite-storage/src/web/index.ts (5)

68-68: Simplified IndexedDB availability check

The isDBAvailable static method has been simplified to directly check for the presence of IndexedDB across different contexts. This removes the Firefox-specific workaround that was mentioned in the previous comments, which is no longer needed as the bug was resolved 5 years ago.


70-80: Simplified isSupported implementation

The method now uses the simplified isDBAvailable method and properly stores the result in the instance variable. This maintains the same functionality while removing unnecessary complexity.


82-87: Improved type safety with explicit return type

The isAccessible method now has an explicit return type Promise<boolean> and uses the synchronous isSupported result to create a resolved promise. This approach maintains the Promise return type needed by the 37 callers in storageActions without requiring complex refactoring.


192-192: Added type annotation for clarity

The type annotation Promise<void[]> has been added for the result of Promise.all() to improve code clarity and type safety.

🧰 Tools
🪛 Biome (1.9.4)

[error] 192-192: void is confusing outside a return type or a type parameter.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)


207-210: Fixed return type to match expected Promise

The code now explicitly converts the Promise<void[]> result from Promise.all() to a Promise<void> to ensure the method returns the expected type, addressing a potential type mismatch issue that could cause problems downstream.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • 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
Copy Markdown
Contributor

@marekrjpolak marekrjpolak left a comment

Choose a reason for hiding this comment

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

Haven't tested, looks great tho. By the way, the trade deficit of +17 -158 lines is enormous so I'm gonna impose some tariffs on you.

image

@Lemonexe Lemonexe merged commit c4f2970 into develop Apr 3, 2025
76 of 77 checks passed
@Lemonexe Lemonexe deleted the chore/remove-BroadcastChannel-lib branch April 3, 2025 09:34
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.

Simplify CommonDB

2 participants