11'use client' ;
22
3- import { RefObject , useContext , useEffect , useLayoutEffect , useRef , useState } from 'react' ;
3+ import { RefObject , useEffect , useRef , useState } from 'react' ;
44import { Clipboard } from 'react-feather' ;
55
66import { usePlausibleEvent } from 'sentry-docs/hooks/usePlausibleEvent' ;
77
88import styles from './code-blocks.module.scss' ;
99
10- import { CodeContext } from '../codeContext' ;
1110import { makeHighlightBlocks } from '../codeHighlights' ;
1211import { makeKeywordsClickable } from '../codeKeywords' ;
1312
@@ -54,7 +53,6 @@ function getCopiableText(element: HTMLDivElement) {
5453export function CodeBlock ( { filename, language, children} : CodeBlockProps ) {
5554 const [ showCopied , setShowCopied ] = useState ( false ) ;
5655 const codeRef = useRef < HTMLDivElement > ( null ) ;
57- const codeContext = useContext ( CodeContext ) ;
5856
5957 // Show the copy button after js has loaded
6058 // otherwise the copy button will not work
@@ -63,20 +61,9 @@ export function CodeBlock({filename, language, children}: CodeBlockProps) {
6361 const [ isMounted , setIsMounted ] = useState ( false ) ;
6462 const { emit} = usePlausibleEvent ( ) ;
6563
66- // Extract isLoading to avoid dependency array issues
67- const isContextLoading = codeContext ?. isLoading ?? true ;
68-
69- // Use useLayoutEffect to set isMounted synchronously before browser paints
70- // This ensures keyword interpolation happens before the user sees anything
71- // Wait for codeKeywords to be loaded before enabling keyword interpolation
72- useLayoutEffect ( ( ) => {
73- if ( codeContext && ! isContextLoading ) {
74- setIsMounted ( true ) ;
75- }
76- } , [ codeContext , isContextLoading ] ) ;
77-
7864 useEffect ( ( ) => {
7965 setShowCopyButton ( true ) ;
66+ setIsMounted ( true ) ;
8067 // prevent .no-copy elements from being copied during selection Right click copy or / Cmd+C
8168 const noCopyElements = codeRef . current ?. querySelectorAll < HTMLSpanElement > ( '.no-copy' ) ;
8269 const handleSelectionChange = ( ) => {
0 commit comments