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

feat: avoid trigger increment-views call in link component prefetch #53

Merged
merged 3 commits into from
Jan 23, 2024

Conversation

MonsterPi13
Copy link
Contributor

Hi there,

When I forked this project, I encountered an issue in production mode - the increment_view_count RPC is triggered in the /writing route due to Link prefetching. The middleware function looks fine and only runs on /writing/:path/.

The problem is caused by Next.js's Link component prefetching all linked pages to improve UX.

To fix this, I had to differentiate between prefetched and normal user-initiated requests. I found that the solution in this discussion solves the prefetch issue nicely.

Apologies for the trouble, and thanks for this amazing work! Your blog looks concise and smooth.

Copy link

vercel bot commented Jan 23, 2024

Someone is attempting to deploy a commit to a Personal Account owned by @suyalcinkaya on Vercel.

@suyalcinkaya first needs to authorize it.

Copy link

vercel bot commented Jan 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
onurdev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 23, 2024 1:54pm

src/middleware.js Outdated Show resolved Hide resolved
Copy link
Owner

@suyalcinkaya suyalcinkaya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! ❤️

Copy link
Owner

@suyalcinkaya suyalcinkaya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I just noticed. Could you please fix the linting back?

src/middleware.js Outdated Show resolved Hide resolved
@suyalcinkaya suyalcinkaya merged commit aec284e into suyalcinkaya:master Jan 23, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants