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]: Preload config error #146

Open
dalist1 opened this issue May 24, 2024 · 6 comments
Open

[Bug]: Preload config error #146

dalist1 opened this issue May 24, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@dalist1
Copy link

dalist1 commented May 24, 2024

Provide environment information

The service worker navigation preload request was cancelled before 'preloadResponse' settled. If you intend to use 'preloadResponse', use waitUntil() or respondWith() to wait for the promise to settle.

Which project is this issue for?

serwist

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

.

To reproduce

Error comes out from this config seems like:

const serwist = new Serwist({
precacheEntries: self.__SW_MANIFEST,
skipWaiting: true,
clientsClaim: true,
navigationPreload: true,
runtimeCaching: defaultCache,
})

Describe the bug

Add the above config, and check the console.

Expected behavior

No error is supposed to come up in the console, not sure where the issue exactly lies, here's my nextjs info:

Operating System:
Platform: linux
Arch: x64
Version: #202404301715 SMP PREEMPT_DYNAMIC Tue Apr 30 17:56:17 UTC 2024
Available memory (MB): 64042
Available CPU cores: 16
Binaries:
Node: 21.7.3
npm: 10.5.0
Yarn: 1.22.22
pnpm: 9.1.1
Relevant Packages:
next: 15.0.0-rc.0 // Latest available version is detected (15.0.0-rc.0).
eslint-config-next: 15.0.0-rc.0
react: 19.0.0-rc-f994737d14-20240522
react-dom: 19.0.0-rc-f994737d14-20240522
typescript: 5.4.5
Next.js Config:
output: N/A

Screenshots (if relevant)

.

Additional information (if relevant)

.

@dalist1 dalist1 added bug Something isn't working triage New issues get this label, remove it after triage labels May 24, 2024
@DuCanhGH
Copy link
Member

@dalist1 huh, not sure how that can happen with defaultCache. Serwist always handles preloaded responses when intercepting network requests.

It may be the case that some navigation requests got through the service worker (i.e when no route matches the request), resulting in the preloaded responses being discarded. You may add serwist.setDefaultHandler to check this.

@gsemyong
Copy link

Having the same issue. It does appear that page is getting preloaded correctly in a production build though.

@DuCanhGH
Copy link
Member

@gsemyong ah...

In development mode, defaultCache is set to undefined. This causes all requests to not be handled by the service worker, resulting in the preloaded responses being discarded. Well, I guess we could add a fallback NetworkFirst strategy for defaultCache there then.

@gsemyong
Copy link

@DuCanhGH I've changed the snippet to be

const serwist = new Serwist({
  precacheEntries: self.__SW_MANIFEST,
  skipWaiting: true,
  clientsClaim: true,
  navigationPreload: true,
  runtimeCaching:
    defaultCache.length === 0
      ? [
          {
            matcher: () => true,
            handler: new NetworkFirst(),
          },
        ]
      : defaultCache,
});

Seems like the warnings are gone. Is that what you meant?

@DuCanhGH
Copy link
Member

@gsemyong ...yep. That's what I meant.

@dalist1
Copy link
Author

dalist1 commented May 27, 2024

guys, I haven't had time to play around with this recently but will definitely try the networkFirst fallback strategy out later.

thanks @gsemyong

@DuCanhGH I've changed the snippet to be

const serwist = new Serwist({
  precacheEntries: self.__SW_MANIFEST,
  skipWaiting: true,
  clientsClaim: true,
  navigationPreload: true,
  runtimeCaching:
    defaultCache.length === 0
      ? [
          {
            matcher: () => true,
            handler: new NetworkFirst(),
          },
        ]
      : defaultCache,
});

Seems like the warnings are gone. Is that what you meant?

@DuCanhGH DuCanhGH removed the triage New issues get this label, remove it after triage label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants