fix: prevent expandable image hydration mismatch - #725
Conversation
📝 WalkthroughWalkthroughChangesExpandable image modal
Estimated code review effort: 3 (Moderate) | ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@qiancai is attempting to deploy a commit to the test-vi Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/components/MDXComponents/ExpandableImage.tsx (1)
3-3: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse the configured absolute import paths.
src/components/MDXComponents/ExpandableImage.tsx#L3-L3: replace./ExpandIconswithcomponents/MDXComponents/ExpandIcons.gatsby/__tests__/expandable-image.test.tsx#L10-L13: replace../../src/components/MDXComponents/ExpandableImagewithcomponents/MDXComponents/ExpandableImage.As per coding guidelines, prefer absolute imports configured by
tsconfig.jsonwithbaseUrl: "./src".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/MDXComponents/ExpandableImage.tsx` at line 3, Update the import in src/components/MDXComponents/ExpandableImage.tsx at lines 3-3 to use the configured absolute components/MDXComponents/ExpandIcons path, and update the import in gatsby/__tests__/expandable-image.test.tsx at lines 10-13 to use components/MDXComponents/ExpandableImage instead of the relative path.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/MDXComponents/ExpandableImage.tsx`:
- Around line 15-35: Update the ExpandableImage trigger and modal flow to
support keyboard activation and focus management: make the trigger at the image
click handler keyboard-operable for Enter and Space, focus the close button when
the dialog opens, trap Tab navigation within the dialog, close on Escape, and
restore focus to the trigger on close. Add an accessible dialog name and tests
covering Enter, Space, Tab, Escape, and focus restoration.
In `@src/styles/docTemplate.css`:
- Around line 259-265: Update the --expandable-image-modal-body-max-height calc
expression to place each subtraction operator on the following line’s start or
otherwise avoid newlines immediately after “-”, satisfying
scss/operator-no-newline-after while preserving the existing height calculation.
---
Nitpick comments:
In `@src/components/MDXComponents/ExpandableImage.tsx`:
- Line 3: Update the import in src/components/MDXComponents/ExpandableImage.tsx
at lines 3-3 to use the configured absolute components/MDXComponents/ExpandIcons
path, and update the import in gatsby/__tests__/expandable-image.test.tsx at
lines 10-13 to use components/MDXComponents/ExpandableImage instead of the
relative path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5db1ef87-8d75-49b3-ab17-5303163b2c6d
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (4)
gatsby/__tests__/expandable-image.test.tsxpackage.jsonsrc/components/MDXComponents/ExpandableImage.tsxsrc/styles/docTemplate.css
Background
MDX wraps a Markdown image in
<p>, whileExpandableImagepreviously rendered a block-level<div>at its root. The resulting<p><div>...</div></p>SSR markup is invalid, so browsers repair the DOM before React 17 hydrates it.That tree mismatch can make later headings and code blocks associate with the wrong nodes, causing the issue as follows:

What changed
Before (the close icon is embedded in the graph):

After (the close icon is displayed as an independent icon):
User impact
Documentation pages containing expandable images no longer corrupt later headings or code blocks during initial hydration. The expanded-image modal retains its styling, keeps the image centered with balanced spacing, and uses a smaller close icon positioned in the top-right reserved space without covering image content.
Validation
pnpm exec jest gatsby/__tests__/expandable-image.test.tsx --runInBand --coverage=falsegit diff --checkdashboard/dashboard-ops-deploy.md; bundle compilation was stopped so the requester can continue the local build.upstream/master.