|
1 | 1 | import { defineNuxtPlugin } from '../nuxt' |
2 | | -import { useRouter } from '../composables' |
| 2 | +import { onNuxtReady } from '../composables/ready' |
| 3 | +import { useRouter } from '../composables/router' |
3 | 4 |
|
4 | 5 | export default defineNuxtPlugin(() => { |
5 | | - useRouter().beforeResolve(async () => { |
6 | | - /** |
7 | | - * This gives an opportunity for the browser to repaint, acknowledging user interaction. |
8 | | - * It can reduce INP when navigating on prerendered routes. |
9 | | - * |
10 | | - * @see https://github.com/nuxt/nuxt/issues/26271#issuecomment-2178582037 |
11 | | - * @see https://vercel.com/blog/demystifying-inp-new-tools-and-actionable-insights |
12 | | - */ |
13 | | - await new Promise((resolve) => { |
14 | | - // Ensure we always resolve, even if the animation frame never fires |
15 | | - setTimeout(resolve, 100) |
16 | | - requestAnimationFrame(() => { setTimeout(resolve, 0) }) |
| 6 | + const router = useRouter() |
| 7 | + onNuxtReady(() => { |
| 8 | + router.beforeResolve(async () => { |
| 9 | + /** |
| 10 | + * This gives an opportunity for the browser to repaint, acknowledging user interaction. |
| 11 | + * It can reduce INP when navigating on prerendered routes. |
| 12 | + * |
| 13 | + * @see https://github.com/nuxt/nuxt/issues/26271#issuecomment-2178582037 |
| 14 | + * @see https://vercel.com/blog/demystifying-inp-new-tools-and-actionable-insights |
| 15 | + */ |
| 16 | + await new Promise((resolve) => { |
| 17 | + // Ensure we always resolve, even if the animation frame never fires |
| 18 | + setTimeout(resolve, 100) |
| 19 | + requestAnimationFrame(() => { setTimeout(resolve, 0) }) |
| 20 | + }) |
17 | 21 | }) |
18 | 22 | }) |
19 | 23 | }) |
0 commit comments