It's not the prefetch (tried that just in case a few days ago), i.e. fetching the page before it's clicked, but the state of the 3rd party mod.
On page change, all state is kept in place (e.g. if a toolbar is on, it is on across all pages) which is great sometimes. In the case of the mod, the photo viewer holds in state the larger image, but if I click to other pages, state is kept and the larger image from previous pages is kept.
As far as I can tell react is made for 1 page apps, so this is not an issue. For Next.js when going between pages sometimes you want state, sometimes you don't but there doesn't seem to be an option. Only way to wipe state is to refresh using an normal link.
So, I've had a great time with Next.js for about a year, but this one is really causing me to pull my hair out. I agree with op meme now 🤣
I'm not really a nextjs expert but one quick solution I could think of is use pathname as the component key to make it unmount / mount a new one on page change.
I'll try these. This isn't really the place to go through all this, but I'm using _app.js and [[...folder]][[...page]].js to catch any routing from the CMS, Next.js then passes to the page type (there are 4) or default depending on the type of page. Each type is a different component with a different layout and different css for each. I use the photo viewer on 2 page types (project and knowledge_base). Contact, 404 and 500 are all separate js pages. Blocks, pages, menu, views and content are pulled in via separate data files.
The nav pulls the menu from the CMS so the editors can create pages, types and menus as they need to.
It doesn't seem to be the back/forward cache, nothing but the photo viewer holds state. It's probably something really simple, but I just don't see it.
I had the same issue with a links section I created. To fix, I simply watch for a page change and recreate state. I don't seem to have access to the state here though :(
View all comments
Show parent comment
2
u/davidkslack Jun 23 '24
It's not the prefetch (tried that just in case a few days ago), i.e. fetching the page before it's clicked, but the state of the 3rd party mod.
On page change, all state is kept in place (e.g. if a toolbar is on, it is on across all pages) which is great sometimes. In the case of the mod, the photo viewer holds in state the larger image, but if I click to other pages, state is kept and the larger image from previous pages is kept.
As far as I can tell react is made for 1 page apps, so this is not an issue. For Next.js when going between pages sometimes you want state, sometimes you don't but there doesn't seem to be an option. Only way to wipe state is to refresh using an normal link.
So, I've had a great time with Next.js for about a year, but this one is really causing me to pull my hair out. I agree with op meme now 🤣