ckeditor5-livewire 1.2.3 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -627,6 +627,49 @@ describe('editor component', () => {
627
627
 
628
628
  vi.useRealTimers();
629
629
  });
630
+
631
+ it('should not crash if content is null in snapshot', async () => {
632
+ vi.useFakeTimers();
633
+
634
+ const { $wire } = livewireStub.$internal.appendComponentToDOM<EditorSnapshot>({
635
+ name: 'ckeditor5',
636
+ el: createEditorHtmlElement(),
637
+ canonical: {
638
+ ...createEditorSnapshot(),
639
+ content: null as any,
640
+ saveDebounceMs: 0,
641
+ },
642
+ });
643
+
644
+ const editor = await waitForTestEditor();
645
+
646
+ $wire.set.mockClear();
647
+ editor.setData('<p>New content</p>');
648
+
649
+ await vi.advanceTimersByTimeAsync(1);
650
+
651
+ expect($wire.set).toHaveBeenCalledWith('content', { main: '<p>New content</p>' });
652
+ vi.useRealTimers();
653
+ });
654
+
655
+ it('should not crash on focus change if content is null in snapshot', async () => {
656
+ const { $wire } = livewireStub.$internal.appendComponentToDOM<EditorSnapshot>({
657
+ name: 'ckeditor5',
658
+ el: createEditorHtmlElement(),
659
+ canonical: {
660
+ ...createEditorSnapshot(),
661
+ content: null as any,
662
+ },
663
+ });
664
+
665
+ const { ui: { focusTracker } } = await waitForTestEditor();
666
+
667
+ // Focus the editor.
668
+ $wire.set.mockClear();
669
+ focusTracker.isFocused = true;
670
+
671
+ expect($wire.set).toHaveBeenCalledWith('focused', true);
672
+ });
630
673
  });
631
674
 
632
675
  describe('dispatch / receive events', () => {
@@ -101,7 +101,7 @@ export async function createLivewireSyncPlugin(
101
101
  const values = this.getEditorRootsValues();
102
102
 
103
103
  // Prevent looping when editor changed content from Livewire.
104
- if (!shallowEqual(values, component.canonical.content)) {
104
+ if (!shallowEqual(values, component.canonical.content ?? {})) {
105
105
  $wire.set('content', values);
106
106
  $wire.dispatch('editor-content-changed', {
107
107
  editorId: component.canonical.editorId,
@@ -127,7 +127,7 @@ export async function createLivewireSyncPlugin(
127
127
  $wire.set('focused', ui.focusTracker.isFocused);
128
128
 
129
129
  // Only push content if it has changed compared to canonical
130
- if (!shallowEqual(values, component.canonical.content)) {
130
+ if (!shallowEqual(values, component.canonical.content ?? {})) {
131
131
  $wire.set('content', values);
132
132
  }
133
133
  };