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

Web and native lifecycle event mismatch when called on a background tab #33

Open
adampal opened this issue Mar 26, 2024 · 2 comments · May be fixed by #36
Open

Web and native lifecycle event mismatch when called on a background tab #33

adampal opened this issue Mar 26, 2024 · 2 comments · May be fixed by #36

Comments

@adampal
Copy link

adampal commented Mar 26, 2024

The web BridgeComponent connect event fires when the element appears on a page. However, if this happens on a background tab, the native BridgeComponent will ignore any messages sent because the destination is not yet active. This means the native component is not initialised.

When the user switches to the tab that has the component, the web connect event has already fired and won't happen again. There is no equivalent to viewWillLoad for the web component so I have no way of initialising the component when the user switches to the tab. You also can't use the native onViewDidLoad lifecycle event because the native component isn't initialised until it receives an event from the web so onViewDidLoad is never called.

I think I understand why we're ignoring events on an inactive destination. However maybe we could make an exception for connect events. The connect event is often used to initialise the component and set some base state ready for when the user starts interacting with it. In most cases this should be ok (preferable even?) to run on a background tab so by the time the user wants to interact with the component it has already set any state it needs.

I'd love to know if anyone else has hit this issue or if there's any recommended way of handling this situation.

If you think allowing connected events on a not-active destination is a good idea, I'm happy to draft up a PR with the change.

@adampal
Copy link
Author

adampal commented Apr 24, 2024

We've been running a custom version of strada-ios in production for the last month or so with the above changes. Just adding this here in case it's helpful to someone:

https://github.com/adampal/strada-ios

@joemasilotti
Copy link
Member

Thanks @adampal, can you please open a PR so we can review?

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

Successfully merging a pull request may close this issue.

2 participants