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

Uploading a PDF breaks the File Block #32673

Closed
mrfoxtalbot opened this issue Jun 14, 2021 · 3 comments
Closed

Uploading a PDF breaks the File Block #32673

mrfoxtalbot opened this issue Jun 14, 2021 · 3 comments
Labels
[Block] File Affects the File Block [Type] Bug An existing feature does not function as intended

Comments

@mrfoxtalbot
Copy link

mrfoxtalbot commented Jun 14, 2021

Steps to reproduce

  1. Add a file block with a PDF into a post
  2. Publish the post.
  3. Reload the post in the editor

What Happens?

  1. With the plugin (10.8) active, the file block renders the PDF preview just fine:

Screen Shot on 2021-06-14 at 18:28:09

  1. As soon as the plugin is deactivated and we use the core version of the editor (5.7.4), if the post is reloaded, it causes a block error.

Screen Shot on 2021-06-14 at 18:10:03

I noticed this error in the console:

Block validation: Expected tag name `a`, instead saw `object`.

Content generated by `save` function:

<div class="wp-block-file"><a href="http://localhost:10018/wp-content/uploads/2021/06/FITXA-DADOPCIO-NATURA-VIVA-2.pdf">FITXA-DADOPCIO-NATURA-VIVA-2</a><a href="http://localhost:10018/wp-content/uploads/2021/06/FITXA-DADOPCIO-NATURA-VIVA-2.pdf" class="wp-block-file__button" download>Download</a></div>

Content retrieved from post body:

<div class="wp-block-file"><object class="wp-block-file__embed" data="http://localhost:10018/wp-content/uploads/2021/06/FITXA-DADOPCIO-NATURA-VIVA-2.pdf" type="application/pdf" style="width:100%;height:600px" aria-label="Embed of FITXA-DADOPCIO-NATURA-VIVA-2."></object><a href="http://localhost:10018/wp-content/uploads/2021/06/FITXA-DADOPCIO-NATURA-VIVA-2.pdf">FITXA-DADOPCIO-NATURA-VIVA-2</a><a href="http://localhost:10018/wp-content/uploads/2021/06/FITXA-DADOPCIO-NATURA-VIVA-2.pdf" class="wp-block-file__button" download>Download</a></div>

@Mamaduka
Copy link
Member

Hi, @mrfoxtalbot

I think this is expected behavior. Gutenberg 10.5 introduced PDF previews, including new markup with <object> - #30857.

So if a user uploads PDF with the latest version of Gutenberg and then switches to a version that doesn't support PDF previews, validation should fail.

@simison
Copy link
Member

simison commented Jun 15, 2021

Yep +1, expected.

As soon as the plugin is deactivated and we use the core version of the editor (5.7.4), if the post is reloaded, it causes a block error.

This would cause issues with any block that has changes done in the plugin but not yet in the core WordPress.

@mrfoxtalbot
Copy link
Author

mrfoxtalbot commented Jun 15, 2021

Ah, that makes sense! Adding a PDF file with the plugin active will create a "special" subset of the file block which does not exist in the core version, and breaks without the plugin.

Screen Shot on 2021-06-15 at 18:10:19

Thank you for the clarification! @simison y @Mamaduka
I am going to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] File Affects the File Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants