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

Subscriptions Block: Stop saving localized attributes defaults in the block content #16361

Merged

Conversation

Copons
Copy link
Contributor

@Copons Copons commented Jul 1, 2020

Fixes #15776

Changes proposed in this Pull Request:

  • Stop saving localized attributes defaults in the Subscriptions block content.

The Subscriptions block has two attributes with localized default values which are saved in the block content as shortcode attributes. Changing the site language will break the block validation, because the strings are saved in the previous language, while the validator expects them to be in the new language.

In this PR we stop adding those attributes to the shortcode if they are the same as the default (haven't been changed by the user).

The shortcode will take care of those missing attributes by using its own defined defaults.

Note

There have been two deprecated versions added. The first handles the normal migration when the language hasn't changed. The second almost identical one, allows for the placeholder text, if left to default values, to fall back to the known English version of the text. It does not change the attribute values just the generated content from the deprecated save so the block isn't invalidated.

Unfortunately, this will only be able to solve the case when the block was created in English, the site switched to a new language and then the block loaded in the editor again afterwards. If the block was created in a non-English language then the site switched to English, we don't know what the original default text should be so can't fallback to it.

Migrating the block and saving the post before changing the language would fix it.

Repro steps:

  1. Add a Subscriptions block on master, and save the post.
  2. Checkout this branch.
  3. Change site language.
  4. Reload the editor: the block breaks. 👎

Working steps:

  1. Add a Subscriptions block on master, and save the post.
  2. Checkout this branch.
  3. Reload the editor, let the block migrate, and save the post.
  4. Change site language.
  5. Reload the editor: the block works. 👍

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

  • Before checking out this PR:
    • Edit a post and add two Subscriptions block. (You will need to be connected to WordPress.com).
    • Leave one unchanged, and update the button label of the other.
    • Save the post.
  • Checkout this PR, build the extensions, and reload the editor.
  • Make sure the blocks have migrated without errors.
  • Check the code view, and make sure the shortcode attributes are not output in separate lines anymore (this will confirm the blocks are using the new save function).
    E.g.
- [jetpack_subscription_form
-		attribute="value"
-		another_attribute="value"
- ]
+ [jetpack_subscription_form attribute="value" another_attribute="value"]
  • Without saving the post, change the site language in /wp-admin/options-general.php, and make sure you also install the new language pack in /wp-admin/update-core.php.
  • Reload the editor and make sure the blocks don't break anymore.
  • Make sure that the button label of the block left unchanged is now translated in the new language.

Proposed changelog entry for your changes:

  • Subscriptions Block: Stop saving localized attributes defaults in the block content

@Copons Copons added [Type] Bug When a feature is broken and / or not performing as intended [Status] In Progress [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Block] Subscriptions labels Jul 1, 2020
@Copons Copons self-assigned this Jul 1, 2020
@jetpackbot
Copy link
Collaborator

jetpackbot commented Jul 1, 2020

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-16361

Scheduled Jetpack release: August 4, 2020.
Scheduled code freeze: July 28, 2020

Generated by 🚫 dangerJS against dad622e

@Copons Copons requested review from sirreal and a team July 1, 2020 17:50
@Copons Copons added [Pri] High [Focus] i18n Internationalization / i18n, adaptation to different languages labels Jul 1, 2020
@Copons Copons removed their assignment Jul 6, 2020
@aaronrobertshaw aaronrobertshaw self-assigned this Jul 6, 2020
@aaronrobertshaw aaronrobertshaw added [Status] Needs Team Review Obsolete. Use Needs Review instead. and removed [Status] In Progress labels Jul 8, 2020
scruffian
scruffian previously approved these changes Jul 8, 2020
Copy link
Member

@scruffian scruffian left a comment

Choose a reason for hiding this comment

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

This looks good to me, and works as advertised. At some point we should remove the shortcode implementation, but that's for another PR 🚢

@scruffian scruffian added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Team Review Obsolete. Use Needs Review instead. labels Jul 8, 2020
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This is going to need a rebase to fix those unrelated test failures, I'm afraid. Thank you!

@jeherve jeherve added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Jul 8, 2020
@jeherve jeherve added this to the 8.8 milestone Jul 8, 2020
@sirreal sirreal removed their request for review July 8, 2020 15:30
Copons and others added 2 commits July 8, 2020 17:48
When a block is created in English and the site switched to a second langauge before the block is migrated, the block will be deemed invalid.

This change will attempt to fall back to English defaults for the placeholder text in the saved shortcode that causes the invalidation. This will not change migrated attributes only the generated content from the deprecated block save function. It also will only cover blocks first created in English and using default text. If the block was created in a second language, there is no means to determine the language and therefore the default text for that translation to fall back to.
@scruffian scruffian force-pushed the try/blocks-fix-default-attributes-translations branch from e93e8d5 to 58d11ef Compare July 8, 2020 16:48
@scruffian
Copy link
Member

Rebase ✅

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello Copons! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D46159-code before merging this PR. Thank you!
This revision will be updated with each commit to this PR

@aaronrobertshaw
Copy link
Contributor

This one was rebased already. D46159-code has been updated with new files.

@scruffian scruffian added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Jul 9, 2020
@apeatling
Copy link
Member

apeatling commented Jul 9, 2020

I'm testing this one, can confirm this breaks on master when switching languages. When I switch to this branch after saving the block on master, rebuild, and reload the editor I get:

Screen Shot 2020-07-09 at 9 33 39 AM

@apeatling apeatling self-requested a review July 9, 2020 16:34
@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Jul 20, 2020
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This tests well for me. 👍

@aaronrobertshaw aaronrobertshaw merged commit 01eeddd into master Jul 21, 2020
@aaronrobertshaw aaronrobertshaw deleted the try/blocks-fix-default-attributes-translations branch July 21, 2020 05:37
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Jul 21, 2020
jeherve added a commit that referenced this pull request Jul 28, 2020
@jeherve
Copy link
Member

jeherve commented Aug 4, 2020

r211582-wpcom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Subscriptions [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Focus] i18n Internationalization / i18n, adaptation to different languages [Pri] High Touches WP.com Files [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Subscriptions Block: Invalidates when edited in different language
7 participants