app/ui: skip sidebar transition animation on initial page load#14515
Open
umutkeltek wants to merge 1 commit intoollama:mainfrom
Open
app/ui: skip sidebar transition animation on initial page load#14515umutkeltek wants to merge 1 commit intoollama:mainfrom
umutkeltek wants to merge 1 commit intoollama:mainfrom
Conversation
When the app loads with sidebarOpen persisted as true, CSS transitions cause the sidebar to visibly animate from closed to open. This happens because transition classes are applied unconditionally while settings are still loading asynchronously via useQuery. Defer transition classes until after the first frame via a hasMounted state flag with requestAnimationFrame, so the sidebar renders in its correct state instantly on load. Subsequent sidebar toggles still animate smoothly. Fixes ollama#12954
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the app loads with
sidebarOpenpersisted astruein settings, CSS transition classes cause the sidebar to visibly animate from closed → open. This happens because:useSettings()usesuseQuery, sosidebarOpeninitially defaults tofalsewhile the async settings fetch is in-flightsidebarOpen: true, the sidebar width changes fromw-0→w-64transition-[width],transition-[left],transition-opacity,transition-all) are applied unconditionally, so the browser animates this state changeThe result is a slide-open animation every time the app loads — the sidebar should appear instantly in its saved state.
Solution
Defer CSS transition classes until after the first paint using a
hasMountedstate flag:All five transition class locations are conditionally applied:
Using
requestAnimationFrame(instead of bareuseEffect) ensures the transition suppression survives the full browser paint cycle, preventing any flash of animation even on slower renders.Changes
app/ui/app/src/components/layout/layout.tsx— 1 file, +15/-5 lineshasMountedstate withuseEffect+requestAnimationFramehasMounted === trueTesting
tsc -b— zero errorsBehavior
Fixes #12954