fix: remeasure virtualized rows after scroll restore#93
fix: remeasure virtualized rows after scroll restore#93AlejandroAkbal wants to merge 1 commit intomainfrom
Conversation
WalkthroughAdds client-side scroll restoration and virtualization remeasurement logic to two posts listing pages. Introduces lifecycle hooks and event listeners to detect page visibility changes, then performs staged row measurements (immediate, next animation frame, 250ms timeout) to stabilize virtual scrolling layout after navigation or data updates. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
📝 Coding Plan
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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pages/posts/[domain].vue (1)
575-699: 🛠️ Refactor suggestion | 🟠 MajorExtract scroll-restore remeasurement into a shared composable.
Line 575 through Line 699 introduces a full lifecycle/timer/watch flow that is duplicated in the premium page. This should be centralized to prevent behavior drift and simplify future fixes.
Proposed refactor sketch
- let scrollRestoreRemeasureTimeout: ReturnType<typeof setTimeout> | null = null - function clearScrollRestoreRemeasureTimeout() { ... } - function remeasureAfterScrollRestore() { ... } - function onPageShow() { ... } - onMounted(() => { ... }) - onBeforeUnmount(() => { ... }) - watch(() => allRows.value.length, () => { remeasureAfterScrollRestore() }) + useVirtualizerScrollRestoreRemeasure({ + rowVirtualizer, + parentRef, + parentOffsetRef, + rowCount: computed(() => allRows.value.length) + })// composables/useVirtualizerScrollRestoreRemeasure.ts export function useVirtualizerScrollRestoreRemeasure({ rowVirtualizer, parentRef, parentOffsetRef, rowCount }) { // move timeout cleanup, pageshow handler, mount/unmount, and rowCount watch here }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pages/posts/`[domain].vue around lines 575 - 699, Extract the scroll-restore remeasurement lifecycle and timer logic into a composable named useVirtualizerScrollRestoreRemeasure and replace the in-file implementation: move the scrollRestoreRemeasureTimeout state, clearScrollRestoreRemeasureTimeout(), remeasureAfterScrollRestore(), onPageShow(), the pageshow listener setup/teardown in onMounted/onBeforeUnmount, and the watch that reacts to allRows.length into the composable; accept and use the passed-in refs rowVirtualizer, parentRef, parentOffsetRef and a reactive rowCount (or allRows) parameter, expose a measureElement helper (wrapping rowVirtualizer.value.measureElement) and an init or returned remeasure function if needed, and update the component to call the composable and set parentOffsetRef from parentRef as before so behavior remains identical.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@pages/posts/`[domain].vue:
- Around line 575-699: Extract the scroll-restore remeasurement lifecycle and
timer logic into a composable named useVirtualizerScrollRestoreRemeasure and
replace the in-file implementation: move the scrollRestoreRemeasureTimeout
state, clearScrollRestoreRemeasureTimeout(), remeasureAfterScrollRestore(),
onPageShow(), the pageshow listener setup/teardown in onMounted/onBeforeUnmount,
and the watch that reacts to allRows.length into the composable; accept and use
the passed-in refs rowVirtualizer, parentRef, parentOffsetRef and a reactive
rowCount (or allRows) parameter, expose a measureElement helper (wrapping
rowVirtualizer.value.measureElement) and an init or returned remeasure function
if needed, and update the component to call the composable and set
parentOffsetRef from parentRef as before so behavior remains identical.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 34354a26-3eaf-43e1-ab8e-707746c236db
📒 Files selected for processing (2)
pages/posts/[domain].vuepages/premium/saved-posts/[domain].vue
Summary
Validation
npx prettier --check \"pages/posts/[domain].vue\" \"pages/premium/saved-posts/[domain].vue\"npm run build(fails due to a pre-existing missing file import:/Users/lume/Projects/Rule-34-App-worktree-47344/assets/lib/rule-34-shared-resources/src/util/BooruUtilsimported bypages/premium/additional-boorus.vue)Feedback
Summary by CodeRabbit
Release Notes