AppTree is sometimes incorrect in this code:
import BaseApp from "next/app";
import { renderToStaticMarkup } from "react-dom/server";
export default class App extends BaseApp {
static async getInitialProps(appCtx) {
const initialProps: any = await BaseApp.getInitialProps(appCtx);
// Not working
const { AppTree } = appCtx;
console.log("Wrong", renderToStaticMarkup(<AppTree {...initialProps} />));
return initialProps;
}
render() {
return <BaseApp {...this.props} />;
}
}
Therefore, all the "with-apollo" examples don't work and the "next-with-apollo" package too.
<AppTree /> is sometimes incorrect:Current <AppTree />: <a href="/about">About page</a>
Correct <AppTree />: <a href="/">Home page</a>
Current <AppTree />: <a href="/about">About page</a>
Correct <AppTree />: <a href="/about">About page</a>
Current <AppTree />: <a href="/about">About page</a>
Correct <AppTree />: <a href="/">Home page</a>
I found a simple way to get the correct AppTree by looking at Next.js source code:
import BaseApp from "next/app";
import { renderToStaticMarkup } from "react-dom/server";
export default class App extends BaseApp {
static async getInitialProps(appCtx) {
const initialProps: any = await BaseApp.getInitialProps(appCtx);
// Working
const { Component, err, router } = appCtx;
console.log(
"Good",
renderToStaticMarkup(
<App {...{ Component, err, router }} {...initialProps} />
)
);
return initialProps;
}
render() {
return <BaseApp {...this.props} />;
}
}
The workaround doesn't fully work because the app is not wrapped (in the Next.js source code, app is passed to a wrapApp function that adds router, etc...).
Hence, useRouter returns null.
@lcswillems It seems i have a similar problem on https://github.com/zeit/next.js/issues/9350
Experiencing the same issue, it might be some combination of AppTree and @apollo/react-ssr v3
@FlorinSenoner could you check whether it is still the case with the next 9.1.6 ?
Having this same issue trying to use Apollo getDataFromTree on the client side. AppTree doesn't seem to be updating.
yes!!! experiencing the same issue
I managed to update to next 9.2.0 and it seems to work now. Not sure if it was the same issue though
It is still not working for me on 9.2.0...
@Timer I recently opened a new issue that updates this issue: https://github.com/zeit/next.js/issues/10126
I opened this new issue because the bug worsened and it is now even easier to reproduce it. Maybe should we close this issue in favor of the new one?
Any news on this?
@Timer Any updates?
Most helpful comment
Experiencing the same issue, it might be some combination of
AppTreeand@apollo/react-ssrv3