Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CKEditorContext erorrs with next.js dev server #485

Open
f1ames opened this issue Jun 10, 2024 · 3 comments
Open

CKEditorContext erorrs with next.js dev server #485

f1ames opened this issue Jun 10, 2024 · 3 comments

Comments

@f1ames
Copy link

f1ames commented Jun 10, 2024

Using CKEditorContext errors with next.js dev server.

Steps

  1. Create next.js project (I used npx create-next-app@latest and picked TS, ESlint, src/ and AppRouter).

  2. Prepare below files:

Using app structure:

page.tsx:

import dynamic from 'next/dynamic';

const CustomEditor = dynamic( () => import( '@/components/editorWithContext' ), { ssr: false } );

function Home() {
  return (
    <CustomEditor />
  );
}

export default Home;

@/components/editorWithContext.tsx:

// components/custom-editor.js
'use client' // only in App Router

import { CKEditor, CKEditorContext } from '@ckeditor/ckeditor5-react';
import { ClassicEditor, Bold, Essentials, Italic, Mention, Paragraph, Undo, Context, ContextWatchdog, CloudServices } from 'ckeditor5';
import { SlashCommand, CloudServicesCommentsAdapter, CommentsRepository, RealTimeCollaborativeComments, Comments } from 'ckeditor5-premium-features';

import 'ckeditor5/ckeditor5.css';
import 'ckeditor5-premium-features/ckeditor5-premium-features.css';

function CustomEditorWithContext() {

	return (
		<CKEditorContext
			context={ Context }
			contextWatchdog={ ContextWatchdog }
			onError={(err) => console.log(err)}
			config={{
				cloudServices: {
					tokenUrl: '...',
					webSocketUrl: '...'
				},
				licenseKey: '...',
				toolbar: [ 'undo', 'redo', '|', 'bold',  'comment', 'commentsArchive']
			}}
		>

			<CKEditor
				editor={ ClassicEditor }
				config={ {
					plugins: [
						Essentials, Mention, Paragraph, SlashCommand, Undo, Bold, RealTimeCollaborativeComments, Comments,
						CloudServices, CloudServicesCommentsAdapter, CommentsRepository
					],
					mention: {
						feeds: [
							{
								marker: '@',
								feed: [ '@Barney', '@Lily', '@Marshall', '@Robin', '@Ted' ]
							},
						]
					},
					collaboration: {
						channelId: 'ch-1'
					},
				} }
				data='<p>Hello from the 1st editor working with the context!</p>'
				onReady={ ( editor ) => {
					console.log( 'Editor 1 is ready to use!', editor );
				} }
			/>

			<CKEditor
				editor={ ClassicEditor }
				config={ {
					plugins: [
						Essentials, Mention, Paragraph, SlashCommand, Undo, RealTimeCollaborativeComments, Comments,
						CloudServices, CloudServicesCommentsAdapter, CommentsRepository
					],
					collaboration: {
						channelId: 'ch-2'
					},
				} }
				data='<p>Hello from the second editor working with the context!</p>'
				onReady={ ( editor ) => {
					console.log( 'Editor 2 is ready to use!', editor );
				} }
			/>

		</CKEditorContext>
	);
}

export default CustomEditorWithContext;

package.json:

{
  "name": "nextjs-nim-ts",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "react": "^18",
    "react-dom": "^18",
    "next": "14.2.3",
    "@ckeditor/ckeditor5-react": "8.0.0-alpha.0",
    "ckeditor5": "42.0.0-alpha.2",
    "ckeditor5-premium-features": "42.0.0-alpha.2"
  },
  "devDependencies": {
    "typescript": "^5",
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "eslint": "^8",
    "eslint-config-next": "14.2.3"
  }
}
  1. Run npm run dev.

  2. Visit localhost:3000.

Actual behavior

Editors are not initialized, error in the console:

Semaphore unmounting error: 
TypeError: Cannot read properties of null (reading 'model')
Error: Cannot add items to destroyed watchdog.
Semaphore mounting error: 
Error: Item with the given id was not registered: e684be1018ff5f08126b45893d5650bf8.

image

Expected behavior

It works.

Additional info

It works with npm run build && npm start. I also checked with plain React and it worked there too without problems.

Maybe it's related to next.js dev server and hot reload?

@Mati365
Copy link
Member

Mati365 commented Jun 10, 2024

Can confirm, fully reproducible on my machine.

@Mati365
Copy link
Member

Mati365 commented Jun 10, 2024

@Witoso / @f1ames I checked it using #480 branch (yarn link approach) and it's no longer reproducible. I'd suggest to check if this error actually happens on old installation methods.

@f1ames
Copy link
Author

f1ames commented Jun 10, 2024

@Mati365 I can confirm it work fine with #480 👍🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants