forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove inheritance from NextCustomServer (vercel#73005)
### What This PR changes `NextCustomServer` to no longer subclass `NextServer` and instead just delegate all methods to `this.renderServer`. I've also added an interface implemented by both `NextServer` and `NextCustomServer` to make it explicit what we're actually exposing. (Note that we're currently exposing too much for legacy reasons. we might want to decide to clean this up a bit, i've started that in vercel#73021) I've also cleaned up some random `(_ as any)`s and unnecessary indirections around the area. ### Why currently, `NextCustomServer` is a subclass of `NextServer`, which makes it very confusing to reason about, because in `prepare()` it creates *a nested `NextServer`* (stored in `this.renderServer`). this isn't immediately visible in the code, but that's what `getRequestHandlers` ends up doing. https://github.com/vercel/next.js/blob/58b993c239689f22641682bbcb0d8dea6d85fdf1/packages/next/src/server/next.ts#L281 then, it delegates *some* methods to that (`render`, `getRequestHandler`, `setAssetPrefix`). But some methods (e.g. `render404`) *aren't* overridden/delegated and just run the implementation inherited from `NextServer`. And those implementations are unaware of `this.renderServer`, so they end up initializing a *second* `NextNodeServer` (`this.server` vs `this.renderServer.server`) and run against that instead. that's bad! and it's why e.g. vercel#61676 was necessary -- we needed to update both servers! i think that this is a leftover of the old implementation where we ran a separate process for rendering. for historical context, see: - vercel#49805 which seems to have introduced this split (the proxy only overrides `prepare`, `getRequestHandler`, and `render`) - vercel#53523 which turned the proxy code into `NextCustomServer` also apparently `render404` and others were broken in development (try running the tests in the first commit I've changed `NextCustomServer` and see the server hang forever).
- Loading branch information
1 parent
87c74c8
commit 08e7410
Showing
10 changed files
with
351 additions
and
108 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.