-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Loading layer delayed with async head file (app dir) #45418
Comments
This also happens using the new |
I've updated my reproduction repository to show the same behavior using the |
I also experience the same issue. |
I'm having the same problem using the same API fetch for This behaviour is mentioned as intentional at: https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming
Whilst this makes sense for the initial page load so the correct head elements are returned to crawlers etc., I would think subsequent navigations within the app shouldn't need to wait for Perhaps an option in |
@huozhi in #45106 (comment) on Feb 22 you mentioned in relation to this problem:
Could you kindly advise if this patch has already been applied to the latest release or is still in the works? As the blocking generateMetadata problem still occurs, but I wasn't sure if we're still waiting on the patch or whether the patch didn't solve this particular issue. Thanks in advance |
@Fredkiss3 #43548 (comment) proposes a hack to return empty metadata for navigations after the initial load, and dynamically change the metadata in each It may not be production-ready, but it would be good to see this sort of functionality available in the Next.js framework. |
Still having this issue in Next 14.1. My |
In the meantime, here is my hacky solution inspired by @Fredkiss3
Usage:
Finally, a hook to update the title from a client component once the data is fetched
|
Same issue here. Currently there appears to be no standard way of showing a loading state while |
Any update? generateMetadata is blocking the UI |
This comment has been minimized.
This comment has been minimized.
@riley-worthington - thanks for sharing your solution. Do you mind explaining why |
Guys, I have found a fix for this whom may be looking: Issue: loading.tsx not showing when metadata is fetching (showing blank instead of loading component).
If it uses client, it does not stream loading component from server when needed. If you need somehow access path, etc. from request, use middleware + headers. P/s: recommend to implement along with #45418 (comment). Max |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue
https://github.com/abstractvector/nextjs-issue-async-head
To Reproduce
Create a
head
file in an appDir API route (e.g../src/app/blog/[slug]/head.tsx
) that returns a default async function. Create aloading.tsx
file or similar alongside it.Describe the Bug
The loading component (e.g.
./src/app/blog/[slug]/loading.tsx
) will not be displayed until the head component has rendered. Likewise, the URL will not be updated until the head component has rendered.If both the head and page components are calling the same APIs to retrieve data (likely a common use case, and one specifically referenced in the documentation), then the loading layer will never show.
Expected Behavior
As soon as the user clicks the link, the URL should update and the loading layer should be displayed.
Which browser are you using? (if relevant)
Firefox 109.0
How are you deploying your application? (if relevant)
next start
The text was updated successfully, but these errors were encountered: