-
Notifications
You must be signed in to change notification settings - Fork 2
fix: preserve scroll position when projects refresh #642
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 fixes a bug where users lost their scroll position in SwaggerUI when switching tabs/windows. The issue occurred because encrypted remote spec URLs with random IVs were causing unnecessary React state updates on every refresh, even when the underlying data hadn't changed.
Key Changes:
- Implemented structural comparison logic to detect actual project changes instead of comparing full JSON
- Added
urlHashfield to track remote URL changes without relying on encrypted URLs - Replaced direct state updates with conditional updates that preserve reference equality when data hasn't changed
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/features/projects/view/ProjectsContextProvider.tsx | Introduced setProjectsIfChanged function that compares projects by structural identity (owner, name, version IDs, spec IDs, and urlHash) to prevent unnecessary state updates |
| src/features/projects/domain/OpenApiSpecification.ts | Added optional urlHash field to the schema for tracking remote URL changes |
| src/features/projects/data/GitHubProjectDataSource.ts | Imported crypto module and generates SHA-256 hash of remote config to populate the urlHash field for remote specifications |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
21163f7 to
02ecd71
Compare
The encrypted URLs for remote specs contain random IVs, causing different ciphertext on each refresh. This triggered unnecessary state updates and re-renders, resetting the documentation viewer's scroll position. Add urlHash field computed from underlying remote config, and compare projects by fingerprint (urlHash for remote specs, URL for others).
02ecd71 to
dc61995
Compare
Description
Preserve scroll position in documentation viewer when projects refresh in the background.
Remote spec URLs are encrypted with random IVs, producing different ciphertext on each refresh even when the underlying config hasn't changed. This was triggering unnecessary React state updates.
Solution: Add a
urlHashfield (SHA-256 of the underlying remote config) and compare projects by fingerprint instead of encrypted URLs.Motivation and Context
Users were losing their scroll position in SwaggerUI when switching tabs/windows, because the visibility change event triggers a project refresh that was incorrectly detected as "changed" data.
Screenshots (if appropriate):
Skaermoptagelse.2025-12-19.kl.10.03.41.mov
Types of changes