Hi,
Environment: Bricks 2.4.4, WordPress 7.1.4, Bricks MCP abilities called through the MCP adapter (mcp-adapter-execute-ability).
Steps:
- bricks/duplicate-post on template 7557 → draft template 7763.
The Code element’s javascriptCode is copied correctly, backslashes intact. - bricks/set-page-elements on 7763 with the same element tree (flat format),
javascriptCode sent unchanged. - bricks/get-page-elements on 7763.
Expected: javascriptCode unchanged.
Actual: every backslash is removed. Examples from the stored value:
before: return price.toFixed(2).replace(/\d(?=(\d{3})+.)/g, ‘$&,’);
after: return price.toFixed(2).replace(/d(?=(d{3})+.)/g, ‘$&,’);
before: originalPrice.match(/(.+?)/);
after: originalPrice.match(/(.+?)/);
The save returned success (changed: true, new revisionId), so the corruption is silent.
It is not limited to set-page-elements. Second test on a fresh duplicate (7767):
- set-page-elements with the backslashes doubled stored the code correctly;
- then bricks/update-element on a different element (root section, setting _cssClasses)
returned success, and the Code element’s javascriptCode had lost all its backslashes again.
So any MCP write re-saves the whole document and strips backslashes from every element.
Also seen: bricks/update-element on the Code element itself with the original value fails
with bricks_conflict_document_write_conflict (“The Bricks document changed while it was
being saved. No candidate data was committed.”).
Impact: one MCP write to any page or template holding JavaScript with regular expressions
or escaped characters silently breaks that code on every page using it.
We found it on draft copies; the live template was not touched.
Suspected cause: the element data is saved with update_post_meta() without wp_slash(),
so WordPress’ wp_unslash() removes the backslashes. The builder’s own save does not have
this problem.