mirror of
https://github.com/cloudflare/vinext.git
synced 2026-09-14 19:04:59 +08:00
a6d9826613
* fix(shims): add runtime default export to next/app
Pages Router fixtures using the canonical `pages/_app.js` pattern
(`import App from 'next/app'; export default class MyApp extends App`)
currently fail to build under vinext with:
[MISSING_EXPORT] "default" is not exported by
"node_modules/.../vinext/dist/shims/app.js"
The existing shim only re-exported a type as default. This adds a real
runtime class component matching Next.js's behaviour:
- `App` extends React.Component, renders `<Component {...pageProps} />`.
- `App.getInitialProps(appContext)` returns `{ pageProps }`, invoking the
wrapped page's `getInitialProps` if defined.
- `App.origGetInitialProps` is preserved alongside `getInitialProps`.
- AppProps, AppContext, AppInitialProps types are exported.
Ported from:
https://github.com/vercel/next.js/blob/canary/packages/next/src/pages/_app.tsx
This unblocks 51 build failures in the Next.js deploy suite that all
trace back to the missing default export.
* fix(shims): expose App class + types in next-shims.d.ts; document null coercion
Address two nits from the PR #1204 bonk review:
1. `next-shims.d.ts` still declared the old minimal `AppProps`-only shape.
External `.d.ts` consumers (editor, type checks against the published
package) couldn't see the new runtime class, `AppContext`, or
`AppInitialProps`. Update the `declare module 'next/app'` block to
declare the full surface added in the shim:
- default `class App<P, CP, S>` extending `React.Component` with
`static origGetInitialProps` / `static getInitialProps` and a
`render(): React.ReactNode` method
- `AppContext` and `AppInitialProps<P>` type aliases
- Expanded `AppProps<P>` shape (router, __N_SSG/__N_SSP flags)
2. `appGetInitialProps` silently coerces a null/undefined return from
`Component.getInitialProps` to `{}`. Next.js's `loadGetInitialProps`
throws in that case. Add an inline comment at the coercion site
noting the divergence, linking to the upstream source, and giving
future maintainers a bread crumb when they're debugging Pages Router
pages that render with mysteriously empty props.