Convert EuiMutationObserver from class to function component#9508
Closed
ragini-pandey wants to merge 4 commits intoelastic:mainfrom
Closed
Convert EuiMutationObserver from class to function component#9508ragini-pandey wants to merge 4 commits intoelastic:mainfrom
EuiMutationObserver from class to function component#9508ragini-pandey wants to merge 4 commits intoelastic:mainfrom
Conversation
|
👋 Since this is a community submitted pull request, a Buildkite build has not been started automatically. Would an Elastic organization member please verify the contents of this pull request and kick off a build manually? |
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors EuiMutationObserver from a class component (via EuiObserver) into a standalone function component implemented with React hooks, while aiming to preserve the existing API and behavior.
Changes:
- Replaced the
EuiObserverinheritance model with hook-based ref tracking and observer lifecycle management insideEuiMutationObserver. - Kept
makeMutationObserveranduseMutationObserverintact. - Added an upcoming changelog entry documenting the refactor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
packages/eui/src/components/observer/mutation_observer/mutation_observer.tsx |
Converts EuiMutationObserver to a hook-based function component and inlines observer lifecycle logic. |
packages/eui/changelogs/upcoming/9508.md |
Adds a changelog entry for the component refactor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/eui/src/components/observer/mutation_observer/mutation_observer.tsx
Show resolved
Hide resolved
packages/eui/src/components/observer/mutation_observer/mutation_observer.tsx
Show resolved
Hide resolved
packages/eui/src/components/observer/mutation_observer/mutation_observer.tsx
Show resolved
Hide resolved
9 tasks
Contributor
Author
|
Closing as per #9511 (comment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Converts
EuiMutationObserverfrom a class component (extendingEuiObserver) to a standalone function component, as requested in #9459.Key implementation details:
EuiObserverlifecycle logic (ref tracking viaupdateChildNode, observer connect/disconnect) directly into the function component usinguseRefanduseCallbackonMutationandobserverOptionsare stored in refs so theupdateChildNodecallback identity stays stable across renders — this prevents React from cycling the ref callback (disconnect → reconnect), which would cause missed mutationsuseEffectwith an empty dependency arraymakeMutationObserverhelper anduseMutationObserverhook are unchangedEuiObserverbase class is left intact sinceEuiResizeObserverstill extends itEuiMutationObserver,EuiMutationObserverProps, anduseMutationObserverexports remain identicalWhy are we making this change?
Closes #9459 — Migrating class components to function components for consistency and to leverage React hooks.
Impact to users
No impact. This is a pure internal refactor — the public API, behavior, and rendered output are identical.
QA
General checklist
Checked in both light and dark modes(no visual changes)Checked in both MacOS and Windows high contrast modes(no visual changes)Checked in mobile(no visual changes)Checked in Chrome, Safari, Edge, and Firefox(no visual changes)Checked for accessibility(no visual changes)Added documentation(no API changes)Props have proper autodocs(no API changes)Checked Code Sandbox(no API changes)Updated visual regression tests(no visual changes)Breaking change(not applicable)