Ghost/ghost/admin/app/components/modals/editor/confirm-leave.hbs
Steve Larson 59b304dfca
🐛 Fixed editor 'are you sure?' modal displaying when no user changes occurred (#20370)
ref https://linear.app/tryghost/issue/ENG-661
- added a dirty check to ignore the `direction` field from the lexical
object; this is set dynamically and shouldn't be serialized, see
facebook/lexical/issues/4998
- fixed a bug where the modal wouldn't display on leaving the editor if
the post had no revisions (e.g. import); this could result in content
being saved over published content with no user action
- added Sentry logging for the modal

We would sometimes see the "Are you sure?" modal pop up when opening a
post in the editor and attempting to navigate away immediately, without
any changes to the post. This appears to be an issue with the serialized
Lexical data, which would change after loading into the editor,
resulting in the scratch and model's lexical values to differ, making
Admin think the user changed the content.

Ideally we'll see a fix upstream (or fix it ourselves). We may need to
revisit this if we experience other such situations. It's awfully
difficult to be able to set a flag saying 'the editor is done loading',
so this seems to be the best path for the moment.

Testing is difficult because we don't actually load the new Lexical editor into e2e/acceptance tests. I've added a unit test that can at least simulate the editor state changing on editor load.
2024-06-13 11:07:56 -05:00

21 lines
853 B
Handlebars

<div class="modal-content" data-test-modal="unsaved-post-changes">
<header class="modal-header">
<h1>Are you sure you want to leave this page?</h1>
</header>
<button class="close" title="Close" type="button" {{on "click" @close}}>{{svg-jar "close"}}<span class="hidden">Close</span></button>
<div class="modal-body">
<p>
Hey there! It looks like you're in the middle of writing something and
you haven't saved all of your content.
</p>
<p>Save before you go!</p>
</div>
<div class="modal-footer">
<button class="gh-btn" data-test-stay-button type="button" {{on "click" @close}}><span>Stay</span></button>
<button class="gh-btn gh-btn-red" data-test-leave-button type="button" {{on "click" (fn @close true)}}><span>Leave</span></button>
</div>
</div>