NextJS 动态 SSR:在移动设备中加载时卡住错误

问题描述 投票:0回答:1

问题:

Next JS 动态导入在移动设备浏览器上加载时卡住(使用的浏览器:iOS 上的 Google Chrome 和 Safari)。而它在桌面上的 Google Chrome 和 Mozilla 上运行得很好。我也在默认配置上使用 next-PWA。难道是因为 next-PWA 的缘故?

代码片段:

import dynamic from "next/dynamic";
import { useMemo } from "react";

export default function Main() {

const Component = useMemo(
    () =>
      dynamic(() => import("@components/Component"), {
        loading: () => <p>The component is loading</p>,
        ssr: false,
      }),
    [],
  );

  return(<div><Component/></div>);
}

在移动设备上输出

The component is loading

在桌面浏览器上输出

Hello from Component
javascript typescript next.js next-pwa
1个回答
-1
投票

故障不是 Next Dynamic 的问题,而是由于 HTTP 站点无法在移动浏览器中获取导航器资源。

编辑:在移动设备中,它需要 HTTPS 而不是 HTTP。因此,当我在本地网络中运行时,它是在 HTTP 中,要在本地网络中启用 HTTPS,您可以查看: https://web.dev/articles/how-to-use-local-https

© www.soinside.com 2019 - 2024. All rights reserved.