Open Glumac7 opened 6 months ago
Thank you for this! We were seeing the symptoms of this in production and couldn't figure it out—I've managed to reproduce this on our setup as well running v13.5.6
, and using getStaticProps
rather than getInitialProps
—note that we don't have the pageExtensions
option detailed in the 'make it work' steps, but just removing the middleware does the same thing. Our middleware is set up to only run on the homepage (/
) and the same issue occurs. As soon as you remove the middleware it works.
It looks like when the middleware is enabled, requests to the /_next/data/<hash>/<path>.json
file return an empty 200 response instead of a 404. The 404 allows next to reload the page to pick up the new data.
Did you find a fix for this?
Link to the code that reproduces this issue
https://github.com/Glumac7/middleware-issues
To Reproduce
In order to reproduce this issue, you need to do the following in order:
http://localhost:3000/test1
go to second page
buttonTypeError: Cannot read properties of undefined
How to make it "work":
next.config.js
, remove "api.ts" forpageExtensions
test2/234
instead of an_error.tsx
Alternatively, you could install next
v13.4.12
using which you would not need to make these changes tonext.config.js
, because the error occurs from13.4.13-canary.0
onward.Current vs. Expected behavior
Currently, we are getting an error presumably due to the middleware. There are no props in
_app.tsx
when there is a new build and a client side redirect happens on an active user session. When we remove"api.ts"
frompageExtensions
, that is, remove the use of the middleware, it works, on bothv13.4.12
andv13.4.13-canary.0
. If we want to use the middleware, we would need to downgrade tov13.4.12
.Expected behaviour should be the same as it is in
v13.4.12
(because the error happens fromv13.4.13-canary.0
onward), that is, for props returned fromgetInitialProps
and used in_app.tsx
not to beundefined
.Provide environment information
Which area(s) are affected? (Select all that apply)
Data fetching (gS(S)P, getInitialProps), Middleware / Edge (API routes, runtime)
Which stage(s) are affected? (Select all that apply)
next build (local), next start (local), Other (Deployed)
Additional context
It started happening from
v13.4.13-canary.0
onward, meaning it also happens on the newest next release (v14.1.3
as of this writing). Works as expected onv13.4.12
.