gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

wp.data.select('core/editor').isSavingPost() not work on Site editor (when I was saving template part)

Open Louisna123 opened this issue 2 years ago • 12 comments

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

Louisna123 avatar Jan 27 '24 10:01 Louisna123

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.

Louisna123 avatar Jan 27 '24 10:01 Louisna123

Sorry, I am new to Gutenberg/Block editor development. Currently, I have too much information to digest.

Louisna123 avatar Jan 27 '24 10:01 Louisna123

@youknowriad, should these selectors work in Site Editor after the "great unification"?

Mamaduka avatar Jan 31 '24 04:01 Mamaduka

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.

youknowriad avatar Jan 31 '24 08:01 youknowriad

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 avatar Jan 31 '24 18:01 Louisna123

@Louisna123, which version of the Gutenberg plugin are you using?

Mamaduka avatar Feb 01 '24 05:02 Mamaduka

@Louisna123, which version of the Gutenberg plugin are you using?

17.5.3

Louisna123 avatar Feb 01 '24 08:02 Louisna123

Do templates have support for "custom fields" (meta), probably not?

youknowriad avatar Feb 01 '24 08:02 youknowriad

@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

merijnponzo avatar Mar 01 '24 11:03 merijnponzo

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.

github-actions[bot] avatar Apr 01 '24 00:04 github-actions[bot]

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.

briangrider avatar May 22 '24 21:05 briangrider

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 avatar Jun 06 '25 00:06 Adi-ty

@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/

merijnponzo avatar Jun 06 '25 07:06 merijnponzo

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')

Adi-ty avatar Jun 07 '25 18:06 Adi-ty

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

  1. Go to the browser console
  2. Go to a New Post, Add a Title for example: "Example Title" and save
  3. Execute the wp.data.select('core/editor').isSavingPost()
  4. ❌ It returns false as expected
  5. Execute the wp.data.select('core/editor').getCurrentPostAttribute('title')
  6. ❌ It returns the title we used "Example Title" as expected

Actual Results

  1. ❌ 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 returning undefined when 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 the core/editor store, and we can continue testing and reopen this ticket accordingly.

Supplemental Artifacts

Results in Block Editor Image

Results in Site Editor Image

SirLouen avatar Jul 29 '25 16:07 SirLouen