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

Next.js项目中Novel编辑器标题与列表功能失效问题求助

解决Next.js中Novel WYSIWYG编辑器标题与列表功能失效问题

以下是针对性的排查和修复步骤:

1. 安装所有必要依赖

Novel编辑器依赖一系列ProseMirror相关包和核心库,仅复制组件文件无法正常运行,执行以下命令补全依赖:

npm install @novel/react @novel/editor prosemirror-view prosemirror-state prosemirror-model prosemirror-commands prosemirror-keymap

2. 标记编辑器为客户端组件

Next.js 13+的App Router默认使用服务器组件,而WYSIWYG编辑器需要客户端交互能力,必须在advanced-editor.tsx文件顶部添加:

'use client';

3. 检查CSS导入优先级

  • 确保prosemirror.css和global.css在项目入口文件(layout.tsx或_app.tsx)中优先导入,避免被其他样式覆盖:
    // layout.tsx (App Router)
    import './prosemirror.css';
    import './global.css';
    import './your-project-styles.css';
    
  • 用浏览器开发者工具检查标题(h1/h2等)和列表(ul/ol)元素,确认它们的样式规则未被display: block、字体大小等关键属性的覆盖。

4. 确认编辑器扩展配置

Novel的useEditor钩子需要明确加载标题和列表相关插件,检查组件内的初始化代码:

import { useEditor } from '@novel/react';
import { createHeadingPlugin, createListPlugin } from '@novel/editor';

export function AdvancedEditor() {
  const editor = useEditor({
    extensions: [
      createHeadingPlugin(), // 必须包含标题插件
      createListPlugin(),   // 必须包含列表插件
      // 其他所需扩展...
    ],
  });

  // 编辑器渲染逻辑...
}

5. 调整Next.js项目配置

若使用App Router,在next.config.js中添加必要的转译配置:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  transpilePackages: ['@novel/react', '@novel/editor'],
};

module.exports = nextConfig;

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 17:23:17