Skip to content

Implement the scroll state handling and restore #9209

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 2 commits into
base: develop
Choose a base branch
from

Conversation

rostislavnagimov
Copy link
Contributor

@rostislavnagimov rostislavnagimov commented Jun 10, 2025

This change saves the scroll state for scrollable elements into the Tab and restores it to the same position when tab switches.

Copy link

Connected to Huly®: UBERF-11461


console.log('[RESTORE] Waiting for two ticks for components to render...');
await tick();
await tick();
Copy link
Member

Choose a reason for hiding this comment

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

looks like hack to me. why not one and not three? can we use more reliable way here, for example events?

Copy link
Member

Choose a reason for hiding this comment

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

oh, I used same hack in old chat, it is because of <Component..>. and the more they are nested, the longer we have to wait ticks.

need to find a better solution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was making that based on the existing chat components says the "one tick is not enough to load chat messages"

Till this moment all other ways was not really working for me (tested something like 5-7 other solutions)

@aonnikov aonnikov requested a review from Copilot June 12, 2025 08:04
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements scroll state handling by saving and restoring the scroll positions for scrollable elements when switching tabs. Key changes include:

  • Introduction of a TabUiState interface to hold scroll position data.
  • Addition of an updateTabUiState function to merge updated scroll state.
  • Implementation of saveScrollState and restoreScrollState functions in the Workbench component.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
plugins/workbench/src/types.ts Added TabUiState interface and updated WorkbenchTab to include uiState.
plugins/workbench-resources/src/workbench.ts Added updateTabUiState to update tab UI state with new scroll positions.
plugins/workbench-resources/src/components/Workbench.svelte Implemented functions to save and restore scroll positions on tab switch.
Comments suppressed due to low confidence (2)

plugins/workbench-resources/src/workbench.ts:67

  • Ensure that the 'tabId' parameter's type matches t._id. If 'tabId' is a Ref, comparing it directly to an identifier might lead to unexpected behavior; consider using 'tabId._id' or updating the parameter type to a string.
const tab = tabs.find(t => t._id === tabId);

plugins/workbench-resources/src/components/Workbench.svelte:297

  • Verify that the value of 'tabId' (retrieved from $tabIdStore) is of the same type as t._id. If it is intended to be a string, ensure that there is no unintended wrapping or type mismatch that might cause the comparison to fail.
const tab = get(tabsStore).find((t) => t._id === tabId);

@aonnikov
Copy link
Member

@rostislavnagimov please fix formatting issues. You can run rush format locally to ensure proper formatting.

Signed-off-by: Rostislav Nagimov <[email protected]>
@rostislavnagimov
Copy link
Contributor Author

@rostislavnagimov please fix formatting issues. You can run rush format locally to ensure proper formatting.

Formating fixed

36585ad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants