Skip to content

Conversation

@ulrikandersen
Copy link
Contributor

@ulrikandersen ulrikandersen commented Dec 19, 2025

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 urlHash field (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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Copilot AI review requested due to automatic review settings December 19, 2025 09:01
Copy link
Contributor

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 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 urlHash field 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.

@ulrikandersen ulrikandersen force-pushed the hotfix/preserve-scroll-on-project-refresh branch 2 times, most recently from 21163f7 to 02ecd71 Compare December 19, 2025 09:37
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).
@ulrikandersen ulrikandersen force-pushed the hotfix/preserve-scroll-on-project-refresh branch from 02ecd71 to dc61995 Compare December 19, 2025 09:44
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.

2 participants