Skip to content

Commit e34e5e0

Browse files
authoredSep 1, 2020
Revert #14580 (#16757)
1 parent 808d6b9 commit e34e5e0

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed
 

‎packages/next/client/page-loader.ts

+12-19
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ const relPreloadStyle = 'fetch'
5656

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

59-
const requestIdleCallback: (fn: () => void) => void =
60-
(window as any).requestIdleCallback ||
61-
function (cb: () => void) {
62-
return setTimeout(cb, 1)
63-
}
64-
6559
function normalizeRoute(route: string) {
6660
if (route[0] !== '/') {
6761
throw new Error(`Route name should start with a "/", got "${route}"`)
@@ -281,20 +275,19 @@ export default class PageLoader {
281275
const { pathname: hrefPathname } = parseRelativeUrl(href)
282276
const route = normalizeRoute(hrefPathname)
283277
return this.promisedSsgManifest!.then(
284-
(s: ClientSsgManifest, _dataHref?: string) => {
285-
requestIdleCallback(() => {
286-
// Check if the route requires a data file
287-
s.has(route) &&
288-
// Try to generate data href, noop when falsy
289-
(_dataHref = this.getDataHref(href, asPath, true)) &&
290-
// noop when data has already been prefetched (dedupe)
291-
!document.querySelector(
292-
`link[rel="${relPrefetch}"][href^="${_dataHref}"]`
293-
) &&
294-
// Inject the `<link rel=prefetch>` tag for above computed `href`.
295-
appendLink(_dataHref, relPrefetch, 'fetch')
278+
(s: ClientSsgManifest, _dataHref?: string) =>
279+
// Check if the route requires a data file
280+
s.has(route) &&
281+
// Try to generate data href, noop when falsy
282+
(_dataHref = this.getDataHref(href, asPath, true)) &&
283+
// noop when data has already been prefetched (dedupe)
284+
!document.querySelector(
285+
`link[rel="${relPrefetch}"][href^="${_dataHref}"]`
286+
) &&
287+
// Inject the `<link rel=prefetch>` tag for above computed `href`.
288+
appendLink(_dataHref, relPrefetch, 'fetch').catch(() => {
289+
/* ignore prefetch error */
296290
})
297-
}
298291
)
299292
}
300293

0 commit comments

Comments
 (0)
Please sign in to comment.