-
Notifications
You must be signed in to change notification settings - Fork 27k
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
with-data-prefetch example doesn't work with Next v8 #6376
Comments
Please send a PR fixing. 😄 |
In addition to the missing module issue reported above, looks like maybe some architecture changed here. This line now returns
Now, it checks if |
Yeah I was telling @Timer this example can't be fixed without core changes. We might allow an option passed to |
@timneutkens gotcha. Are you implying that data prefetching is no longer possible with nextjs? |
I'm saying that this solution/example is using internal APIs hence why it breaks on majors. We should probably expose an external API for loading the component. |
^^ That would be pretty awesome! |
Hey @timneutkens 👋 - what are the internal APIs that this example currently relies on that we can expose to make prefetching data possible again? |
Given that the example no longer works in Next 8, will you be happy to accept a PR that deletes it from canary? I spent a couple of hours setting up something similar in my app before realising that |
There's a method called For some reason If you use TypeScript, it is possible to still call/reference the method by casting My following approach isn't perfect but at least it fetched the component, hence able to call the import Router from 'next/router'
import { UrlLike, RouterProps } from 'next-server/router'
import { format, resolve, parse } from 'url'
interface MyRouterProps extends RouterProps {
fetchComponent: (route: string) => Promise<NextComponentType>
}
type UrlAlike = string | UrlLike
export default async (href: UrlAlike, asPath?: UrlAlike) => {
if (typeof window === 'undefined') return
const hrefString = href === 'string' ? href : format(href)
const route = resolve(location.pathname, hrefString)
if (Router.router === null) return
// the following fetches the component for the valid route
const component = await (router as MyRouterProps).fetchComponent(route)
// ...
} edit: My approach avoids using |
Replied on twitter but also posting here: https://twitter.com/timneutkens/status/1145573026869760000
As said in my tweet I'd love for someone to draft up a RFC for this. Requirements from my side:
|
Closing as this example was deleted. Next.js automatically prefetches data when it's safe now ( |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Examples bug report
Example name
with-data-prefetch
Describe the bug
The example fails to compile with this error:
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
npx create-next-app --example with-data-prefetch with-data-prefetch-app
npm install
npm run dev
Expected behavior
The example should run and data prefetching should work as described.
Screenshots
System information
Additional context
This bug also affects the
data-prefetch-link
library and thenext-apollo
library.The text was updated successfully, but these errors were encountered: