next-pwa: dynamicStartUrl Not Working As Expected on Mobile
Provide environment information
"next": "13.4.12", "@ducanh2912/next-pwa": "^9.5.0",
Whose documentation is this feedback for?
Describe the problem
this is my current config for the pwa I’m trying to create.
const withPWA = require("@ducanh2912/next-pwa").default({
disable: false,
dest: "public",
cacheOnFrontEndNav: false,
cacheStartUrl: true,
dynamicStartUrl: true,
workboxOptions: {
skipWaiting: true,
},
});
My startUrl or “/” is an async server component where I make a fetch to see whether a user exists based on a token (retrieved using cookies from “next/headers”) and if they do then I render UserComponent or else I render a vanilla home page.
When I visit the page on the website, when I install the pwa on my computer it works as expected, by which I mean the page is dynamically rendered based on the data retrieved by the fetch call on the server before page load.
However, when I install the pwa on an android device , the first time the pwa loads, I get the vanilla home page, despite me manually knowing a token is present. If I pull to refresh the screen, it updates to the correct UserComponent view.
I have tried to the setting cacheStartUrl to false in the config as well and got the same result.
Any advice on how I can fix this or what I’m doing wrong?
Expected behavior
when the pwa is installed on mobile, the startUrl which is an async server component should dynamically render UI based on state returned by a fetch call on load.
Screenshots (if relevant)
No response
Additional information (if relevant)
Turning the startUrl into a client component and running the fetch in a useEffect does work. However I’d prefer to not do that, if possible.
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 16 (8 by maintainers)
i did double check that the cache was removed and there was no sw. interestingly if I visit an authentication link sent via email that redirects me to a page within the app (not the ‘/’ url) and sets a token, it does manage to register that a token is present when the eventual page loads, I can even navigate back to ‘/’ from there and everything works fine. However, if I close the pwa, kill it in the background and then reopen it, same issue of no token on initial ‘/’ page load. Sigh.
I should mark this issue closed here for now then, I guess. Will try and do some further debugging and see if I can find any way out of or around this. Thanks for all your help!
Sounds good. Will try and then update you on what I find!
I appreciate you looking into it whenever you get the time. Do let me know if I can be of any help!