Repository navigation
Conversation
When a plugin registers a lazy implementation such as
`web: () => import('./web').then((m) => new m.MyWeb())`, every call made
before the first load settled ran the loader again. Calling addListener()
twice without awaiting created two instances, and only the last one was
kept, so listeners added to the others never fired.
Share the pending load between those calls. A load that fails is still
retried on the next call.
Fixes ionic-team#6938
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
registerPlugin()loads a lazy implementation such asweb: () => import('./web').then((m) => new m.MyWeb())on the first method call. Calls made before that load finishes each ran the loader again, so the plugin got several instances and only the last one was kept. Listeners added on the earlier instances never fire.This shares the pending load between those calls. If the load fails, the next call retries, as before.
Change Type
Rationale / Problems Fixed
Fixes #6938 (from ionic-team/capacitor-plugins#1699: calling
addListener()twice withoutawaiton web loses the first listener).Tests or Reproductions
Added two tests to
core/src/tests/plugin.spec.ts: twoaddListener()calls withoutawaiton a lazy web plugin now create one instance and both listeners fire (the first test fails onmainwith 2 instances), and a lazy implementation that fails to load is retried on the next call.npm testincorepasses.Platforms Affected