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

Using Dexie prevents the browser from enabling the bfcache because of the usage of BroadcastChannel #1776

Closed
slevy85 opened this issue Aug 3, 2023 · 4 comments

Comments

@slevy85
Copy link

slevy85 commented Aug 3, 2023

Hello,

I noticed that the browser wasn't using bfcache with my app, lighthouse was giving me the error message:

The page cannot be cached because it has a BroadcastChannel instance with registered listeners.

I found out that Dexie was using the BroadcastChannel, after removing it, the bfcache was working.

My question is, can we make the usage of the broadcast channel optional ? Or eventually can we delay the opening of the BroadcastChannel until Dexie opens the connection to the database?
For me it will mean that most of the users will be able to experiment the bfcache, and only a few users (who need Dexie) won't.

Thank you for your help.

@slevy85
Copy link
Author

slevy85 commented Aug 3, 2023

Here is a github issue that relates between bfcache and BroadcastChannel whatwg/html#7253

@dfahlander
Copy link
Collaborator

Thanks for sharing this information which wasn't something I was aware of. The issue seems to be broader than just BroadcastChannel - the indexedDB connection itself would prevent bfcache according to https://web.dev/bfcache/#always-close-open-connections-before-the-user-navigates-away

I suppose a correct solution would be to listen to the pagehide and pageshow events to take down BroadcastChannel and IDBConnections and bring them up again in the pageshow event if I understood the article correctly.

I suppose this would be doable but it would have to be done carefully in a prerelase at some point.

@dsherley9
Copy link

I'm running into this exact problem as well. Firefox, Chrome, and Edge all will ignore the bfcache, because of the registered listeners. However, it appears Safari doesn't behave this way and will still attempt to load the page from the bfcache regardless. The IndexedDB just ends up being in a corrupt state. Would be nice to opt into using the Service Worker implementation via configuration or have some sort of logic implemented to handle this.

@dfahlander
Copy link
Collaborator

Solved in dexie@4.0.1-beta.7 by subscribing to pagehide/pageshow and taking down BroadcastChannel and IDB connections. I've been able to verify that the BroadcastChannel isn't blocking the bfcache anymore.

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

No branches or pull requests

3 participants