-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[lexical-history] Bug Fix: SharedHistoryExtension forwards the parent maxDepth #9044
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
Merged
+110
−6
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eee99af
[lexical-history] Bug Fix: SharedHistoryExtension forwards the parent…
LeSingh1 994f3c3
Test all forwarded output signals
etrepum c7e634b
Merge remote-tracking branch 'origin/main' into history-shared-maxdepth
etrepum 4f67fe8
reflow jsdoc
etrepum 6a7730e
Raise e2e timing threshold from 60s to 100s
etrepum 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
99 changes: 99 additions & 0 deletions
99
packages/lexical-history/src/__tests__/unit/SharedHistoryMaxDepth.test.ts
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,99 @@ | ||
| /** | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| * | ||
| */ | ||
|
|
||
| import { | ||
| buildEditorFromExtensions, | ||
| getExtensionDependencyFromEditor, | ||
| } from '@lexical/extension'; | ||
| import {HistoryExtension, SharedHistoryExtension} from '@lexical/history'; | ||
| import {configExtension} from 'lexical'; | ||
| import {describe, expect, test} from 'vitest'; | ||
|
|
||
| const PARENT_MAX_DEPTH = 7; | ||
| const PARENT_DELAY = 123; | ||
|
|
||
| function buildParent() { | ||
| return buildEditorFromExtensions({ | ||
| dependencies: [ | ||
| configExtension(HistoryExtension, { | ||
| delay: PARENT_DELAY, | ||
| maxDepth: PARENT_MAX_DEPTH, | ||
| }), | ||
| ], | ||
| name: 'shared-max-depth-parent', | ||
| }); | ||
| } | ||
|
|
||
| function buildChild() { | ||
| return buildEditorFromExtensions({ | ||
| dependencies: [SharedHistoryExtension], | ||
| name: 'shared-max-depth-child', | ||
| }); | ||
| } | ||
|
|
||
| describe('SharedHistoryExtension forwards the parent history signals', () => { | ||
| test('the child adopts the parent maxDepth', () => { | ||
| using parent = buildParent(); | ||
| using child = buildChild(); | ||
|
|
||
| const shared = getExtensionDependencyFromEditor( | ||
| child, | ||
| SharedHistoryExtension, | ||
| ); | ||
| shared.output.parentEditor.value = parent; | ||
|
|
||
| const parentHistory = getExtensionDependencyFromEditor( | ||
| parent, | ||
| HistoryExtension, | ||
| ); | ||
| const childHistory = getExtensionDependencyFromEditor( | ||
| child, | ||
| HistoryExtension, | ||
| ); | ||
|
|
||
| // Premise: the parent really carries the configured cap, and the child's | ||
| // own default differs from it. | ||
| expect(parentHistory.output.maxDepth.peek()).toBe(PARENT_MAX_DEPTH); | ||
|
|
||
| // The child pushes onto the parent's shared undoStack, so it has to apply | ||
| // the parent's cap rather than its own default. | ||
| expect(childHistory.output.maxDepth.peek()).toBe(PARENT_MAX_DEPTH); | ||
| }); | ||
|
|
||
| test('the already-forwarded signals still arrive', () => { | ||
| using parent = buildParent(); | ||
| using child = buildChild(); | ||
|
|
||
| const shared = getExtensionDependencyFromEditor( | ||
| child, | ||
| SharedHistoryExtension, | ||
| ); | ||
| shared.output.parentEditor.value = parent; | ||
|
|
||
| const parentHistory = getExtensionDependencyFromEditor( | ||
| parent, | ||
| HistoryExtension, | ||
| ); | ||
| const childHistory = getExtensionDependencyFromEditor( | ||
| child, | ||
| HistoryExtension, | ||
| ); | ||
| const keys = [ | ||
| 'delay', | ||
| 'historyState', | ||
| 'now', | ||
| 'maxDepth', | ||
| 'disabled', | ||
| ] as const; | ||
| expect( | ||
| Object.fromEntries(keys.map(k => [k, childHistory.output[k].peek()])), | ||
| ).toEqual( | ||
| Object.fromEntries(keys.map(k => [k, parentHistory.output[k].peek()])), | ||
| ); | ||
| }); | ||
| }); | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.