-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
RootLayout doesn't receive searchParams
as props
#43863
Comments
I think only pages receive |
@filipesmedeiros I think that’s by design since layouts are supposed not to rerender on page transitions. and in the generated types for next layouts, I have these types here : type PageParams = Record<string, string>
interface PageProps {
params: any
searchParams?: any
}
interface LayoutProps {
children: React.ReactNode
params: any
} It seems like Layouts cannot receive PS: I got these types after running |
For context, my use case is conditionally rendering some parts of the layout depending on URL search params. |
Can you use a client component to conditionnaly render the components ? because in client components wherever you are in the tree, you can call And since you can pass server components as children (or props) to client components, you can even pre-render the parts you need on the layout and pass them as props to a client component with |
Thanks for the suggestion, @Fredkiss3. That would work. |
Also suggested this change to client component + |
@mpereira to be clear, this affects all layouts, correct? Not only If so, maybe it makes sense to update the title + description + demo of the issue? It's nice to have a tracking issue for this, since I remember seeing somewhere "the Next.js team is considering adding additional information to Layout props" - can't find the resource right now though... |
Or wait, I just found this issue as well, sounds similar: @balazsorban44 would you suggest marking #43863 as a duplicate of #43704? |
@karlhorky marking this one as a duplicate sounds good to me. |
Ok, I asked @adileo if he would edit the issue to mention the additional details explicitly and create a demo, potentially using yours as a starting point: #43704 (comment) |
Thanks for the ping and sorry for the late reply, I think we can fold this discussion into #43704 as suggested above. 👍 |
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. |
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://stackblitz.com/edit/vercel-next-js-z5qkbs?file=app%2Flayout.js
To Reproduce
Open https://stackblitz.com/edit/vercel-next-js-z5qkbs?file=app/layout.js
Open https://vercelnextjsz5qkbs-4a2j--3000.local-credentialless.webcontainer.io/?foo=true
Check terminal output in https://stackblitz.com/edit/vercel-next-js-z5qkbs?file=app/layout.js (from
console.log(props)
inRootLayout
props
inRootLayout
doesn't includesearchParams
, even though layouts should be considered server components.Describe the Bug
props
inRootLayout
doesn't includesearchParams
, even though layouts should be considered server components.Expected Behavior
props
inRootLayout
shoud includesearchParams
.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: