wp.data.select('core/editor').isSavingPost() not work on Site editor (when I was saving template part)
Description
wp.data.select('core/editor').isSavingPost() not work on Site editor (when I was saving template part), it works well on block editor (post edit page).
One more issue: wp.data.select("core/editor").getCurrentPostAttribute("meta") also works on Block editor but return undefined on Site editor.
Step-by-step reproduction instructions
Just open your Site editor and Block editor, then test the above code on Chrome Console respectively .
Screenshots, screen recording, code snippet
No response
Environment info
No response
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
Did I misunderstand something, or are there some equivalent ways to get the same data in Site editor as in Block editor? If I can use the same function on both Site and Block editor, I can extract the code and reduce the code.
Sorry, I am new to Gutenberg/Block editor development. Currently, I have too much information to digest.
@youknowriad, should these selectors work in Site Editor after the "great unification"?
Yeah, I believe most of them will work, you might have some unexpected results at time (checking whether the post is being saved while you have both the template and post visible...) but yeah, they should work now.
I open a template part and tried in Chrome Console:
wp.data.select("core/editor").getEditedPostAttribute("meta") undefined
wp.data.select("core/editor").getEditedPostAttribute("meta") : works for post/page type, but doesn't work wp_template/wp_template_part type;
@Louisna123, which version of the Gutenberg plugin are you using?
@Louisna123, which version of the Gutenberg plugin are you using?
17.5.3
Do templates have support for "custom fields" (meta), probably not?
@Mamaduka I can confirm
const isSavingPost = wp.data.select("core/editor").isSavingPost();
is not working on the site editor anymore. Probably since 6.2 or 6.3 Currently i am testing on 6.5 (beta) and it's still not working
So at the moment there is no way to check a save from the site-editor
Hi, This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps. Thanks for helping out.
I can verify this isn't working in the site editor as well. I don't believe there is currently a way to hook into the user pressing the "Save" button in the site editor but there really should be. "Ctrl + s" while editing a page in the site editor works and triggers isPostSaving. But even though clicking the "Save" button notifies the user that there are pages that have been modified, continuing with the second "Save" button does not trigger isPostSaving.
Looking at this issue, I can see that the problem arises from the difference between the Block Editor (core/editor store) and the Site Editor (core/edit-site store). The Site Editor lacks the compatibility selectors that developers expect to work consistently across both editing contexts. This can be resolved by adding the missing isSavingPost() and getCurrentPostAttribute() selectors to the Site Editor store.
@Adi-ty We ended up with
export const getSaveState = () => {
const { __experimentalGetDirtyEntityRecords, isSavingEntityRecord } =
select('core');
const dirtyEntityRecords = __experimentalGetDirtyEntityRecords();
const isSaving = dirtyEntityRecords.some((record: any) =>
isSavingEntityRecord(record.kind, record.name, record.key)
);
return isSaving ? true : false;
};
within wp.data.subscribe(() => {
This is inspired by the save button of the right panel https://github.com/WordPress/gutenberg/blob/trunk/packages/edit-site/src/components/save-panel/index.js/
After further investigation and reviewer feedback, this appears to be a misunderstanding of how Gutenberg's data stores work.
The Solution Already Exists:
The core/editor store is available in both Block Editor and Site Editor contexts. Developers should use:
// Works in BOTH contexts
wp.data.select('core/editor').isSavingPost()
wp.data.select('core/editor').getCurrentPostAttribute('title')
Reproduction Report
Description
❌ This report can't validate that the issue can be reproduced.
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.29
- Server: Apache/2.4.62 (Debian)
- Database: mysqli (Server: 11.8.2-MariaDB-ubu2404 / Client: mysqlnd 8.2.29)
- Browser: Chrome 138.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.3
- MU Plugins: None activated
- Plugins:
- Gutenberg 21.3.0-rc.2
- Test Reports 1.2.0
Testing Instructions
- Go to the browser console
- Go to a New Post, Add a Title for example: "Example Title" and save
- Execute the
wp.data.select('core/editor').isSavingPost() - ❌ It returns
falseas expected - Execute the
wp.data.select('core/editor').getCurrentPostAttribute('title') - ❌ It returns the title we used "Example Title" as expected
Actual Results
- ❌ Error condition occurs (reproduced).
Additional Notes
- As @Adi-ty has already pointed out, there doesn't seem to be a problem here. What I don't really have clear is what are the expectations here. What are you expecting as a result from
isSavingPost. Maybe it was returningundefinedwhen the report was created, but given there is barely no information and no expected results, this report has not aged very well, and it's unclear to see where is the issue with the information we currently have - For this reason, I think that it's time to close this as
worksforme. If anyone can provide additional information about an issue with thecore/editorstore, and we can continue testing and reopen this ticket accordingly.
Supplemental Artifacts
Results in Block Editor
Results in Site Editor