Skip to content

Commit 3f80590

Browse files
committed
fix: improve keyword interpolation reliability
1 parent 5eda123 commit 3f80590

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/components/codeBlock/index.tsx

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

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

66
import {usePlausibleEvent} from 'sentry-docs/hooks/usePlausibleEvent';
@@ -61,9 +61,14 @@ export function CodeBlock({filename, language, children}: CodeBlockProps) {
6161
const [isMounted, setIsMounted] = useState(false);
6262
const {emit} = usePlausibleEvent();
6363

64+
// Use useLayoutEffect to set isMounted synchronously before browser paints
65+
// This ensures keyword interpolation happens before the user sees anything
66+
useLayoutEffect(() => {
67+
setIsMounted(true);
68+
}, []);
69+
6470
useEffect(() => {
6571
setShowCopyButton(true);
66-
setIsMounted(true);
6772
// prevent .no-copy elements from being copied during selection Right click copy or / Cmd+C
6873
const noCopyElements = codeRef.current?.querySelectorAll<HTMLSpanElement>('.no-copy');
6974
const handleSelectionChange = () => {

src/components/codeKeywords/keyword.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import {MotionProps} from 'framer-motion';
55
import {KeywordSpan} from './styles';
66

77
export function Keyword({
8-
initial = {opacity: 0, y: -10, position: 'absolute'},
8+
initial = false, // Disable initial animation on mount to prevent flash
99
animate = {
1010
position: 'relative',
1111
opacity: 1,
1212
y: 0,
13-
transition: {delay: 0.1},
1413
},
1514
exit = {opacity: 0, y: 20},
1615
transition = {

0 commit comments

Comments
 (0)