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

File Block re-enables "Show inline embed" when replacing file #67248

Closed
4 of 6 tasks
MadtownLems opened this issue Nov 22, 2024 · 5 comments · Fixed by #67263
Closed
4 of 6 tasks

File Block re-enables "Show inline embed" when replacing file #67248

MadtownLems opened this issue Nov 22, 2024 · 5 comments · Fixed by #67263
Assignees
Labels
[Block] File Affects the File Block [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@MadtownLems
Copy link

MadtownLems commented Nov 22, 2024

Description

When a file block, which has had "Show inline embed" off, has its file replaced - "Show inline embed" toggles itself back on. Simply replacing the file should update as few settings as possible, and this one should not be toggled on.

(This feels similar to #66979 , where replacing an Image Block's image can alter settings. I feel like there could be a movement to get 'replace' functionality more clearly defined and consistent.)

Step-by-step reproduction instructions

  1. Insert a File Block.
  2. Select a PDF
  3. Disable "Show inline embed"
  4. Replace the file with a different one
  5. See that "Show inline embed" is toggled back on and a preview is shown

Screenshots, screen recording, code snippet

No response

Environment info

WordPress 6.7.1 (and 6.6.2), variety of themes, no Gutenberg plugin

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
@MadtownLems MadtownLems added the [Type] Bug An existing feature does not function as intended label Nov 22, 2024
@t-hamano t-hamano added the [Block] File Affects the File Block label Nov 23, 2024
@Sukhendu2002
Copy link
Contributor

Hi @MadtownLems, Thanks for reporting this issue. I was able to reproduce it. Replacing the file toggles "Show inline embed" back on, even when it was previously disabled. Tested on WordPress 6.7 and 6.7.1 with various themes and no active plugins.

@Mamaduka
Copy link
Member

I've not tested it, but something like this should help retain PDF-related attributes.

diff --git packages/block-library/src/file/edit.js packages/block-library/src/file/edit.js
index 937eb3d28eb..6415cb83f52 100644
--- packages/block-library/src/file/edit.js
+++ packages/block-library/src/file/edit.js
@@ -128,15 +128,21 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) {
 		}
 
 		const isPdf = newMedia.url.endsWith( '.pdf' );
+		const pdfAttributes = isPdf
+			? {
+					displayPreview: attributes.displayPreview ?? true,
+					previewHeight: attributes.previewHeight ?? 600,
+			  }
+			: { displayPreview: undefined, previewHeight: undefined };
+
 		setAttributes( {
 			href: newMedia.url,
 			fileName: newMedia.title,
 			textLinkHref: newMedia.url,
 			id: newMedia.id,
-			displayPreview: isPdf ? true : undefined,
-			previewHeight: isPdf ? 600 : undefined,
 			fileId: `wp-block-file--media-${ clientId }`,
 			blob: undefined,
+			...pdfAttributes,
 		} );
 		setTemporaryURL();
 	}

@Sukhendu2002
Copy link
Contributor

Hi @Mamaduka, Thanks for the input, I can see how it will help retain the PDF-related attributes. I will go ahead and implement the changes accordingly.

@Mamaduka
Copy link
Member

@Sukhendu2002, I saw your draft PR. Let me know when it's ready for the review.

@Sukhendu2002
Copy link
Contributor

Hi @Mamaduka, The PR is now ready for review. Please have a look when you get a chance.

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 [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants