If a Subscription Block is added to a post with one localization, then subsequently edited in another localization, the block will be invalidated with no good way of recovering. The default texts in the block must be maintained, customization of the texts will prevent invalidation.
Core Gutenberg is working out how to handle situations like this:
Some of the default block attributes are localized with __:
https://github.com/Automattic/jetpack/blob/db3e47183b64a343aa594fd32a815483bfdf302d/extensions/blocks/subscriptions/attributes.js#L7-L10
https://github.com/Automattic/jetpack/blob/db3e47183b64a343aa594fd32a815483bfdf302d/extensions/blocks/subscriptions/attributes.js#L19-L22
These attributes are stored directly in the save function:
https://github.com/Automattic/jetpack/blob/db3e47183b64a343aa594fd32a815483bfdf302d/extensions/blocks/subscriptions/save.js#L24-L47
https://github.com/Automattic/jetpack/blob/db3e47183b64a343aa594fd32a815483bfdf302d/extensions/blocks/subscriptions/save.js#L105-L129
The block may be saved with a localized text Enter your email address, then when the editor loads and validates the block content, it finds an unexpected localization (e.g. _Dirección de correo electrónico_) and determines that the block content is not valid.
I wrote about the problem of "impure save" here in more detail: pafL3P-kL-p2
In this case, translations implicitly leak into the block's save, rendering them impure and susceptible to invalidation.
This causes the following issues:
This has been present since the very first iteration of the block: https://github.com/Automattic/wp-calypso/pull/28887
cc: @obenland @iamtakashi
/wp-admin/admin.php?page=jetpack#/discussion)/wp-admin/post-new.php)/subscription)/wp-admin/options-general.php)/wp-admin/update-core.php)Save (English):

Load (Spanish):

Block validation: Block validation failed for `jetpack/subscriptions` ({name: "jetpack/subscriptions", icon: {…}, …
Content generated by `save` function:
<div class="wp-block-jetpack-subscriptions">[jetpack_subscription_form show_subscribers_total="false" show_only_email_and_button="true"]</div>
Content retrieved from post body:
<div class="wp-block-jetpack-subscriptions">[jetpack_subscription_form show_only_email_and_button="true" custom_background_button_color="undefined" custom_text_button_color="undefined" submit_button_text="Subscribe" submit_button_classes="undefined" show_subscribers_total="false" ]</div>
I added 8.6 milestone from #15475.
cc @apeatling who's been working on some improvements to the Subscriptions block.
I was doing some additional testing and it doesn't seem like you can modify the placeholder text through the block UI at all.
Ah bummer, this was tested (https://github.com/Automattic/jetpack/pull/15107#discussion_r401088736) but somehow slipped still through.
@sirreal Did you test this with the updates to the block in master? I couldn't reproduce this when I was working on it, but I probably wasn't doing it correctly. I'll try again today.
@apeatling Yep, I just spun up a new site with Jetpack beta "Bleeding edge" build and was able to reproduce the issue following the instructions in the description.
Couple of options I can think of:
Remove the defaults as translatable for these two strings. The user can update the input button text on their own, and we can make the placeholder text editable.
Remove the defaults as translatable and add logic to the edit component to check for a different translation and update it once the block has been loaded (assuming the value hasn't been edited).
??
I think source: html would be a solution here, since by default the text is stored in the HTML comment which can lead to incompatible data (English attribute, translated HTML).
Note that this affects several blocks
(and maybe others--I only searched through the attributes.js files, so this may have missed blocks that set default attributes in other ways)
Note that this affects several blocks
I'm not sure if it was the same reason, but the Map block and the Contact Info block were also broken (invalidated) with the translations for all the Mag 16, and I had to manually fix in the json files. It was really time-consuming, and the issue blocks us to deploy layouts regularly.
Note, I updated my comment above to indicate that it's not an exhaustive list
(and maybe others--I only searched through the
attributes.jsfiles, so this may have missed blocks that set default attributes in other ways)
I think source: html would be a solution here, since by default the text is stored in the HTML comment which can lead to incompatible data (English attribute, translated HTML).
In the case of the contact form and subscription blocks, the source: html is not going to work because the save function creates a shortcode that is then rendered via the backend at runtime.
It could work for the other blocks that do not do this however.
I tried this with the Calendly block, but I'm not having any luck with selecting via source: html or text because of the server side rendering.
@lessbloat This might be a good candidate for the Manage Janitorial rotation
@creativecoder by the looks of it, this is likely too complex for the Janitor rotation.
Note that this affects several blocks
* [Subscriptions](https://github.com/Automattic/jetpack/blob/3466b0681a195db76416077b8d3647f877f41448/extensions/blocks/subscriptions/attributes.js#L9) * [Eventbrite](https://github.com/Automattic/jetpack/blob/3466b0681a195db76416077b8d3647f877f41448/extensions/blocks/subscriptions/attributes.js#L9) * [Calendly](https://github.com/Automattic/jetpack/blob/3466b0681a195db76416077b8d3647f877f41448/extensions/blocks/calendly/attributes.js#L21) * [Revue](https://github.com/Automattic/jetpack/blob/3466b0681a195db76416077b8d3647f877f41448/extensions/blocks/revue/attributes.js#L13) * [Contact Form](https://github.com/Automattic/jetpack/blob/5fbf71770770dc16d20eae74c07946493a89945a/extensions/blocks/contact-form/attributes.js#L9)(and maybe others--I only searched through the
attributes.jsfiles, so this may have missed blocks that set default attributes in other ways)
I've just run a quick test, and of these only Subscriptions seems to be affected.
(TBH I haven't tried _all_ Contact Form variations, but it shouldn't matter)
The difference is that those blocks don't save the localized attributes in the block content, whereas Subscriptions does.
<!-- wp:jetpack/revue {"revueUsername":"test"} -->
<div class="wp-block-jetpack-revue">
<!-- wp:jetpack/button {"element":"button","text":"Subscribe"} /-->
<a class="wp-block-jetpack-revue__fallback" href="https://www.getrevue.co/profile/test">
https://www.getrevue.co/profile/test
</a>
</div>
<!-- /wp:jetpack/revue -->
Revue has all the fields labels and placeholders as localized attributes, plus the button text, which is an attribute of the Button inner block.
No field labels/placeholders are saved in the block content, as the form is built server-side.
The inner Button doesn't break because the parent block is actually defining it with the localized attribute: in other words, we are actually _setting_ its text attribute with the localized string.
The side effect is that changing the site language won't also change the Button text.
This might be considered an issue, though, but a different one.
<!-- wp:jetpack/subscriptions -->
<div class="wp-block-jetpack-subscriptions wp-block-jetpack-subscriptions__supports-newline">
[jetpack_subscription_form
subscribe_placeholder="Enter your email address"
submit_button_text="Sign Up"
]</div>
<!-- /wp:jetpack/subscriptions -->
Subscriptions (example trimmed for readability), instead, saves the defaults in the block content.
As pointed out by @sirreal, when the block loads with a different translation, it tries to match it with the block content, and fails, breaking the block.
I'm still trying to figure out a good solution, though.
SSR-ing the block is not a good one, as we want the shortcode to stay in the post content.
Maybe instead of having attribute _defaults_, we could actually save them as attribute _values_?
We would end up with the same issue I've pointed out earlier about the Button inner block, but I'd argue it's better than having the block break? 🤔
Actually I think I've found a nice solution! ✨
I've unassigned myself, but of course feel free to pick #16361 up! 🙂