Skip to content

Commit b845b3d

Browse files
committed
revert: use useEffect for keyword interpolation timing, avoid premature render optimization
1 parent 19813bf commit b845b3d

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

src/components/codeBlock/index.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
'use client';
22

3-
import {RefObject, useContext, useEffect, useLayoutEffect, useRef, useState} from 'react';
3+
import {RefObject, useEffect, useRef, useState} from 'react';
44
import {Clipboard} from 'react-feather';
55

66
import {usePlausibleEvent} from 'sentry-docs/hooks/usePlausibleEvent';
77

88
import styles from './code-blocks.module.scss';
99

10-
import {CodeContext} from '../codeContext';
1110
import {makeHighlightBlocks} from '../codeHighlights';
1211
import {makeKeywordsClickable} from '../codeKeywords';
1312

@@ -54,7 +53,6 @@ function getCopiableText(element: HTMLDivElement) {
5453
export 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

Comments
 (0)