Skip to content

[WIP] Forms: Try using inner blocks for file upload field #42980

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

Conversation

aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented Apr 9, 2025

⚠️ Please note this is a draft PR based off #42890 to illustrate how a complete inner blocks approach for the file field might work ⚠️

Proposed changes:

This isn't a full implementation as it doesn't update the frontend rendering of the file field to ensure the correct classes and styles are applied e.g. the default block class and block supports.

Screenshot_09-Apr_19-26-18_2720

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

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

Testing instructions:

  • Go to '..'

Introduces foundational form field blocks:
- jetpack/input
- jetpack/label
- jetpack/option
- jetpack/options

These blocks will be reused across all field types using inner blocks.
- Prevents adding bulk changes when syncing blocks to the undo stack
- Correctly determines the parent field block for option blocks to check
  if syncing is enabled
- Correctly find all option blocks regardless of whether they are a
  field's direct child, e.g. consent, or nested within an options block
  e.g. single/multiple choice fields.
Updates legacy form field blocks to use shared inner blocks:
- jetpack/input
- jetpack/label
- jetpack/option
- jetpack/options

This commit also updates the registration of form blocks so the new
shared blocks are available in the editor.
Note: This commit does not address updating the frontend rendering to
include the correct block classes and inline styles from block supports.
@aaronrobertshaw aaronrobertshaw added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Block] Contact Form Form block (also see Contact Form label) [Package] Forms [Feature] Forms Blocks Blocks designed to streamline user input and engagement, such as contact, newsletter sign-ups, etc. labels Apr 9, 2025
@aaronrobertshaw aaronrobertshaw requested a review from edanzer April 9, 2025 09:21
@aaronrobertshaw aaronrobertshaw self-assigned this Apr 9, 2025
Copy link
Contributor

github-actions bot commented Apr 9, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the try/file-field-with-inner-blocks branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack try/file-field-with-inner-blocks

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

github-actions bot commented Apr 9, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • 🔴 Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


🔴 Action required: Please add missing changelog entries for the following projects: projects/packages/forms

Use the Jetpack CLI tool to generate changelog entries by running the following command: jetpack changelog add.
Guidelines: /docs/writing-a-good-changelog-entry.md


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Apr 9, 2025
Copy link

Code Coverage Summary

Cannot generate coverage summary while tests are failing. 🤐

Please fix the tests, or re-run the Code coverage job if it was something being flaky.

Full summary · PHP report · JS report

{
url: DEFAULT_ICON,
width: 24,
height: 24,
Copy link
Contributor

Choose a reason for hiding this comment

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

The addition of these width / height attributes seems to be creating an issue. When I first insert the block it loads as expected. I can see the width/height attributes set correctly to 24 px on the sidebar. If I save and check the frontend, the block loads as expected.

But... if I just refresh the editor, I get a block validation error. Here's the error:

blocks.js?ver=e851ee8e9644a9abf7ed:11967 Block validation: Block validation failed for `core/image` ({name: 'core/image', icon: {…}, keywords: Array(7), attributes: {…}, providesContext: {…}, …}).

Content generated by `save` function:

<figure class="wp-block-image aligncenter is-resized is-style-default" style="margin-bottom:20px"><img src="https://erick2.jurassic.tube/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-forms/assets/images/upload-icon.svg" alt=""/></figure>

Content retrieved from post body:

<figure class="wp-block-image aligncenter is-resized is-style-default" style="margin-bottom:20px"><img src="https://erick2.jurassic.tube/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-forms/assets/images/upload-icon.svg" alt="" style="width:24px;height:24px"/></figure>

Here's an image:
icon-block-validation

In short, the save function content does not contain the style tag with width/height.

@edanzer
Copy link
Contributor

edanzer commented Apr 16, 2025

Rather than deal with complex merge conflicts after rebase of base branch, just moved work to #43114

Closing in favor of that PR.

@edanzer edanzer closed this Apr 16, 2025
@github-actions github-actions bot removed [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Contact Form Form block (also see Contact Form label) [Feature] Contact Form [Feature] Forms Blocks Blocks designed to streamline user input and engagement, such as contact, newsletter sign-ups, etc. [Package] Forms [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants