Skip to content

fix(ui): persist sidebar open state and width to prevent flash on load #12743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: canary
Choose a base branch
from

Conversation

NorkzYT
Copy link
Contributor

@NorkzYT NorkzYT commented Jun 7, 2025

persist-sidebar-open-state.mp4

This PR change updates the sidebar initialization so it reads the open and width values from persistent storage. This prevents the UI from flashing open by default on startup.

Both left and right sidebars restore correctly from the last known state from storage.

Summary by CodeRabbit

  • New Features
    • Sidebar and workbench panels now retain their open/closed status and width based on your previously saved preferences, providing a more personalized and consistent experience across sessions.
  • Tests
    • Added comprehensive tests to ensure sidebar state persistence and behavior are reliable and consistent.

…retrieval to ensure consistency with current state management
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

graphite-app bot commented Jun 7, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@graphite-app graphite-app bot requested review from a team and removed request for a team June 7, 2025 00:50
Copy link

coderabbitai bot commented Jun 7, 2025

Walkthrough

The initialization of sidebar-related LiveData observables in both the app sidebar and workbench modules was modified. Instead of always using hardcoded default values, the observables now initialize from the persisted state if available, falling back to the previous defaults only if no stored value exists. Additionally, a new test suite was added for the AppSidebar entity to verify its default values, state mutations, and persistence behavior.

Changes

File(s) Change Summary
.../app-sidebar/entities/app-sidebar.ts Changed initialization of open$ and width$ to use stored state if available, otherwise fallback to defaults.
.../workbench/entities/workbench.ts Updated sidebarOpen$, sidebarWidth$, and workspaceSelectorOpen$ to initialize from stored state if present.
.../app-sidebar/entities/__tests__/app-sidebar.spec.ts Added new test suite for AppSidebar verifying default states, setters, and persistence using Vitest.

Poem

A sidebar peeks from memory’s den,
Its width and open state recall when—
Not just defaults, but history’s say,
Guides how you start your work today.
With state restored, the panels gleam,
CodeRabbit hops in a seamless stream!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
packages/frontend/core/src/modules/workbench/entities/workbench.ts (3)

61-62: Handle undefined emissions in sidebarOpen$ watcher
The fallback ?? false applies only to the initial value. If globalState.watch ever emits undefined, it will pass through. Wrap the watcher in .pipe(map(value => value ?? false)) to ensure every emission falls back to false.


67-69: Guard against undefined watcher values for width
Similar to sidebarOpen$, consider adding .pipe(map(value => value ?? 320)) on the watcher stream to apply the fallback on every update.


75-77: Ensure fallback for workspace selector watcher
Add .pipe(map(value => value ?? false)) to the watcher so that any undefined emissions are converted back to false, maintaining consistency after the initial load.

packages/frontend/core/src/modules/app-sidebar/entities/app-sidebar.ts (2)

50-53: Align getCachedAppSidebarOpenState with open$ default
getCachedAppSidebarOpenState returns the raw stored value, which may be undefined. Consider using the same fallback (?? true) here to avoid exposing undefined.


58-61: Remove redundant return statement
The explicit return; in setOpen is unnecessary. You can simplify the method by omitting it.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7aafbf1 and d4edea3.

📒 Files selected for processing (2)
  • packages/frontend/core/src/modules/app-sidebar/entities/app-sidebar.ts (1 hunks)
  • packages/frontend/core/src/modules/workbench/entities/workbench.ts (1 hunks)
🧰 Additional context used
🪛 ESLint
packages/frontend/core/src/modules/app-sidebar/entities/app-sidebar.ts

[error] 27-27: Finnish notation should not be used here.

(rxjs/finnish)

packages/frontend/core/src/modules/workbench/entities/workbench.ts

[error] 66-66: Finnish notation should not be used here.

(rxjs/finnish)


[error] 74-74: Finnish notation should not be used here.

(rxjs/finnish)

🔇 Additional comments (5)
packages/frontend/core/src/modules/workbench/entities/workbench.ts (3)

59-62: Restore persisted sidebar open state
Initializing sidebarOpen$ with this.globalState.get(...) ?? false ensures the sidebar’s last state is used on load, preventing the flash. This aligns perfectly with the PR objective to persist UI state.

🧰 Tools
🪛 ESLint

[error] 59-59: Finnish notation should not be used here.

(rxjs/finnish)


66-69: Restore persisted sidebar width
The sidebarWidth$ LiveData now correctly reads from globalState with a 320 fallback, matching the stored user preference on startup.

🧰 Tools
🪛 ESLint

[error] 66-66: Finnish notation should not be used here.

(rxjs/finnish)


74-77: Restore persisted workspace selector state
Initializing workspaceSelectorOpen$ with the persisted value and falling back to false meets the requirement to persist UI state across loads.

🧰 Tools
🪛 ESLint

[error] 74-74: Finnish notation should not be used here.

(rxjs/finnish)

packages/frontend/core/src/modules/app-sidebar/entities/app-sidebar.ts (2)

20-25: Persist sidebar open state with fallback mapping
Using .watch<boolean>(...).pipe(map(value => value ?? true)) alongside an initial fallback correctly reads stored state and handles undefined on every emission.

🧰 Tools
🪛 ESLint

[error] 20-20: Finnish notation should not be used here.

(rxjs/finnish)


27-32: Persist sidebar width with fallback mapping
The width$ LiveData now uses .watch<number>(...).pipe(map(value => value ?? 248)) and an initial fallback, ensuring both initial and subsequent undefined emissions map to 248.

🧰 Tools
🪛 ESLint

[error] 27-27: Finnish notation should not be used here.

(rxjs/finnish)

@github-actions github-actions bot added the test Related to test cases label Jun 8, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4edea3 and 2f81ba7.

📒 Files selected for processing (1)
  • packages/frontend/core/src/modules/app-sidebar/entities/__tests__/app-sidebar.spec.ts (1 hunks)
🔇 Additional comments (3)
packages/frontend/core/src/modules/app-sidebar/entities/__tests__/app-sidebar.spec.ts (3)

1-18: LGTM! Solid test setup for sidebar persistence testing.

The test setup correctly initializes the Framework with MemoryMemento to mock storage behavior, which aligns perfectly with testing the persistence fixes mentioned in the PR objectives.


20-25: LGTM! Default values test validates fallback behavior.

This test correctly verifies that when no stored state exists (fresh MemoryMemento), the sidebar falls back to the expected default values (open: true, width: 248). This aligns with the PR's goal of reading from persistent storage with fallback defaults.


50-53: LGTM! Cached state test validates correct retrieval.

The test correctly verifies that getCachedAppSidebarOpenState() returns the current cached state value, ensuring the persistence mechanism works as expected.

@forehalo
Copy link
Member

forehalo commented Jun 9, 2025

cool

Copy link

codecov bot commented Jun 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.63%. Comparing base (115496a) to head (2f81ba7).
Report is 2 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #12743      +/-   ##
==========================================
- Coverage   55.94%   55.63%   -0.32%     
==========================================
  Files        2653     2655       +2     
  Lines      125303   125319      +16     
  Branches    19898    19834      -64     
==========================================
- Hits        70105    69722     -383     
+ Misses      53450    53290     -160     
- Partials     1748     2307     +559     
Flag Coverage Δ
server-test 79.03% <ø> (-0.73%) ⬇️
unittest 31.62% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@NorkzYT
Copy link
Contributor Author

NorkzYT commented Jun 14, 2025

@L-Sun

Please run CI test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app:core test Related to test cases
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants