Merged
Conversation
f2b5055 to
953e006
Compare
Previously, we were packing the properties used by __GRAPHILE_APP__ into the query params of a parsed URL object received by Next.js. This exploited a loophole by which the `search` field of the URL object remained the source of truth for navigation, but the `query` field would be written into `__NEXT_DATA__` whence it could be retrieved by @app/client/src/pages/_app.tsx upon bootstrap and written into the window global. Starting in Next.js 14, if both `search` and `query` are present, search will take precedence. Injecting these extra properties into the search segment will cause rehydration errors during navigation due to a mismatch between the browser history and what Next thinks the search segment should contain. In this commit, we change strategies and instead pack the extra props into the `req` object in @app/server/src/middleware/installSSR.ts, read them out of `ctx.req` in `MyApp.getInitialProps()` in @app/client/src/pages/_app.tsx, and return them as part of the props object. This causes Next to serializes them into the __NEXT_DATA__ bootstrap payload under the `props` key, whence they can be attached to `window.__GRAPHILE_APP__` as before. We also add some abstractions in @app/lib to centralize reading and writing to this global object in a type-safe manner. unblocks next 14.x
Next 14 wires its custom-server websocket listener lazily from the request handler path, so reading the fake server's upgrade listener during SSR middleware installation can miss it. That leaves the central upgrade dispatcher without a Next handler and causes /_next/webpack-hmr connections to be destroyed. Register the Next upgrade dispatcher entry up front, but resolve the listener from the fake server when a matching upgrade arrives. This keeps the existing single-server websocket dispatch model without reaching into Next's private custom-server fields.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.