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

[NEXT-1287] Docs: Problem of calling a page twice when navigating a page using nextLink #49844

Closed
holicreact opened this issue May 16, 2023 · 17 comments · Fixed by #51292
Closed
Assignees
Labels
Documentation Related to Next.js' official documentation. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@holicreact
Copy link

holicreact commented May 16, 2023

What is the improvement or update you wish to see?

Problem of calling a page twice when navigating a page using nextLink

Is there any context that might help us understand?

If you apply the prefetch={false} option to nextLink, the page is called twice when navigating the page of a sub-dynamic segment of the dynamic segment path.

I am sending additional unnecessary API requests because I make API requests inside the page.

For example, when you have a [categorySlug][subCategorySlug] path, if you browse the categorySlug page, you request the page only once, but when you browse the subCategorySlug path, you request the page twice

If this is a bug, please fix it If it's not a bug, please let me know how to prevent page duplicate calls Thank you.

Does the docs page already exist? Please link to it.

**https://app-directory-v2.vercel.app/context

https://github.com/holicreact/app-directory-v2.git**

From SyncLinear.com | NEXT-1287

@holicreact holicreact added the Documentation Related to Next.js' official documentation. label May 16, 2023
@SamarthBagga
Copy link

HI, to better understand the issue you are facing, could you please share the code that you are currently running? The more details you can provide, the easier it will be to find the problem.

@thexpand
Copy link

thexpand commented May 16, 2023

@holicreact Could it be only in development because of the strict mode? Note that components mount, then unmount, and then they mount again when React is in strict mode. This happens only in development.

@holicreact
Copy link
Author

HI, to better understand the issue you are facing, could you please share the code that you are currently running? The more details you can provide, the easier it will be to find the problem.

@SamarthBagga
thank this is link
https://github.com/holicreact/app-directory-v2

@holicreact엄격한 모드 때문에 개발 중일 수 있습니까? React가 엄격 모드에 있을 때 컴포넌트가 마운트되었다가 마운트 해제되었다가 다시 마운트된다는 점에 유의하십시오. 이것은 개발에서만 발생합니다.

@thexpand It's sad but It's working regardless of that.

@chaepling
Copy link

chaepling commented May 17, 2023

Having the same issue here. Can somebody please explain why this is happening? My logging plan exceeded due to this cause.

@holicreact
Copy link
Author

Having the same issue here. Can somebody please explain why this is happening? My logging plan exceeded due to this cause.

@chaepling you too? I hope this problem is resolved soon

@smo043
Copy link

smo043 commented May 17, 2023

We are also seeing similar issues in production. I have apis on all of my pages, and the apis are going into an infinite cycle due to link prefetch.

@jakepeyser
Copy link

jakepeyser commented May 17, 2023

This issue is preventing us from upgrading to v13.4. We have several navigation elements with many links that we can't afford to prefetch them all, so we'd need to set prefetch to false, but this issue would have us duplicating the requests on each link click, neither of which is desired.

@smo043
Copy link

smo043 commented May 17, 2023

@jakepeyser - Could you please tell me what version of NextJS you're using? I'll upgrade my code to the same version and give it a shot.

@jakepeyser
Copy link

@smo043 We're on 13.3.4 in prod

@smo043
Copy link

smo043 commented May 17, 2023

@jakepeyser - Thank you, I just tried the same thing and encountered the same issue. Check to see if this issue persists for you; I put a console log to my api route and can see it logs continuously which I feel a major problem.

@jakepeyser
Copy link

@smo043 I do not see the issue at our current version, Next.js only seems to prefetch metadata on hover and the new page is rendered and injected on click

@smo043
Copy link

smo043 commented May 17, 2023

@smo043 I do not see the issue at our current version, Next.js only seems to prefetch metadata on hover and the new page is rendered and injected on click

Oh okay, In my case all routes are being prefetched on every page load

@smo043
Copy link

smo043 commented May 17, 2023

@holicreact - could we change the title of this issue, since many of us have a similar issue?

@holicreact
Copy link
Author

holicreact commented May 18, 2023

This issue is preventing us from upgrading to v13.4. We have several navigation elements with many links that we can't afford to prefetch them all, so we'd need to set prefetch to false, but this issue would have us duplicating the requests on each link click, neither of which is desired.

@jakepeyser That's right, depending on the specific conditions, both sides have problems.

@smo043 I do not see the issue at our current version, Next.js only seems to prefetch metadata on hover and the new page is rendered and injected on click

@jakepeyser
@smo043

When prefetch={true}, the development environment fetching mouse hover data.
However, in a production environment, the data fetching when visible in the viewport.

When prefetch={false}, production does not patch the data even if the mouse is hover
Click the link to call the page twice.

I think this is related to hard navigation or soft navigation or next13's bug

@holicreact - could we change the title of this issue, since many of us have a similar issue?

@smo043 What are you going to change the title to?
If it's a good title, I agree I think maybe you can choose a better title than me Please

@smo043
Copy link

smo043 commented May 18, 2023

@holicreact - Sorry for not being clear, can we change [docs] to [bug]?

@holicreact
Copy link
Author

holicreact commented May 18, 2023

@holicreact - Sorry for not being clear, can we change [docs] to [bug]?

@smo043 That's a good idea. I'll organize it and post the bug report again

@huozhi huozhi added the linear: next Confirmed issue that is tracked by the Next.js team. label Jun 13, 2023
@huozhi huozhi changed the title Docs: Problem of calling a page twice when navigating a page using nextLink [NEXT-1287] Docs: Problem of calling a page twice when navigating a page using nextLink Jun 13, 2023
@huozhi huozhi assigned huozhi and feedthejim and unassigned huozhi and feedthejim Jun 13, 2023
@huozhi huozhi assigned feedthejim and unassigned feedthejim Jun 14, 2023
@kodiakhq kodiakhq bot closed this as completed in #51292 Jun 14, 2023
kodiakhq bot pushed a commit that referenced this issue Jun 14, 2023
This PR fixes a few reports that we were double fetching when navigating via a link that had prefetch false.

## Context

The bug was happening because we were inadvertently eagerly fetching even if we potentially bailed out of the optimistic navigation, which would then trigger another fetch from going through the regular navigation path.

There's potentially another bug here where we should potentially not bail out of optimistic navigation in the cases reported but we can fix that later.



fix #49844
link NEXT-1287
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Related to Next.js' official documentation. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants