-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Fix crashing differ on large paragraphs #16821
Conversation
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.
Maybe a helper like our spliceArray
could be a better solution?
ckeditor5/packages/ckeditor5-utils/src/splicearray.ts
Lines 12 to 33 in 08270aa
/** | |
* Splices one array into another. To be used instead of `Array.prototype.splice` as the latter may | |
* throw "Maximum call stack size exceeded" when passed huge number of items to insert. | |
* | |
* Note: in contrary to Array.splice, this function does not modify the original `target`. | |
* | |
* ```ts | |
* spliceArray( [ 1, 2 ], [ 3, 4 ], 0, 0 ); // [ 3, 4, 1, 2 ] | |
* spliceArray( [ 1, 2 ], [ 3, 4 ], 1, 1 ); // [ 1, 3, 4 ] | |
* spliceArray( [ 1, 2 ], [ 3, 4 ], 1, 0 ); // [ 1, 3, 4, 2 ] | |
* spliceArray( [ 1, 2 ], [ 3, 4 ], 2, 0 ); // [ 1, 2, 3, 4 ] | |
* spliceArray( [ 1, 2 ], [], 0, 1 ); // [ 2 ] | |
* ``` | |
* | |
* @param target Array to be spliced. | |
* @param source Array of elements to be inserted to target. | |
* @param start Index at which nodes should be inserted/removed. | |
* @param count Number of items. | |
* | |
* @returns New spliced array. | |
*/ | |
export default function spliceArray<T>( target: ReadonlyArray<T>, source: ReadonlyArray<T>, start: number, count: number ): Array<T> { |
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.
Maybe extend the diff
array size by change.howMany
and use fill
??
@pszczesniak / @niegowski I'd recommend sticking with a for loop to maintain consistency with other parts of edit: I checked
|
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.
Please add an automatic test so we do not have a regression in the future.
@niegowski Added |
// add them manually one by one to avoid this limit. However loop might be a bit slower than `push` method on | ||
// smaller changesets so we need to decide which method to use based on the size of the change. | ||
// See: https://github.com/ckeditor/ckeditor5/issues/16819 | ||
if ( change.howMany > 1500 ) { |
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.
Could you write (here and/or in the issue) why we choose 1500?
It's based on some tests or it's some kind of random value?
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.
Limitation of args stack depends on OS / Browser etc. I chose some kind of random value.
Suggested merge commit message (convention)
Fix (engine): No longer crash editor when trying to style a very long paragraph. Closes #16819
Additional information
It looks like 200k arguments, passed to
.push
method of the Array, causes Google Chrome crashing. I switched it to plain for loop and it works fine.