[docs] Fix copy button not working on first page load#48630
Open
overvi wants to merge 1 commit into
Open
Conversation
Deploy previewhttps://deploy-preview-48630--material-ui.netlify.app/ Bundle size
Check out the code infra dashboard for more information about this PR. |
476650b to
de22831
Compare
be81bf0 to
98e2caa
Compare
0c8dd71 to
9b9987e
Compare
mj12albert
requested changes
Jun 8, 2026
| return; | ||
| const observer = new MutationObserver((mutationsList, _) => { | ||
| for (const mutation of mutationsList) { | ||
| if (mutation.type === 'childList' && mutation.addedNodes.length) { |
Member
There was a problem hiding this comment.
this condition seems too broad and causes the event listeners to be repeatedly (and unnecessarily) added
Author
There was a problem hiding this comment.
I added a guard to prevent duplicates and the mutation observer now targets the elements directly instead of the previous condition. I think it should be good now could you take another look?
c343c92 to
501c8df
Compare
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.
Fixes #48629
The
useEffecthook was executing before the copy buttons had been rendered, causing the event listeners to not be attached correctly. As a result, the copy functionality did not initialize properly on first page load.This timing issue also prevented the correct copy button label from being loaded during the initial visit to the page. The effect now runs after the copy buttons are available ensuring listeners are attached correctly