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

Editor crashes when the content of a synced pattern is updated #6703

Closed
fluiddot opened this issue Mar 6, 2024 · 2 comments · Fixed by WordPress/gutenberg#59632
Closed
Labels
Reusable block [Type] Bug Something isn't working

Comments

@fluiddot
Copy link
Contributor

fluiddot commented Mar 6, 2024

Describe the bug

Note

Synced patterns (formerly named Reusable blocks) are only available on WPCOM sites.

In the mobile native version, we only cover the functionality of rendering the synced pattern. We don't support yet editing the content. However, its content might change locally due to side effects triggered during rendering.

As an example, having an Image block with a URL that doesn't contain the query parameter w (width) leads to an update. In this case, the Image block sets the width based on the size attribute and updates the URL. This update makes the editor crash with the error undefined is not a function.

To Reproduce

Preparation:

  1. On a web browser, navigate to the patterns page.
  2. Select the WP.com site for testing.
  3. Click on "Add new pattern".
  4. Add a title.
  5. Add an Image block.
  6. Edit the HTML of the Image block and remove the query parameters from the image source (e.g. ?w=1024).
  7. Publish it.

Steps:

  1. Create a post.
  2. Tap on ➕ button.
  3. Tap on "Synced patterns" tab.
  4. Tap the item created in the preparation section.
  5. Observe that the editor crashes.

Expected behavior
The editor shouldn't crash when using synced patterns.

Screenshots

Smartphone (please complete the following information):

  • Device: iPhone 11
  • OS: iOS 17.0.2
  • Version 24.4

Additional context
N/A

@fluiddot fluiddot added [Type] Bug Something isn't working Reusable block labels Mar 6, 2024
@fluiddot
Copy link
Contributor Author

fluiddot commented Mar 6, 2024

After investigating the issue, I found out the culprit. The crash is related to footnotes, which it's logic is part of the updates made in the hook useEntityBlockEditor. Let me share the trace of this logic to better explain the issue:

  1. Hook useEntityBlockEditor is used in the Provider component and in core/block (synced pattern):

  2. In useEntityBlockEditor, the function onChange updates footnotes. This function is triggered when there's an update in the block, for instance, when an attribute is updated.

  3. However, it only processes footnotes when the meta property of the entity is defined. This is not the case for the majority of blocks, but it is for core/block.

  4. As part of the footnotes logic, the function getFootnotesOrder calls getRichTextValuesCached.

  5. At the same time, the function getRichTextValuesCached uses getRichTextValues.

  6. getRichTextValues is a private API that is not exported in the native version:

Hence, the issue would be solved by simply exporting getRichTextValues.

@fluiddot
Copy link
Contributor Author

fluiddot commented Mar 6, 2024

Following wordpress-mobile/WordPress-iOS#22776 (comment), seems the issue can also be reproduced in Cover block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reusable block [Type] Bug Something isn't working
Projects
None yet
1 participant