fix: code copy button now copies full code block#550
Open
olga-venger wants to merge 1 commit intopmndrs:mainfrom
Open
fix: code copy button now copies full code block#550olga-venger wants to merge 1 commit intopmndrs:mainfrom
olga-venger wants to merge 1 commit intopmndrs:mainfrom
Conversation
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.
Closes #546
Problem
The copy button in code blocks only copies partial content.
extractTextFromChildrenrecursively walks the React element tree usingisValidElement, butnext-mdx-remote/rscrenders code blocks as React Server Components, where lines are streamed to the client as lazy chunks.isValidElementreturnsfalsefor these, so the function silently drops everything from that point in the tree.Fix
Replace
extractTextFromChildrenwith ref.current.textContenton the<pre>element. By the time the copy button is clicked, the browser has already rendered the full RSC output into real DOM text nodes andtextContentreads from there directly, regardless of how React internally represented the element tree.This also removes the dependency on
isValidElement, which is a legacy React API not designed for RSC.