mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
### 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 https://github.com/vercel/next.js/pull/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. #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: - #49805 which seems to have introduced this split (the proxy only overrides `prepare`, `getRequestHandler`, and `render`) - #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).
23 lines
481 B
JavaScript
23 lines
481 B
JavaScript
import { useRouter } from 'next/router'
|
|
|
|
// NOTE: we want this page to be dynamic, otherwise the HTML won't contain search params
|
|
export async function getServerSideProps() {
|
|
return { props: {} }
|
|
}
|
|
|
|
export default function Page() {
|
|
const router = useRouter()
|
|
const searchParam = router.query.q
|
|
return (
|
|
<p>
|
|
made it to dynamic dashboard
|
|
{!!searchParam && (
|
|
<>
|
|
<br />
|
|
query param: {searchParam}
|
|
</>
|
|
)}
|
|
</p>
|
|
)
|
|
}
|