Skip to content

Commit

Permalink
Revert #14580
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Sep 1, 2020
1 parent d20dbd6 commit bf87f65
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions packages/next/client/page-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ const relPreloadStyle = 'fetch'

const hasNoModule = 'noModule' in document.createElement('script')

const requestIdleCallback: (fn: () => void) => void =
(window as any).requestIdleCallback ||
function (cb: () => void) {
return setTimeout(cb, 1)
}

function normalizeRoute(route: string) {
if (route[0] !== '/') {
throw new Error(`Route name should start with a "/", got "${route}"`)
Expand Down Expand Up @@ -281,20 +275,19 @@ export default class PageLoader {
const { pathname: hrefPathname } = parseRelativeUrl(href)
const route = normalizeRoute(hrefPathname)
return this.promisedSsgManifest!.then(
(s: ClientSsgManifest, _dataHref?: string) => {
requestIdleCallback(() => {
// Check if the route requires a data file
s.has(route) &&
// Try to generate data href, noop when falsy
(_dataHref = this.getDataHref(href, asPath, true)) &&
// noop when data has already been prefetched (dedupe)
!document.querySelector(
`link[rel="${relPrefetch}"][href^="${_dataHref}"]`
) &&
// Inject the `<link rel=prefetch>` tag for above computed `href`.
appendLink(_dataHref, relPrefetch, 'fetch')
(s: ClientSsgManifest, _dataHref?: string) =>
// Check if the route requires a data file
s.has(route) &&
// Try to generate data href, noop when falsy
(_dataHref = this.getDataHref(href, asPath, true)) &&
// noop when data has already been prefetched (dedupe)
!document.querySelector(
`link[rel="${relPrefetch}"][href^="${_dataHref}"]`
) &&
// Inject the `<link rel=prefetch>` tag for above computed `href`.
appendLink(_dataHref, relPrefetch, 'fetch').catch(() => {
/* ignore prefetch error */
})
}
)
}

Expand Down

0 comments on commit bf87f65

Please sign in to comment.