You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js本地localhost环境下CKEditor加载运行异常问题

Next.js 集成 CKEditor5 加载异常问题

以下是我用于初始化编辑器的代码:

export default function Home() {
  
  const editorRef = useRef()
  const [ editorLoaded, setEditorLoaded ] = useState( false )
  const { CKEditor, ClassicEditor } = editorRef.current || {}

  useEffect( () => {
    editorRef.current = {
      CKEditor: require( '@ckeditor/ckeditor5-react' ).CKEditor,
      ClassicEditor: require( '@ckeditor/ckeditor5-build-classic' )
    }
    setEditorLoaded( true )
  }, [] )

    return (
      <div className='w-full h-full' >
      <h1>Ckeditor5 Nextjs</h1>
      {
        editorLoaded ?
        <CKEditor className="mt-3 wrap-ckeditor" editor={ClassicEditor} onReady={editor => {
         console.log(editor);
        }} />
        :
        "loading..."
      }
      

    </div>
    )
}

异常表现

  • 编辑器完成加载后,数百毫秒后会自动卸载
  • 完全相同的代码放到CodeSandbox中运行没有任何问题
  • onReady回调中打印编辑器实例,控制台输出为null,无法获取预期的实例对象
  • 检索Github、Stack Overflow均未找到对应解决方案

临时解决方式

移除next.config.js中的reactStrictMode:true配置即可解决该问题,该配置引发问题的根本原因可后续进一步探究。


内容的提问来源于stack exchange,提问作者mahdi tajik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.02 22:57:25