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

Inconsistent behaviour for modified badges and Matrix fields #9814

Closed
mmikkel opened this issue Sep 9, 2021 · 5 comments
Closed

Inconsistent behaviour for modified badges and Matrix fields #9814

mmikkel opened this issue Sep 9, 2021 · 5 comments
Labels
authoring ✍️ features related to author experience bug

Comments

@mmikkel
Copy link
Contributor

mmikkel commented Sep 9, 2021

Description

There is some peculiar behaviour going on with modified badges (i.e. those blue lines) and Matrix fields:

  1. When adding (or removing) a block, Craft will add a blue line to the entire Matrix field. But, when reloading the draft (without applying it), the blue line is gone.
  2. After reloading the draft, if a field in a new Matrix block (i.e. a Matrix block that only exists for the draft and hasn't been saved as part of the current entry yet) is edited, Craft adds a blue line to the field. But again, if the draft is reloaded the blue line for that subfield disappears.

Steps to reproduce

  1. Open up the edit page for an existing entry (current), with a Matrix field in its layout
  2. Add a block. Note that the entire Matrix field is marked with a blue line.
  3. Reload the browser. Note that the blue line for the Matrix field is gone.
  4. After reloading, edit a field in the block that just added. Note that a blue line is added to the subfield.
  5. Reload the browser again. Note that the blue line that was added to the field in the new block, is now gone. Any lines added to edited fields in pre-existing blocks are retained, though.

Additional info

The behaviour seems to be identical for provisional drafts and "real" drafts.

  • Craft version: 3.7.12
  • PHP version: 7.4
  • Database driver & version:
  • Plugins & versions: none
@mmikkel mmikkel added the bug label Sep 9, 2021
@brandonkelly
Copy link
Member

These discrepancies are due to PHP and JS having different ways of determining field modification statuses. When you initially load the page, each field type has a chance to get determine whether it should appear as modified. (Matrix chooses to not show that, as its nested fields will get their own modification statuses.) Whereas when edits are autosaved via JS, we can’t (currently) get field types’ input on their modification statuses without completely re-rendering the form, which would slow the autosave down considerably. So instead the JS makes its best guess as to where the new status badges should be added.

I do hope to come up with a way for the back-end to drive the front-end status indicators down the road though, so will leave this open and update it when I come up with something.

@brandonkelly brandonkelly added the authoring ✍️ features related to author experience label Sep 9, 2021
@mmikkel
Copy link
Contributor Author

mmikkel commented Sep 9, 2021

Right, I completely get that getting consistent status indicators without a single source of truth for the changes is difficult (would it be possible to return all the fields’ modification statuses as part of the auto-save payload, instead of having the JS guess?)

Matrix chooses to not show that, as its nested fields will get their own modification statuses.

This is the part that sticks out to me as potentially the most problematic, though - on the initial pageload for an existing draft, there’ll be no indicators at all for Matrix fields where blocks have been added or removed - ie the Matrix field appears untouched. That makes it really easy to miss that a change has been made to the field, as authors will reasonably come to expect indicators for any and all changes, relative to the current entry.

@brandonkelly
Copy link
Member

would it be possible to return all the fields’ modification statuses as part of the auto-save payload, instead of having the JS guess?

That would only work for top-level fields, unfortunately.

This is the part that sticks out to me as potentially the most problematic, though - on the initial pageload for an existing draft, there’ll be no indicators at all for Matrix fields where blocks have been added or removed - ie the Matrix field appears untouched. That makes it really easy to miss that a change has been made to the field, as authors will reasonably come to expect indicators for any and all changes, relative to the current entry.

Yeah good point. I just tweaked this so the entire Matrix field gets highlighted when changed, in addition to the sub-field. So that should basically resolve this, as field status highlights are now consistent for Matrix fields across JS and page reloads.

@mmikkel
Copy link
Contributor Author

mmikkel commented Sep 13, 2021

I just tweaked this so the entire Matrix field gets highlighted when changed, in addition to the sub-field.

Sounds great, thanks Brandon.

@brandonkelly
Copy link
Member

Craft 3.7.13 is out now with that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
authoring ✍️ features related to author experience bug
Projects
None yet
Development

No branches or pull requests

2 participants