fix(Pre): sync root div min-height to pre height to fix Safari codeblock layout rendering#6565
fix(Pre): sync root div min-height to pre height to fix Safari codeblock layout rendering#6565johnson-jnr wants to merge 3 commits into
Conversation
📝 WalkthroughWalkthroughThe Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
commit: |
benjamincanac
left a comment
There was a problem hiding this comment.
Nice catch on the root cause. I'm wondering if this should go in CodeCollapse instead of Pre though? A plain code block never changes height, so we'd be running a ResizeObserver on every pre on the page for something only the collapse toggle can trigger. Feels like it belongs next to the height logic.
Also you probably want { box: 'border-box' } on useElementSize, otherwise it measures the content box and the min-height ends up ~26px short of the actual pre height.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/runtime/components/prose/CodeCollapse.vue (1)
77-77: ⚡ Quick winAdd
data-slot="root"on the root slot element.Line 77 applies the
roottheme slot class (ui.root(...)) but does not annotate the same element withdata-slot="root".Suggested patch
- <div ref="rootRef" :style="{ '--ui-code-height': `${codeHeight}px` }" :class="ui.root({ class: [props.ui?.root, props.class] })"> + <div ref="rootRef" data-slot="root" :style="{ '--ui-code-height': `${codeHeight}px` }" :class="ui.root({ class: [props.ui?.root, props.class] })">As per coding guidelines:
Add data-slot="name" attributes on all template elements in component slots. Based on learnings: adddata-slotwhen the element itself carries the matching theme-slot class binding (ui.root(...)here).🤖 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/runtime/components/prose/CodeCollapse.vue` at line 77, The root element rendering the component's themed root class (the div with ref="rootRef" and :class="ui.root({ class: [props.ui?.root, props.class] })") is missing the required slot annotation; add data-slot="root" on that same div so the element that carries ui.root(...) also has data-slot="root" (keep ref="rootRef" and the existing :style and :class bindings intact).Sources: Coding guidelines, Learnings
🤖 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.
Nitpick comments:
In `@src/runtime/components/prose/CodeCollapse.vue`:
- Line 77: The root element rendering the component's themed root class (the div
with ref="rootRef" and :class="ui.root({ class: [props.ui?.root, props.class]
})") is missing the required slot annotation; add data-slot="root" on that same
div so the element that carries ui.root(...) also has data-slot="root" (keep
ref="rootRef" and the existing :style and :class bindings intact).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c80e0f57-65be-4fc6-807d-f012338c9679
📒 Files selected for processing (2)
src/runtime/components/prose/CodeCollapse.vuesrc/theme/prose/code-collapse.ts
✅ Files skipped from review due to trivial changes (1)
- src/theme/prose/code-collapse.ts
|
Thanks for the review @benjamincanac I have moved the logic to |
🔗 Linked issue
Resolves #6398
Note: Same issue occurs on Safari on Mac.
❓ Type of change
📚 Description
On the docs page, when
Expand codebutton is clicked,preelement height changes from its initial200pxtoauto(with a max height of 80vh).ui/src/theme/prose/code-collapse.ts
Line 11 in aa10c90
This update is necessary for
preto fully contain the code.In Chrome and Firefox, when the nested
preheight changes, its parent container height updates accordingly as expected. However, in Safari there is a rendering issue becausepreheight change fails to propagate to its parent, so the outer parent div keeps the stale initial height of200px.CSS-only fixes i tried didn't work. The fix here gets
pre'sdynamic height usinguseElementSize(which usesResizeObserver) and applies it as themin-heightofpre'sparent div.📝 Checklist