Replies: 3 comments 1 reply
-
WDYT of using |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
(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 ) |
Beta Was this translation helpful? Give feedback.
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
getInitialProps
works with_app.js
and 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
getInitialProps
runs client-side on page transitions, it suggests that testing forcontext.req
is a valid approach for preventing logic from running during client-side page transitions. However, this is false in the case of usinggetInitialProps
in_app.js
and transitioning to a page withgetServerSideProps
- in this case,getInitialProps
will run on the server side.This means that inside of
getInitialProps
orgetServerSideProps
, 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
context
that indicates whether the current request is a page transition or not. I've seen mention of aisDataReq
flag before. Perhaps this could be exposed.Describe alternatives you've considered
I've noticed that on client-side page transitions,
context.req.url
always 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.Beta Was this translation helpful? Give feedback.
All reactions