Skip to content

Fix SSR PostGraphile access for Next 15 dev#41

Merged
AprilArcus merged 1 commit into
mainfrom
pass-pgl-on-req
Apr 16, 2026
Merged

Fix SSR PostGraphile access for Next 15 dev#41
AprilArcus merged 1 commit into
mainfrom
pass-pgl-on-req

Conversation

@AprilArcus
Copy link
Copy Markdown
Owner

Next 15 dev wraps page requests in a Proxy. Accessing req.app through that wrapper can interact badly with Express because the Express app is both a callable function and an object with route helpers. In practice, our SSR Apollo setup could end up tripping Express path handling with a non-string value, causing:

TypeError: path.replace is not a function

during getDataFromTree.

Read the PostGraphile instance from the Express app once while installing SSR, then attach it directly to each SSR request as req.pgl. The server-side Apollo link now reads req.pgl instead of reaching back through req.app.get("pgl") during page rendering.

This keeps SSR independent of Next's request proxy behavior and avoids accidentally invoking Express routing internals while building the server-side GraphQL link.

Next 15 dev wraps page requests in a Proxy. Accessing `req.app` through
that wrapper can interact badly with Express because the Express app is
both a callable function and an object with route helpers. In practice,
our SSR Apollo setup could end up tripping Express path handling with a
non-string value, causing:

  TypeError: path.replace is not a function

during `getDataFromTree`.

Read the PostGraphile instance from the Express app once while installing
SSR, then attach it directly to each SSR request as `req.pgl`. The
server-side Apollo link now reads `req.pgl` instead of reaching back
through `req.app.get("pgl")` during page rendering.

This keeps SSR independent of Next's request proxy behavior and avoids
accidentally invoking Express routing internals while building the
server-side GraphQL link.
@AprilArcus AprilArcus merged commit 20dd98a into main Apr 16, 2026
5 checks passed
@AprilArcus AprilArcus deleted the pass-pgl-on-req branch April 16, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant