Skip to content

RichText: fix __unstableMarkLastChangeAsPersistent call on mount - #73378

Closed
ellatrix wants to merge 3 commits into
trunkfrom
fix/rich-text-double-dispatch
Closed

ellatrix wants to merge 3 commits into
trunkfrom
fix/rich-text-double-dispatch

Conversation

@ellatrix

@ellatrix ellatrix commented Nov 18, 2025 •

Copy link
Copy Markdown
Member

What?

Closes #63167.

Fixes an issue where __unstableMarkLastChangeAsPersistent is called when the effect is run twice on mount and none of the dependencies have changed in the second run. Apparently this is normal in React StrictMode: https://react.dev/reference/react/StrictMode#fixing-bugs-found-by-re-running-effects-in-development

Why?

It shows up in the performance graphs when running React in dev mode. Yes, it's only dev mode and not production, but it increases the bloat and makes it harder to see actual problems.

How?

Check if the the change is already persistent.

Testing Instructions

See instructions from #63167.

Testing Instructions for Keyboard

Screenshots or screencast

Before After

@ellatrix ellatrix added the [Type] Performance Related to performance efforts label Nov 18, 2025
@github-actions

github-actions Bot commented Nov 18, 2025 •

Copy link
Copy Markdown

Size Change: +20 B (0%)

Total Size: 7.51 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 383 kB +20 B (+0.01%)

compressed-size-action

@Mamaduka Mamaduka added the [Package] Block editor /packages/block-editor label Feb 17, 2026
@Mamaduka
Mamaduka force-pushed the fix/rich-text-double-dispatch branch from d1002ca to ff9e27c Compare February 17, 2026 09:47
@Mamaduka

Copy link
Copy Markdown
Member

@ellatrix, hope you don't mind my rebasing. I was debugging #63167, which led me to __unstableMarkLastChangeAsPersistent extra call in StrickMode. This patch fixes the issue.

I think we can merge once all CI checks pass.

@Mamaduka
Mamaduka marked this pull request as ready for review February 17, 2026 09:54
@github-actions

github-actions Bot commented Feb 17, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: stokesman <presstoke@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@stokesman stokesman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In my testing the fixes the part of the issue I was able to reproduce – the file block. I think the comment I added there must be a separate issue.

Comment on lines +40 to +43
if (
registry.select( blockEditorStore ).isLastBlockChangePersistent()
) {
__unstableMarkLastChangeAsPersistent();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should the conditional be flipped? This reads funny to me but maybe it's an API naming thing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe so, though it still causes some undo e2e test to fail, we might need to find a different approach.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

some undo e2e test to fail

I get the same result on that test locally yet it passes after negating the conditional. I didn't see new failures on other tests either but I didn't run all of them – just those under test/e2e/specs/editor/various/.

Should we try it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sorry, probably made a typo. It's been a while since I made this PR. I'm a bit busy with other stuff, will look at some point if you don't beat me to it

@Mamaduka

Copy link
Copy Markdown
Member

Thanks for testing, @stokesman!

@github-actions

Copy link
Copy Markdown

Flaky tests detected in 39f0ec3.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22159550780
📝 Reported issues:

@Mamaduka

Copy link
Copy Markdown
Member

Unfortunately, I can still reproduce the issue (#63167).

@stokesman, what are your repro steps? Mine are a bit unreliable, maybe we could use yours to add e2e tests.

@stokesman

Copy link
Copy Markdown
Contributor

I’ve never managed to reproduce the first part of the issue. I can reproduce the part of the issue that involves the file block now too.

@Mamaduka

Copy link
Copy Markdown
Member

Created a PR for an alt solution - #83463.

@Mamaduka

Copy link
Copy Markdown
Member

Closing in favor of #83463.

@Mamaduka Mamaduka closed this Sep 25, 2026
@Mamaduka
Mamaduka deleted the fix/rich-text-double-dispatch branch September 25, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Type] Performance Related to performance efforts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Site Editor: Unexpected "undo" behavior in StrictMode

3 participants