Skip to content

[6.x] Fix Bard set disappearing after save#14956

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
eminos:fix/bard-set-remove-empty-nodes
Jul 8, 2026
Merged

[6.x] Fix Bard set disappearing after save#14956
jasonvarga merged 1 commit into
statamic:6.xfrom
eminos:fix/bard-set-remove-empty-nodes

Conversation

@eminos

@eminos eminos commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #14688.

Summary

This fixes a Bard CP sync issue where a Bard field containing only a single set could appear to lose that set after the first save when remove_empty_nodes is configured to trim empty nodes at the start and end.

The backend processing is not actually deleting the set. With remove_empty_nodes: trim, PHP correctly trims the surrounding empty paragraph nodes and preserves the set. That also matches the reported behavior: refreshing the page makes the set appear again, which means the saved value is still present.

The problem is in the frontend watcher that syncs an externally updated Bard value back into the Tiptap editor after save:

this.editor.commands.clearContent();
this.editor.commands.setContent(content, true);

clearContent() emits an update with an empty paragraph before setContent() applies the real server value. For a Bard field whose server-trimmed value is only a set, that intermediate empty update can be picked up by the publish state, making the set disappear visually until the page is refreshed.

This PR changes the clear step to be silent:

this.editor.commands.clearContent(false);
this.editor.commands.setContent(content, true);

That keeps the editor replacement behavior the same, but avoids emitting the temporary empty Bard value. The final setContent(content, true) still emits the real updated value.

Tests

  • vendor/bin/phpunit tests/Fieldtypes/BardTest.php
  • npm run test

I also added a regression test confirming that trimming empty Bard nodes preserves a set surrounded by empty paragraphs.

Note

This PR is being submitted from eminos GitHub account, but the investigation, patch, and PR write-up were prepared by Codex GPT 5.5.

@eminos eminos changed the title Fix Bard set disappearing after save [6.x] Fix Bard set disappearing after save Jul 8, 2026
@eminos

eminos commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

I've done a manual test on a production website with this patch, and it seems to fix the issue without breaking anything (visible) 🙂

@jasonvarga jasonvarga merged commit 6fa971b into statamic:6.x Jul 8, 2026
20 of 22 checks passed
@eminos eminos deleted the fix/bard-set-remove-empty-nodes branch July 8, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unique set in bard field is removed on first save when "remove_empty_node" option is set to "Remove empty nodes at the start and end"

2 participants