Skip to content
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

Fix writer update issue #7001

Merged
merged 4 commits into from
Feb 13, 2025
Merged

Conversation

bastianallgeier
Copy link
Member

Description

The writer input records transactions for actual state updates but also for selections. So far, we don't check before we emit an input event. This leads to a quite nasty situation where selections or even just a focus even also emit an input event at the same time. With the new changes setup, this means that every selection change or focus event will send an update to the backend. This PR fixes this by checking for the involved steps in the transaction object. If there are no steps, there's no need to emit something.

Changelog

Fixes

Breaking changes

None

For review team

  • Add changes & docs to release notes draft in Notion

Copy link
Member

@afbora afbora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant!

@bastianallgeier
Copy link
Member Author

@afbora I've just made another change. We never really watch the preventUpdate meta data entry in the update method. But this is set on purpose in the value watcher to avoid sending additional input events when the value changed from the backend.

Before, hitting the discard button would always lead to another input event being triggered by the writer. After this change, the additional input events are gone.

@afbora
Copy link
Member

afbora commented Feb 13, 2025

@bastianallgeier
Copy link
Member Author

Oh, this is super weird. You are right. But it seems that it somehow still propagates to the update event. Then I have to track down why it is not being detected there.

@afbora
Copy link
Member

afbora commented Feb 13, 2025

OK. Also we can move the payload.transaction.steps.length check into Editor.js::dispatchTransaction() method to consistency.

@bastianallgeier
Copy link
Member Author

The update event seems to be triggered from somewhere else and I can't find it right now. It isn't enough to make that check in the dispatchTransaction method. Update still gets called.

I've also made another change. We trigger an input event when the editor is being initialized. This seems very wrong to me. I think we did this earlier when the HTML from the backend would be different from what the writer would create as document. In that case the values between backend and changes in local storage would not be exactly the same and the changes button would appear. But I think we don't really need this anymore with the new setup. But we have to test it some more.

@bastianallgeier
Copy link
Member Author

I just tested it with invalid HTML on the backend and it works flawlessly. I really think that the combination of cleaned up events and the new changes architecture will finally help us tame the Writer monster.

@afbora
Copy link
Member

afbora commented Feb 13, 2025

@bastianallgeier I think if condition is wrong, it should be like that: use and operator instead or. Just following changes works for me.

// Only emit an update if the doc has changed and
// an update has not been actively prevented
if (
  transaction.docChanged &&
  !transaction.getMeta("preventUpdate") &&
  transaction.steps.length > 0
) {
  this.emit("update", payload);
}

https://github.com/getkirby/kirby/blob/v5/fix/6959-writer-update-issue/panel/src/components/Forms/Writer/Editor.js#L288

@bastianallgeier
Copy link
Member Author

bastianallgeier commented Feb 13, 2025

This is embarrasing. You are totally right. The || broke the logic there 🙈 Works like a charm now.

@bastianallgeier bastianallgeier merged commit 8378beb into v5/develop Feb 13, 2025
4 checks passed
@bastianallgeier bastianallgeier deleted the v5/fix/6959-writer-update-issue branch February 13, 2025 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants