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

withNotices: Memoize the noticeOperations object #29582

Merged
merged 1 commit into from
Mar 5, 2021

Conversation

pablinos
Copy link
Member

@pablinos pablinos commented Mar 5, 2021

Description

The refactor of withNotices in #28676 introduced a bug where the
functions within noticeOperations were changing on every render. That
meant that if they were present in the dependency array of a useEffect,
then the effect would trigger causing an infinite loop.

This was partially fixed with #29491, but there are other instances
where the noticeOperations object itself is being listed as a
dependency, and so the problem persists.

As suggested by @stokesman
#29491 (comment)
this change memoizes the whole object.

How has this been tested?

It's been manually tested in the same way as #29491. With the current release of Jetpack insert a podcast block. Before #29491, the block would be stuck in a loop. With this change it won't be. Similarly, the Instgram Gallery block will get stuck in a loop without this fix, but that has been fixed with Automattic/jetpack#19034

Types of changes

Bug fix - This hopefully makes withNotices behave as before the refactor

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

The refactor of withNotices in WordPress#28676 introduced a bug where the
functions within `noticeOperations` were changing on every render. That
meant that if they were present in the dependency array of a useEffect,
then the effect would trigger causing an infinite loop.

This was partially fixed with WordPress#29491, but there are other instances
where the noticeOperations object itself is being listed as a
dependency, and so the problem persists.

As suggested by @stokesman
WordPress#29491 (comment)
this change memoizes the whole object.
Copy link
Contributor

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This tests well for me. ✅

@ntsekouras ntsekouras merged commit 9dc9615 into WordPress:trunk Mar 5, 2021
@github-actions github-actions bot added this to the Gutenberg 10.2 milestone Mar 5, 2021
ntsekouras pushed a commit that referenced this pull request Mar 5, 2021
The refactor of withNotices in #28676 introduced a bug where the
functions within `noticeOperations` were changing on every render. That
meant that if they were present in the dependency array of a useEffect,
then the effect would trigger causing an infinite loop.

This was partially fixed with #29491, but there are other instances
where the noticeOperations object itself is being listed as a
dependency, and so the problem persists.

As suggested by @stokesman
#29491 (comment)
this change memoizes the whole object.
@youknowriad youknowriad added the [Type] Bug An existing feature does not function as intended label Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants