Skip to content

Commit bf7e805

Browse files
authored
fix: re-sync onboarding options visibility after keyword interpolation (#15514)
When isMounted triggers keyword interpolation, makeKeywordsClickable clones React elements causing DOM recreation that loses .hidden classes. Added useLayoutEffect to re-apply visibility state synchronously before paint. Fixes checkbox display bug introduced by hydration fix in #15473. Note: this isn't an ideal long term solution to reapply changes, but does the trick until we can invest in a refactor <!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR *Tell us what you're changing and why. If your PR **resolves an issue**, please link it so it closes automatically.* ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent b121d92 commit bf7e805

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/components/codeBlock/index.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
'use client';
22

3-
import {RefObject, useEffect, useRef, useState} from 'react';
3+
import {RefObject, useContext, useEffect, useLayoutEffect, 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';
1011
import {makeHighlightBlocks} from '../codeHighlights';
1112
import {makeKeywordsClickable} from '../codeKeywords';
13+
import {updateElementsVisibilityForOptions} from '../onboarding';
1214

1315
export interface CodeBlockProps {
1416
children: React.ReactNode;
@@ -53,6 +55,7 @@ function getCopiableText(element: HTMLDivElement) {
5355
export function CodeBlock({filename, language, children}: CodeBlockProps) {
5456
const [showCopied, setShowCopied] = useState(false);
5557
const codeRef = useRef<HTMLDivElement>(null);
58+
const codeContext = useContext(CodeContext);
5659

5760
// Show the copy button after js has loaded
5861
// otherwise the copy button will not work
@@ -83,6 +86,15 @@ export function CodeBlock({filename, language, children}: CodeBlockProps) {
8386
};
8487
}, []);
8588

89+
// Re-sync onboarding visibility after keyword interpolation recreates DOM nodes.
90+
// makeKeywordsClickable clones elements, losing .hidden classes. useLayoutEffect
91+
// corrects this synchronously before paint to prevent visible flicker.
92+
useLayoutEffect(() => {
93+
if (isMounted && codeContext?.onboardingOptions) {
94+
updateElementsVisibilityForOptions(codeContext.onboardingOptions, false);
95+
}
96+
}, [isMounted, codeContext?.onboardingOptions]);
97+
8698
useCleanSnippetInClipboard(codeRef, {language});
8799

88100
// Mermaid blocks should not be processed by CodeBlock - they need special client-side rendering

src/components/onboarding/index.tsx

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

3-
import {ReactNode, useContext, useEffect, useReducer, useState} from 'react';
3+
// eslint-disable-next-line no-restricted-imports -- Required for JSX in test environment
4+
import React, {ReactNode, useContext, useEffect, useReducer, useState} from 'react';
45
import {QuestionMarkCircledIcon} from '@radix-ui/react-icons';
56
import * as Tooltip from '@radix-ui/react-tooltip';
67
import {Button, Checkbox, Theme} from '@radix-ui/themes';

0 commit comments

Comments
 (0)