mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
14c86bef1d
* Implement a very simple prefetching solution. * Remove next-prefetcher. * Require 'whatwg-fetch' only in the client. * Use xhr in the code. * Use a simple fetching solution. * Fix 404 and xhr status issue. * Move the prefetching implementation to next/router. * Add deprecated warnning for next/prefetch * Run only 2 parellel prefetching request at a time. * Change xhr to jsonPageRes. * Improve the prefetching logic. * Add unit tests covering the Router.prefetch() * Update examples to use the new syntax. * Update docs. * Use execOnce() to manage warn printing. * Remove prefetcher building from the flyfile.js Because, we no longer use it.
34 lines
904 B
JavaScript
34 lines
904 B
JavaScript
import React from 'react'
|
|
import Link from './link'
|
|
import Router from './router'
|
|
import { warn, execOnce } from './utils'
|
|
|
|
const warnImperativePrefetch = execOnce(() => {
|
|
const message = '> You are using deprecated "next/prefetch". It will be removed with Next.js 2.0.\n' +
|
|
'> Use "Router.prefetch(href)" instead.'
|
|
warn(message)
|
|
})
|
|
|
|
const wantLinkPrefetch = execOnce(() => {
|
|
const message = '> You are using deprecated "next/prefetch". It will be removed with Next.js 2.0.\n' +
|
|
'> Use "<Link prefetch />" instead.'
|
|
warn(message)
|
|
})
|
|
|
|
export function prefetch (href) {
|
|
warnImperativePrefetch()
|
|
return Router.prefetch(href)
|
|
}
|
|
|
|
export default class LinkPrefetch extends React.Component {
|
|
render () {
|
|
wantLinkPrefetch()
|
|
const props = {
|
|
...this.props,
|
|
prefetch: this.props.prefetch === false ? this.props.prefetch : true
|
|
}
|
|
|
|
return (<Link {...props} />)
|
|
}
|
|
}
|