-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
chore: [app dir bootstrapping 4] check nullability of navigation hook return values #12005
Conversation
@grzpab is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thank you for following the naming conventions! 🙏 Feel free to join our discord and post your PR link to collect XP and win prizes! |
📦 Next.js Bundle Analysis for @calcom/webThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
setLoadMore(true); | ||
} | ||
setMembers(members.concat(membersFetch)); | ||
setLoadMore(membersFetch.length >= limit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Big change. Will test locally before approving. Thanks again @grzpab 🙏🏽
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM. Tested locally and found no issues. Checks are passing. I think it's safe to merge and test on dev and QA.
What does this PR do?
This PR enforces nullability checks for return values from
useParams
anduseSearchParams
.If a page has neither
getServerSideProps
notgetInitialProps
, Next.js will optimize it statically. This makes theusePathname
anduseSearchParams
equalnull
until the router becomes available during hydration.If you add the app directory to the web directory and run yarn build, the types will be updated by Next.js builder/plugin and the projects will then include the compat type definitions provided by Next.js.
This mechanism is coded here: https://github.com/vercel/next.js/blob/524b31513a58e58e15862ac8aa3f27da8a47a267/packages/next/src/lib/typescript/writeAppTypeDeclarations.ts#L54
The example compat type definition is here: https://github.com/vercel/next.js/blob/524b31513a58e58e15862ac8aa3f27da8a47a267/packages/next/navigation-types/compat/navigation.d.ts
Requirement/Documentation
https://nextjs.org/docs/app/api-reference/functions/use-pathname
https://nextjs.org/docs/app/api-reference/functions/use-search-params
https://nextjs.org/docs/pages/building-your-application/rendering/automatic-static-optimization
Type of change
How should this be tested?
The app should work exactly as worked before.
Since nullability issues (TypeErrors) have not been observed before, this change should only satisfy the TS compiler.
Caveats:
useSearchParams
andusePathname
return values on the prerender. Other pages don't have these values on the first render. The code should not allow:a) running write operation on first render (with e.g.
useEffect
) that use values from these hooks.b) running read operations unconditionally based on the values from these hooks.
One idea was to wrap each component with a HOC that:
null
whenuseSearchParams
orusePathname
arenull
searchParams
andpathname
as props to the wrapped component.One problem is possible flickering stemming from a lot of components appearing when these two values become available.
Mandatory Tasks
Checklist