Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ class CachePlugin implements PluginWithState<CachePluginState> {

if (contentModel) {
updateCache(this.state, contentModel, selection);
} else {
this.invalidateCache();
}

break;
Expand Down Expand Up @@ -165,8 +163,13 @@ class CachePlugin implements PluginWithState<CachePluginState> {

private invalidateCache() {
if (!this.editor?.isInShadowEdit()) {
this.state.cachedModel = undefined;
this.state.cachedSelection = undefined;
if (this.state.cachedModel) {
this.state.cachedModel = undefined;
}

if (this.state.cachedSelection) {
this.state.cachedSelection = undefined;
}

// Clear paragraph indexer to prevent stale references to old paragraphs
// It will be rebuild next time when we create a new Content Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,14 @@ describe('CachePlugin', () => {
});

expect(state).toEqual({
cachedModel: undefined,
cachedModel: model,
cachedSelection: undefined,
paragraphMap: mockedParagraphMap,
domIndexer: new DomIndexerImpl(),
textMutationObserver: mockedObserver,
});
expect(reconcileSelectionSpy).not.toHaveBeenCalled();
expect(resetMapSpy).toHaveBeenCalledTimes(1);
expect(resetMapSpy).not.toHaveBeenCalled();
});

it('No domIndexer, has model in event', () => {
Expand Down
Loading