You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm consistently facing a 404 error on <basePath>/_next/data/<BUILD_ID>/<path>.json requests.
The issue arises when providing a value for basePath in next.config.js (tested on a project using pages router).
Looking at the matchRoute function in packages/open-next/src/core/routing/routeMatcher.ts, the regex array used to match a path is derived from optionalBasepathPrefixRegex which prepends the basePath to the path regex. This results is a regex pattern that looks something this:
/^\/basePath\/?(?:)?path(?:\/)?$/
In the function fixDataPage in packages/open-next/src/core/routing/matcher.ts, we are removing the dataPattern (<basePath>/_next/data/<BUILD_ID>) from rawPath which includes the basePath resulting in a transformed rawPath of just /path.
When matchRoute is eventually called, it will try to match the above regex pattern with /path which will fail, resulting in a 404 response return for the data route.
When newPath is initialised in fixDataPage, can we prepend it with ${NextConfig.basePath ?? ""} so that the transformed rawPath would be basePath/path?
Thank you!
PS: Currently, when handling a route, fixDataPage outputs /path for both .../basePath/.../path and .../path requests which I don't think is the intended behaviour?
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Hello!
I'm consistently facing a 404 error on
<basePath>/_next/data/<BUILD_ID>/<path>.json
requests.The issue arises when providing a value for
basePath
innext.config.js
(tested on a project usingpages
router).Looking at the
matchRoute
function inpackages/open-next/src/core/routing/routeMatcher.ts
, theregex
array used to match a path is derived fromoptionalBasepathPrefixRegex
which prepends thebasePath
to the path regex. This results is a regex pattern that looks something this:/^\/basePath\/?(?:)?path(?:\/)?$/
In the function
fixDataPage
inpackages/open-next/src/core/routing/matcher.ts
, we are removing thedataPattern
(<basePath>/_next/data/<BUILD_ID>
) fromrawPath
which includes thebasePath
resulting in a transformedrawPath
of just/path
.When
matchRoute
is eventually called, it will try to match the above regex pattern with/path
which will fail, resulting in a 404 response return for the data route.When
newPath
is initialised infixDataPage
, can we prepend it with${NextConfig.basePath ?? ""}
so that the transformedrawPath
would bebasePath/path
?Thank you!
PS: Currently, when handling a route,
fixDataPage
outputs/path
for both.../basePath/.../path
and.../path
requests which I don't think is the intended behaviour?The text was updated successfully, but these errors were encountered: