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] App fails to load in airplane mode #4831

Open
DirtyHairy opened this issue Oct 12, 2024 · 5 comments
Open

[BUG] App fails to load in airplane mode #4831

DirtyHairy opened this issue Oct 12, 2024 · 5 comments

Comments

@DirtyHairy
Copy link

DirtyHairy commented Oct 12, 2024

What happened?

If I start the app (with the service worker happy and running) the page will not load. Inspecting the web view shows that navigator.serviceWorker is not defined in this state.

How do we reproduce the behavior?

  1. Install app
  2. Launch and kill app
  3. Wait until the cache expires
  4. Launch app
  5. App fails to load and shows connection indicator

What do you expect to happen?

App loads

What environment were you using?

iOS 17.7

Additional context

To me it seem that WKWebView does not properly initialise the service worker / registration properly if the first page load fails. I was able to work around the issue by trying a second load with cachePolicy: .returnCacheDataElseLoad if the first load fails. This bug may be similar to #4649

You can check the code in my app for reference: https://github.com/cloudpilot-emu/cpe-shim-ios/blob/master/app/CloudpilotEmu/ViewController.swift

I can prepare a pull request against the iOS shim if you like 😏

@maiconcarraro
Copy link
Contributor

seems relevant to you @khmyznikov

@DirtyHairy
Copy link
Author

DirtyHairy commented Oct 12, 2024

I've debugged a bit more and it seems that setting cachePolicy: .returnCacheDataElseLoad not only allows the load to proceed, but all assets are apparently correctly served by the service worker. So it really looks like the lack of connectivity causing WKWebView to abort early without initialising the worker, and allowing it to load from the cache seems to fix it without any actual cache load.

@jgw96
Copy link
Contributor

jgw96 commented Oct 14, 2024

@DirtyHairy just to confirm, setting that fixed the issue?

@DirtyHairy
Copy link
Author

@DirtyHairy just to confirm, setting that fixed the issue?

Yeah, indeed, loading with cachePolicy: .returnCacheDataElseLoad fixes the issue, and checking the devtools suggests that nothing is actually loaded from cache if the service worker is installed.

However, I don't do that on first load, but only if the first load fails --- otherwise, if the service worker has not yet installed and my PWA changes sufficiently (i.e. script names changing and old versions being removed from the server) between the app being terminated and being restarted the service worker will never install and the user will be stuck with a broken version in the cache.

Unfortunately, I still get a delay when there is bad network coverage on the first attempt to load.

Copy link
Contributor

This issue has been marked as "needs attention 👋" since it has not been triaged for 7 days. Please triage the issue .

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

No branches or pull requests

3 participants