-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Watchdog no longer restarts other editors that might share some configuration or plugins but were not affected by the error. #19418
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
Open
Mati365
wants to merge
10
commits into
master
Choose a base branch
from
ck/19407
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a793bb5
Watchdog no longer restarts other editors that might share some confi…
Mati365 b9617cf
Add context watchdog manual test.
Mati365 7ce5497
Fix EOF
Mati365 797edfb
Adjust comment.
Mati365 06fe4e1
Adjust comment.
Mati365 5b8fb5f
Extend probe.
Mati365 67a9767
Adjust asseration.
Mati365 a684de2
Simplify expresion.
Mati365 595d286
Extend editor specific variables array.
Mati365 48ca817
Extend list
Mati365 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| type: Fix | ||
| scope: | ||
| - ckeditor5-watchdog | ||
| closes: | ||
| - https://github.com/ckeditor/ckeditor5/issues/19407 | ||
| --- | ||
|
|
||
| Improved the error detection mechanism in `EditorWatchdog`. It now better identifies which editor instance is responsible for an error, preventing unnecessary restarts of other editors that might share some configuration or plugins but were not affected by the error. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/ckeditor5-watchdog/tests/manual/contextwatchdog.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <button id="context-error">Simulate `Error` in Context Plugin</button> | ||
| <button id="random-error">Simulate a random `Error`</button> | ||
|
|
||
| <div>Context state: <span id='context-state'></span></div> | ||
|
|
||
| <div class="editor"> | ||
| <div id="editor-1"> | ||
| <h2>Heading 1</h2> | ||
| <p>Paragraph</p> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="editor"> | ||
| <div id="editor-2"> | ||
| <h2>Heading 1</h2> | ||
| <p>Paragraph</p> | ||
| </div> | ||
| </div> | ||
|
|
||
| <style> | ||
| .editor { | ||
| margin-top: 20px; | ||
| } | ||
| </style> |
124 changes: 124 additions & 0 deletions
124
packages/ckeditor5-watchdog/tests/manual/contextwatchdog.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /** | ||
| * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved. | ||
| * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options | ||
| */ | ||
|
|
||
| import { Context, ContextPlugin } from '@ckeditor/ckeditor5-core'; | ||
| import { ClassicEditor } from '@ckeditor/ckeditor5-editor-classic'; | ||
| import { ArticlePluginSet } from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset.js'; | ||
| import { CKEditorError } from '@ckeditor/ckeditor5-utils'; | ||
|
|
||
| import { ContextWatchdog } from '../../src/contextwatchdog.js'; | ||
|
|
||
| const stateElement = document.getElementById( 'context-state' ); | ||
|
|
||
| class ContextErrorPlugin extends ContextPlugin { | ||
| init() { | ||
| window.contextErrorPlugin = this; | ||
| } | ||
|
|
||
| throwError() { | ||
| setTimeout( () => { | ||
| throw new CKEditorError( 'context-error', this.context ); | ||
| } ); | ||
| } | ||
| } | ||
|
|
||
| class TypingError { | ||
| constructor( editor ) { | ||
| this.editor = editor; | ||
| } | ||
|
|
||
| init() { | ||
| const inputCommand = this.editor.commands.get( 'input' ); | ||
|
|
||
| inputCommand.on( 'execute', ( evt, data ) => { | ||
| const commandArgs = data[ 0 ]; | ||
|
|
||
| if ( commandArgs.text === '1' ) { | ||
| // Simulate error. | ||
| this.editor.foo.bar = 'bom'; | ||
| } | ||
| } ); | ||
| } | ||
| } | ||
|
|
||
| const watchdog = new ContextWatchdog( Context ); | ||
|
|
||
| window.watchdog = watchdog; | ||
|
|
||
| const contextConfig = { | ||
| plugins: [ ContextErrorPlugin ] | ||
| }; | ||
|
|
||
| watchdog.create( contextConfig ) | ||
| .then( () => { | ||
| return Promise.all( [ | ||
| watchdog.add( { | ||
| id: 'editor1', | ||
| type: 'editor', | ||
| creator: async ( element, config ) => { | ||
| const editor1 = await ClassicEditor.create( element, config ); | ||
|
|
||
| window.editor1 = editor1; | ||
| console.log( 'Created editor1!', editor1 ); | ||
|
|
||
| return editor1; | ||
| }, | ||
| sourceElementOrData: document.getElementById( 'editor-1' ), | ||
| config: { | ||
| plugins: [ ArticlePluginSet, TypingError ], | ||
| image: { toolbar: [ 'toggleImageCaption', 'imageTextAlternative' ] }, | ||
| toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ] | ||
| } | ||
| } ), | ||
| watchdog.add( { | ||
| id: 'editor2', | ||
| type: 'editor', | ||
| creator: async ( element, config ) => { | ||
| const editor2 = await ClassicEditor.create( element, config ); | ||
|
|
||
| window.editor2 = editor2; | ||
| console.log( 'Created editor2!', editor2 ); | ||
|
|
||
| return editor2; | ||
| }, | ||
| sourceElementOrData: document.getElementById( 'editor-2' ), | ||
| config: { | ||
| plugins: [ ArticlePluginSet, TypingError ], | ||
| image: { toolbar: [ 'toggleImageCaption', 'imageTextAlternative' ] }, | ||
| toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ] | ||
| } | ||
| } ) | ||
| ] ); | ||
| } ); | ||
|
|
||
| watchdog.on( 'itemError', ( evt, { itemId, error } ) => { | ||
| console.log( `Context watchdog item (${ itemId }) error:`, error ); | ||
| } ); | ||
|
|
||
| watchdog.on( 'error', ( evt, { error } ) => { | ||
| console.log( 'Context watchdog error:', error ); | ||
| } ); | ||
|
|
||
| watchdog.on( 'restart', () => { | ||
| console.log( 'Context watchdog restarted.' ); | ||
| } ); | ||
|
|
||
| watchdog.on( 'stateChange', () => { | ||
| console.log( `Context watchdog state changed to '${ watchdog.state }'` ); | ||
|
|
||
| stateElement.innerText = watchdog.state; | ||
| } ); | ||
|
|
||
| stateElement.innerText = watchdog.state; | ||
|
|
||
| document.getElementById( 'context-error' ).addEventListener( 'click', () => { | ||
| if ( window.contextErrorPlugin ) { | ||
| window.contextErrorPlugin.throwError(); | ||
| } | ||
| } ); | ||
|
|
||
| document.getElementById( 'random-error' ).addEventListener( 'click', () => { | ||
| throw new Error( 'foo' ); | ||
| } ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # ContextWatchdog manual test | ||
|
|
||
| 1. Click `Simulate Error in Context Plugin`. The context and both editors should crash and be restarted. The error should be logged in the console. | ||
|
|
||
| 2. Click `Simulate a random error`. No editor should be restarted. | ||
|
|
||
| 3. Refresh page and quickly click `Simulate Error in Context Plugin` 4 times. After the last error the watchdog should be crashed permanently and it should not restart. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you select this list of objects? Maybe we should add some more like
editor.editing,editor.ui,editor.editing.mapper?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I selected these fields because they’re the core editor properties that are always present and each of them is an instance of a CKEditor 5 specific class. In other words, this list isn’t random - it includes only the stable subsystems that exist in practically every editor, regardless of the loaded features.