Repository navigation
Replies: 3 comments 1 reply
|
I was also surprised to find that My use case is that I'd like to allow my client to modify site navigation and app-level details from a CMS, whilst ensuring the app is SSRd. My I understand I could implement a custom server to solve this, but then I can't deploy on Vercel. Whilst @tunesmith's solution of adding a flag to I notice @timneutkens indicated this would be a feature coming to Next.js in #10874 (comment), when the new data fetching patterns were introduced at the start of 2020. |
|
(Context and source of discussion https://stackoverflow.com/questions/64949719/nextjs-is-there-a-way-to-invoke-something-only-on-serverside-only-on-a-fresh-p ) |
Uh oh!
There was an error while loading. Please reload this page.
Feature request
Is your feature request related to a problem? Please describe.
As reported in #19426, there is potential confusion on how
getInitialPropsworks with_app.jsand page-levelgetServerSideProps.It's useful to invoke logic on the server side that will only run on initial page load.
Logic and queries like this are wasteful if requested on every client-side page transition.
While the documentation says that
getInitialPropsruns client-side on page transitions, it suggests that testing forcontext.reqis a valid approach for preventing logic from running during client-side page transitions. However, this is false in the case of usinggetInitialPropsin_app.jsand transitioning to a page withgetServerSideProps- in this case,getInitialPropswill run on the server side.This means that inside of
getInitialPropsorgetServerSideProps, there is not a reliable, supported way to tell if the current request is during initial page load, or during a client-side page transition.Describe the solution you'd like
One easy solution would be to expose a boolean flag in
contextthat indicates whether the current request is a page transition or not. I've seen mention of aisDataReqflag before. Perhaps this could be exposed.Describe alternatives you've considered
I've noticed that on client-side page transitions,
context.req.urlalways starts with/_next/data, and that could be conditioned upon, but it's unclear whether this is "supported" in terms of something that can be relied upon in future releases.All reactions