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

Allow saving in FSE for Form Options #1834

Merged
merged 6 commits into from
Sep 12, 2023
Merged

Conversation

Soare-Robert-Daniel
Copy link
Contributor

@Soare-Robert-Daniel Soare-Robert-Daniel commented Aug 29, 2023

Closes #1802

Summary

[UPDATED]

A straightforward solution to this problem is to insert a dummy block and then delete it immediately. This will mark the block as dirty, thus enabling the Post/Page saving. The functionality is wrapped in a debounce function, which prevents multiple events from triggering simultaneously.

ℹ️ This works reliably in Post/Pages/FSE/Widgets/Customizer 🔥

[OLD SOLUTION]

Usually, the Save button is enabled when you make a change to the content of the post/page. The problem arises when some functionality is not tied to the content but is triggered by the Save button.

Form Options live in the WP Options. When a user changes something in the Form the Mail, the values must be saved in WP Options to take effect. They are not tied to the block attributes, thus making them invisible for the Editor to detect changes.

After some heavy investigation regarding the saving mechanism in the Gutenberg editor, a simple trick to enable the saving is to make a request using the function dispatch( 'core' ).editEntityRecord.

In this PR, we implement a function that makes this request by adding an unregistered meta value to the entity. Since it is unregistered, the value is not saved anymore, but making the request marks the post/page as dirty, thus enabling the Save button.

⚠️ This is not working with Widgets on the widget page.

Screenshots

2023-08-29.17-36-19.mp4

Test instructions

  1. Use an FSE theme.
  2. Add a form inside of the templates/pages.
  3. Save the form as it is, then change some values in the Form Options.
  4. Save button should be available.

⚠️ The Save will be available after 3 seconds without modification. As long as you type or change something in the Form options within 3 seconds, it will not trigger.

⚠️ You should notice Form options have been saved, which confirms the save request.


Checklist before the final review

  • Included E2E or unit tests for the changes in this PR.
  • Visual elements are not affected by independent changes.
  • It is at least compatible with the minimum WordPress version.
  • It loads additional script in frontend only if it is required.
  • Does not impact the Core Web Vitals.
  • In case of deprecation, old blocks are safely migrated.
  • It is usable in Widgets and FSE.
  • Copy/Paste is working if the attributes are modified.
  • PR is following the best practices

@Soare-Robert-Daniel Soare-Robert-Daniel added the pr-checklist-skip Allow this Pull Request to skip checklist. label Aug 29, 2023
@Soare-Robert-Daniel Soare-Robert-Daniel self-assigned this Aug 29, 2023
@Soare-Robert-Daniel Soare-Robert-Daniel marked this pull request as ready for review August 29, 2023 14:40
@pirate-bot
Copy link
Contributor

pirate-bot commented Aug 29, 2023

Bundle Size Diff

Package Old Size New Size Diff
Animations 270.81 KB 270.81 KB 0 B (0.00%)
Blocks 1.42 MB 1.42 MB 113 B (0.01%)
CSS 85.28 KB 85.28 KB 0 B (0.00%)
Dashboard 122.49 KB 122.49 KB 0 B (0.00%)
Export Import 83.17 KB 83.17 KB 0 B (0.00%)
Pro 303.34 KB 303.34 KB 0 B (0.00%)

@pirate-bot
Copy link
Contributor

pirate-bot commented Aug 29, 2023

Plugin build for e77fe2d is ready 🛎️!

@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label Aug 29, 2023
@pirate-bot
Copy link
Contributor

pirate-bot commented Aug 29, 2023

E2E Summary

Typing

Test Average Time (ms) Standard Deviation (ms) Median Time (ms) Quantile for soft limit (%) Quantile for hard limit (%)
Typing 54.14 5.47 53.55 78.95 (60ms) 100 (80ms)
Values above 60ms "0 - 66.42, 9 - 61.04, 12 - 61.33, 16 - 61.74"

@HardeepAsrani
Copy link
Member

All good here or any changes required @Soare-Robert-Daniel?

@Soare-Robert-Daniel
Copy link
Contributor Author

@HardeepAsrani I am now investigating how to allow saving on the Widgets page.

Copy link
Member

@HardeepAsrani HardeepAsrani left a comment

Choose a reason for hiding this comment

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

You can fix the merge conflicts and put it up for QA, thank you @Soare-Robert-Daniel

@rodica-andronache
Copy link

rodica-andronache commented Sep 5, 2023

@Soare-Robert-Daniel I can't make it work, not sure if I'm missing anything. The values I save, disappear after a page refresh. I've tried with the free version of Otter from this PR https://vertis.d.pr/v/y6Bgy7

@Soare-Robert-Daniel
Copy link
Contributor Author

@HardeepAsrani, the FSE saving is now given by select( 'core/editor' )?.isSavingNonPostEntityChanges(). We should also check the saving for Custom CSS since it uses the same mechanism as Form. We might have a regression.

@HardeepAsrani
Copy link
Member

@Soare-Robert-Daniel Were you able to fix the issue Rodica has with this?

@Soare-Robert-Daniel
Copy link
Contributor Author

@Soare-Robert-Daniel Were you able to fix the issue Rodica has with this?

Yes.

@rodica-andronache
Copy link

@Soare-Robert-Daniel now everything's working well 👍

@HardeepAsrani HardeepAsrani merged commit e1fa507 into development Sep 12, 2023
12 checks passed
@HardeepAsrani HardeepAsrani deleted the fix/form-saving-fse branch September 12, 2023 11:02
@pirate-bot
Copy link
Contributor

🎉 This PR is included in version 2.4.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@pirate-bot pirate-bot added the released Indicate that an issue has been resolved and released in a particular version of the product. label Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-checklist-complete The Pull Request checklist is complete. (automatic label) pr-checklist-skip Allow this Pull Request to skip checklist. released Indicate that an issue has been resolved and released in a particular version of the product.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Otter Contact Form not Saving Changes in Neve FSE Templates/Template Parts
4 participants