为什么我的 nextjs 应用程序不能在 Safari 上运行?
Why my nextjs app doesn't work on Safari?
我正在使用 nextjs 开发网络应用程序。除了 Mac 上的 Safari 之外,所有浏览器都运行良好。这是我打开开发者控制台时得到的:
仅在 Mac 上发生这种情况,它仍然可以在 iPhone 上正常 运行。有谁知道为什么会这样?
IntersectionObserver API 在 Safari v3.1-12 上不可用。您或您的任何图书馆正在使用此 API。要使其在旧版本的 Safari 上运行,您需要对其进行 polyfill。像这样的东西应该可以完成 Safari v6+ 的工作:
// pages/_app.jsx
import Script from 'next/script';
const App = ({ Component, pageProps }) => (
<>
<Script
src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver"
strategy="beforeInteractive"
/>
<Component {...pageProps} />
</>
);
export default App;
参考文献:
- https://caniuse.com/intersectionobserver
- https://nextjs.org/docs/basic-features/supported-browsers-features#custom-polyfills
- https://github.com/w3c/IntersectionObserver/tree/main/polyfill
- https://nextjs.org/docs/basic-features/script#loading-polyfills
- https://nextjs.org/docs/advanced-features/custom-app
我正在使用 nextjs 开发网络应用程序。除了 Mac 上的 Safari 之外,所有浏览器都运行良好。这是我打开开发者控制台时得到的:
仅在 Mac 上发生这种情况,它仍然可以在 iPhone 上正常 运行。有谁知道为什么会这样?
IntersectionObserver API 在 Safari v3.1-12 上不可用。您或您的任何图书馆正在使用此 API。要使其在旧版本的 Safari 上运行,您需要对其进行 polyfill。像这样的东西应该可以完成 Safari v6+ 的工作:
// pages/_app.jsx
import Script from 'next/script';
const App = ({ Component, pageProps }) => (
<>
<Script
src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver"
strategy="beforeInteractive"
/>
<Component {...pageProps} />
</>
);
export default App;
参考文献:
- https://caniuse.com/intersectionobserver
- https://nextjs.org/docs/basic-features/supported-browsers-features#custom-polyfills
- https://github.com/w3c/IntersectionObserver/tree/main/polyfill
- https://nextjs.org/docs/basic-features/script#loading-polyfills
- https://nextjs.org/docs/advanced-features/custom-app