| 1 | import { Router } from 'next/router' |
| 2 | import NProgress from 'nprogress' |
| 3 | import { FontFaceProvider, FontFaceRenderer } from 'utils/hooks/useFontFace' |
| 4 | import 'focus-visible' |
| 5 | import 'wicg-inert' |
| 6 | import 'nprogress/nprogress.css' |
| 7 | import 'swiper/css/bundle' |
| 8 | import 'css/index.css' |
| 9 | |
| 10 | // NProgress |
| 11 | const translating = () => { |
| 12 | NProgress.start() |
| 13 | document.documentElement.classList.add('translating') |
| 14 | } |
| 15 | |
| 16 | const translated = () => { |
| 17 | NProgress.done() |
| 18 | setTimeout( |
| 19 | () => document.documentElement.classList.remove('translating'), |
| 20 | 250 |
| 21 | ) |
| 22 | } |
| 23 | |
| 24 | Router.events.on('routeChangeStart', translating) |
| 25 | Router.events.on('routeChangeComplete', translated) |
| 26 | Router.events.on('routeChangeError', translated) |
| 27 | |
| 28 | NProgress.configure({ showSpinner: false, trickleSpeed: 350 }) |
| 29 | |
| 30 | // Make resilience from manipulating DOM by Google translator |
| 31 | // https://github.com/facebook/react/issues/11538 |
| 32 | if (typeof Node === 'function' && Node.prototype) { |
| 33 | const { removeChild, insertBefore } = Node.prototype |
| 34 | |
| 35 | Node.prototype.removeChild = function <T extends Node>(child: T): T { |
| 36 | if (child.parentNode !== this) { |
| 37 | if (console) { |
| 38 | console.error( |
| 39 | 'Cannot remove a child from a different parent', |
| 40 | child, |
| 41 | this |
| 42 | ) |
| 43 | } |
| 44 | return child |
| 45 | } |
| 46 | return removeChild.call(this, child) as T |
| 47 | } |
| 48 | Node.prototype.insertBefore = function <T extends Node>( |
| 49 | newNode: T, |
| 50 | referenceNode: Node | null |
| 51 | ): T { |
| 52 | if (referenceNode && referenceNode.parentNode !== this) { |
| 53 | if (console) { |
| 54 | console.error( |
| 55 | 'Cannot insert before a reference node from a different parent', |
| 56 | referenceNode, |
| 57 | this |
| 58 | ) |
| 59 | } |
| 60 | return newNode |
| 61 | } |
| 62 | return insertBefore.call(this, newNode, referenceNode) as T |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | const App = ({ Component, pageProps }) => ( |
| 67 | <FontFaceProvider> |
| 68 | <FontFaceRenderer /> |
| 69 | <Component {...pageProps} /> |
| 70 | </FontFaceProvider> |
| 71 | ) |
| 72 | |
| 73 | export default App |
| 74 |