Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: if a web plugin is used without await, multiple instances get created #6938

Open
jcesarmobile opened this issue Sep 26, 2023 · 1 comment
Labels
platform: web type: bug A confirmed bug report

Comments

@jcesarmobile
Copy link
Member

Bug Report

Capacitor Version

5.x

Platform(s)

web

Current Behavior

If a web plugin is used without await, multiple instances get created, which causes problems for addListener calls.
See ionic-team/capacitor-plugins#1699 for more details.

Expected Behavior

A single instance of the plugin should be created

Code Reproduction

https://github.com/miqmago/capacitor-plugins-issue-1699

Other Technical Details

If not using await on the plugin calls, the plugin's registerPlugin function gets executed multiple times, and the way we have created the plugins a new plugin gets created every time.
Note that the web's registerPlugin doesn't get executed multiple times, the plugin is only registered once on web as expected and it already has a "singleton" like mechanism that would return an existing plugin if it was already created, but the plugin's registerPlugin multiple executions don't result in multiples web runtime registerPlugin calls.

Additional Context

While this could be fixed plugin by plugin (like the proposed "singleton" in the linked issue or creating the web plugin outside of the registerPlugin call so it always returns the same, I think we should try to fix it in @capacitor/core so it get fixed for all plugins without additional changes on them.

@ionitron-bot ionitron-bot bot added the triage label Sep 26, 2023
@ionitron-bot ionitron-bot bot removed the triage label Sep 26, 2023
@jcesarmobile jcesarmobile added the type: bug A confirmed bug report label Sep 26, 2023
@ionitron-bot
Copy link

ionitron-bot bot commented Sep 26, 2023

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: web type: bug A confirmed bug report
Projects
Status: Backlog 🤖
Development

No branches or pull requests

2 participants