Skip to content

fix(theme-common): properly memoize attributeFilter in useMutationObs…#11718

Closed
garry00107 wants to merge 1 commit intofacebook:mainfrom
garry00107:fix/mutation-observer-attribute-filter
Closed

fix(theme-common): properly memoize attributeFilter in useMutationObs…#11718
garry00107 wants to merge 1 commit intofacebook:mainfrom
garry00107:fix/mutation-observer-attribute-filter

Conversation

@garry00107
Copy link
Contributor

Pre-flight checklist

Motivation

This PR addresses the TODO in useMutationObserver.ts:

The useShallowMemoObject hook only performs shallow comparison—it flattens object entries and compares values directly. This means attributeFilter (an array) is compared by reference, not by value. If a caller passes a new array instance with the same contents on each render, the options will be considered "changed" and the MutationObserver will be recreated unnecessarily.

Solution

  1. Added a new useShallowMemoArray utility to reactUtils.tsx that properly memoizes arrays by their element values
  2. Updated useMutationObserver to extract and memoize attributeFilter separately before combining it back with the rest of the options

Test Plan

yarn test packages/docusaurus-theme-common

@meta-cla meta-cla bot added the CLA Signed Signed Facebook CLA label Feb 6, 2026
@netlify
Copy link

netlify bot commented Feb 6, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 643c821
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6985de3cf3a6d700089090d3
😎 Deploy Preview https://deploy-preview-11718--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@slorber
Copy link
Collaborator

slorber commented Feb 6, 2026

This solution starts to become too complex, we don't even use that code path, and it's not covered by any test.

Please don't pick random code TODO and try to solve them, some of them are not always meant to be solved immediately, but later, once we have a use-case for improving our code. I'd prefer if you focused on actual bugs, and wrote clear tests to show that the problem is solved. Here the test plan doesn't test your code at all.

Also, please disclose any AI usage. If you want to contribute here, please start gaining my trust by doing so manually.

@slorber slorber closed this Feb 6, 2026
@garry00107
Copy link
Contributor Author

Hi @slorber , thank you for the feedback.

I want to acknowledge that the test plan didn't actually test the new code path, which defeats the purpose.

I used Claude to help identify and implement this change.
I'll close this PR. Thank you for taking the time to review.

@garry00107 garry00107 deleted the fix/mutation-observer-attribute-filter branch February 6, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants