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]: getServerSideProps not triggered #74

Closed
mick-feller opened this issue Feb 12, 2024 · 7 comments
Closed

[Bug]: getServerSideProps not triggered #74

mick-feller opened this issue Feb 12, 2024 · 7 comments
Assignees
Labels
bug Something isn't working triage New issues get this label, remove it after triage

Comments

@mick-feller
Copy link

Provide environment information

package versions used:

"@serwist/next": "^8.4.4",
"@serwist/precaching": "^8.4.4",
"@serwist/sw": "^8.4.4",

Which project is this issue for?

@serwist/next

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

To reproduce

sw.js file:

import { defaultCache } from "@serwist/next/browser";
import { installSerwist } from "@serwist/sw";

// Anything random.
const revision = crypto.randomUUID();

installSerwist({
  // eslint-disable-next-line no-restricted-globals
  precacheEntries: self.__SW_MANIFEST,
  skipWaiting: true,
  clientsClaim: true,
  navigationPreload: true,
  runtimeCaching: defaultCache,
  fallbacks: {
    entries: [
      {
        url: "/offline",
        revision,
        matcher({ request }) {
          return request.destination === "document";
        },
      },
    ],
  },
});

next.config.js

const withSerwist = require("@serwist/next").default({
  cacheOnFrontEndNav: true,
  swSrc: "sw.js",
  swDest: "public/sw.js",
  reloadOnOnline: true,
  disable: process.env.NODE_ENV === "development", // to disable pwa in development
  // ... other options
});

Describe the bug

I recently moved to serwist from next-pwa as i'm slowly going to start migrating to app directory.

While i'm not in app directory yet i noticed that somehow when i do a route change in the browser it seems to pull a fully cached page back and not trigger getServerSideProps anymore and my data comes back empty that i expect to be there.

It's working all fine without service workers involved and with next-pwa this was working properly as well.

If i stay on the page and then actually refresh the browser all the data shows up.

I also tried setting navigationPreloa, clientsClaim and cacheOnFrontEndNav to false without much success.

minimal repo will be tough this seems to also only happen when i run nextjs build. if i enable service worker in local dev environment everything works just fine.

Expected behavior

i expect that my data still comes back from getServerSideProps when a nextjs Link component is clicked.

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

@mick-feller mick-feller added bug Something isn't working triage New issues get this label, remove it after triage labels Feb 12, 2024
@mick-feller
Copy link
Author

so after doing some digging reverting back to next-pwa i was seeing the same issues show up there. it has to do with the cache strategy in the service worker that is being used there, so maybe this helps with this issue as well but this is what fixed it for me for next-pwa:
vercel/next.js#51454

@DuCanhGH
Copy link
Member

@mick-feller oh, thanks for investigating! This behaviour will be changed in v9.

@mick-feller
Copy link
Author

@DuCanhGH awesome looking forward to it. more then happy to test this as I want to get off next-pwa sooner then later to clean up some snyk security reports.

@DuCanhGH
Copy link
Member

@mick-feller will most likely come with 9.0.0-preview.4! You can use Serwist preview for now, then migrate back to stable later. Up to you, though.

@mick-feller
Copy link
Author

Once I get a chance I'll try it out! Thanks!

@DuCanhGH
Copy link
Member

@mick-feller should be fixed in the latest preview :) Closing this issue.

@mick-feller
Copy link
Author

@DuCanhGH upgraded to serwist preview and working like a charm! thanks for the quick fix!

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

No branches or pull requests

2 participants