Skip to content

Conversation

@amustaque97
Copy link
Member

Fixes: #33839

Description

This is done in order to avoid function call getting cancelled on multiple refresh

How has this been tested?

Screenshots

Types of changes

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 (please manually search all *.native.js files for terms that need renaming or removal).

@Mamaduka Mamaduka added [Package] Server Side Render /packages/server-side-render [Type] Bug An existing feature does not function as intended labels Dec 28, 2021
@amustaque97 amustaque97 marked this pull request as ready for review January 28, 2022 16:57
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't put refs inside dependency callbacks. It doesn't work the way you might think it works:

https://epicreact.dev/why-you-shouldnt-put-refs-in-a-dependency-array/

Also, becuase prevProps is an object, it will fail the identity equality check on every render due to props being a new object on every render. And prevProps is not even used inside the callback, so it shouldn't be in the dependency array anyway.

attributes, httpMethod, and urlQueryArgs are the actual dependencies of the callback. httpMethod can easily be added to the dependency array, but because attributes and urlQueryArgs are objects, you can't just put them in the dependency array directly, so you'd have to store their versions from the prior render using usePrevious, perform deep equality checks using Lodash's equals, and put the boolean result of those comparisons in the dependency array.

Copy link
Member

Choose a reason for hiding this comment

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

Just a side note that since we no longer use Lodash in the entire repository (see #52571), we're using a couple of methods for comparison:

  • shallow comparison: see the @wordpress/is-shallow-equal package.
  • deep comparison: the fast-deep-equal package.

@Mamaduka
Copy link
Member

Hi, @amustaque97

This PR came up during the weekly editor bug scrub, and I wanted to check if you plan to continue working on it.

@amustaque97
Copy link
Member Author

Hi @Mamaduka, by this weekend. I should be able to work on the review comments 🙂

@Mamaduka
Copy link
Member

Thanks for the reply, @amustaque97!

Zero pressure, I just wanted to check on the status 👍

This is done in order to avoid function call getting cancelled on multiple refresh
fix `useCallback` dependency array
@amustaque97 amustaque97 force-pushed the fix/useDebounce-does-not-call-function branch from 8480425 to 92d1c06 Compare August 7, 2022 14:56
@amustaque97 amustaque97 requested a review from Mamaduka August 15, 2022 13:03
@Mamaduka
Copy link
Member

Thanks for working on this, @amustaque97! I believe this issue was resolved as part of different bug report - #69237.

@Mamaduka Mamaduka closed this Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Server Side Render /packages/server-side-render [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useDebounce does not call function if the component refreshes

4 participants