awcodes / filament-tiptap-editor

A Rich Text Editor plugin for Filament Forms.
MIT License
249 stars 64 forks source link

Editor state not reset when nested #385

Closed freshleafmedia closed 3 weeks ago

freshleafmedia commented 1 month ago

Filament Version

v3.2.76

Plugin Version

v3.3.3

PHP Version

8.3.6

Problem description

When the schema of a block contains a TiptapEditor the editor state is not reset when adding a second block.

I appreciate that nested editors isn't necessarily an intended feature however it allows for some very dynamic customisation, any pointers on how to fix the issue or where the issue is coming from would be appreciated.

Expected behavior

The editor value should be blank

Steps to reproduce

https://github.com/awcodes/filament-tiptap-editor/assets/10062339/43b6b77c-ba25-4d71-8b86-a2215e7f5b1c

Reproduction repository

https://github.com/freshleafmedia/tiptap-repro

Relevant log output

No response

freshleafmedia commented 1 month ago

I think I have narrowed it down. The TiptapEditors in each block are assigned the same statePath. It's effectively like doing:

$schema = [
    TiptapEditor::make('nested-content'),
    TiptapEditor::make('nested-content'),
];

So obviously they have the same state.

:thinking:

freshleafmedia commented 1 month ago

The state saved to the database is correct, it is only the displayed state which is incorrect...

@awcodes Would you be able to have a look at this issue, I am stumped. I am willing to sponsor you for your time.

Thanks.

awcodes commented 1 month ago

Looked into this a little today. Not sure if it's an issue with the plugin or in filament, where the block is not getting nested in its parent state. Probably not an a filament issue but not 100% sure at this point.

awcodes commented 1 month ago

And since the plugin uses a global manager for the editors on the page, (weird bug with alpine and Tiptap not understanding alpine's proxy usage) that are keyed by the statePath it's difficult to have a solid way to destroy them in the object.

awcodes commented 1 month ago

If it helps you to try to help. In the devtools console you can inspect the editor instances with window.filamentTiptapEditors.

awcodes commented 1 month ago

State management and modals have been the biggest problems with this thing.

awcodes commented 1 month ago

Was actually easier before Livewire v3 when alpine and livewire were independent of each other. 😅

awcodes commented 1 month ago

Update: mostly have this fixed. But need a better way to manage the editors when the modal can have two editors tied to the same root state.

awcodes commented 3 weeks ago

I have this modal stuff solved, I think. But it introduced a regression with repeaters and builders. I'm trying to get it solved. Thanks again for your patience.

awcodes commented 3 weeks ago

Check v3.4.0 and please reopen if you are still having issues.