-
Notifications
You must be signed in to change notification settings - Fork 27.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate next/router to use React.createContext #6030
Migrate next/router to use React.createContext #6030
Conversation
Got any tips on how to troubleshoot if the tests are failing? The test suite keeps spawning Chrome instances 😅 Edit: Looks like |
Looks like an issue with the |
You can run it locally:
|
Ah nice thanks! Okay so I think the problem is that the |
…rg/next.js into use-new-context-in-router
Oh yeah I see, you didn't add it to |
Looks like the Azure build error is unrelated to this PR, right? 🤔 |
@alexandernanberg yep it fails inconsistently sometimes. |
Great PR @alexandernanberg 🙏 |
Could you send me a DM on https://spectrum.chat/users/timneutkens |
Done ✔️ |
I'm trying to use import { RouterContext } from 'next/router'
const Foo = () => (
<RouterContext.Consumer>
{router => {
console.log(router) // undefined
return null
}}
</RouterContext.Consumer>
) Can you think why? |
@@ -180,7 +180,9 @@ async function doRender ({ App, Component, props, err, emitter: emitterProp = em | |||
// In development runtime errors are caught by react-error-overlay. | |||
if (process.env.NODE_ENV === 'development') { | |||
renderReactElement(( | |||
<App {...appProps} /> | |||
<RouterContext.Provider value={makePublicRouterInstance(router)}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so I think this is a big breaking change for next-graphql-react
, and probably the Apollo examples too:
https://github.com/jaydenseric/next-graphql-react/blob/v1.0.1/src/index.mjs#L92
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure this new approach of <RouterContext.Provider>
wrapping <App>
(as opposed to doing it inside <App>
via a router
prop, like before) is here to stay? If so, I can work it in to next-graphql-react
and cut a new release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I fully understand, the router
props is still passed to the <App />
if that's what you are referring to 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way @alexandernanberg is exactly how I would have implemented it, outside of _app.js.
@jaydenseric That's interesting, I can't seem to reproduce it myself. Can you provide reproducible sample repo? |
@alexandernanberg in the import { Query } from 'graphql-react'
import { RouterContext } from 'next/router'
export default () => (
<RouterContext.Consumer>
{router => {
console.log(router)
return null
}}
</RouterContext.Consumer>
) With I imagine this reproduction would work for the |
Fixes parts of #5716. I had some issues with the test suite but I'm fairly certain that I got it working correctly.