Articles not appearing as bookmarked in some cases
Context
Please provide any relevant information about your setup
Expected Behavior
Post should appear as bookmarked without a refresh
Current Behavior
Post doesnt show as bookmarked with a refresh
Screenshots
https://github.com/codu-code/codu/assets/46611809/ab3ed4ee-9f73-4f78-bda1-551f8dc779a5
Steps to reproduce
Please provide detailed steps for reproducing the issue
- Navigate to https://www.codu.co/articles
- Click on an article
- Click bookmark icon on the left side of the page
- Navigate back to the articles page by clicking the link
- Notice the bookmark is not present
Additional info
Provide any additional information here
@JohnAllenTech can you plz assign this issue to me? and also add hacktoberfest label to this
I assigned you @hrit2773 Thanks.
@hrit2773 Have you made any progress on this, or should I unassign you and make it available to someone else?
@John-Paul-Larkin Yes I'm still working on this is it ok if I make a PR by this week itself.
@John-Paul-Larkin I would like to share my progress and get the PR done by today if you approve. Actually what's happening is that as Next.js uses caching it always shows the previous loaded page when articles route is hit back. The bookmarked value is consistently updated in the database so no problems with the data. What we can do is we can always try to refetch the status of all articles when the articles page is mounted or even if the popstate event is made. That is the solution to this bug. Your thoughts?
I changed the cacheTime to 0 and its fetching all the articles again ensuring the changes are visible when the user visits the articles link back again. What do you think @John-Paul-Larkin @JohnAllenTech it was a small bug. Can I proceed with the PR
Uh oh! @hrit2773, the image you shared is missing helpful alt text. Check https://github.com/codu-code/codu/issues/882#issuecomment-2421645691.
Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.
Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.
Uh oh! @hrit2773, the image you shared is missing helpful alt text. Check https://github.com/codu-code/codu/issues/882#issuecomment-2421645691.
Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.
Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.
Hi @hrit2773 Although setting the cache time to 0 will work, I am sure there is a more efficient way to do this. I think, instead, we can set the stale time to 0 and revalidate the query when the user returns to the page. Im not sure of the implementation of this, but my hunch is that it is a problem with a well worn solution.
invalidating the cache when an article is bookmarked seems like the way to go to me
👌 That sounds right John thanks. We can invalidate the query when the users bookmarks an article.
queryClient.invalidateQueries({ queryKey: ['bookmarks'] })
A query key should be added to the bookmarks query.
@JohnAllenTech yup nice Idea and it will be a better way. I'll make a pr by today and close it
hi @hrit2773! did you get the chance to finish this? If you did could you tag the PR here? thanks