Skip to content

Refactor application state#110

Merged
paolosimone merged 4 commits into
mainfrom
refactor-application-state
Nov 2, 2025
Merged

Refactor application state#110
paolosimone merged 4 commits into
mainfrom
refactor-application-state

Conversation

@paolosimone
Copy link
Copy Markdown
Owner

@paolosimone paolosimone commented Nov 2, 2025

The ApplicationState has been extracted into its own module as preparation for future evolutions.

Defer application loading until settings have been read from async storage, instead of using default values which cause layout shift.

@paolosimone paolosimone requested a review from Copilot November 2, 2025 06:20
Copy link
Copy Markdown
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 refactors the application initialization logic to properly handle asynchronous loading of settings, theme, and localization data. The key changes include:

  • Converting hooks that depend on storage to return nullable values during initial loading
  • Introducing a loading state that waits for all required data before rendering the main application
  • Refactoring storage from a singleton pattern to a factory function
  • Converting runtime detection from a constant to a function
  • Moving ApplicationState logic from App.tsx into a dedicated file
  • Updating numerous dependencies in package.json and yarn.lock

Reviewed Changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
extension/yarn.lock Updated various ESLint packages, type definitions, and other dependencies to newer versions
extension/package.json Bumped versions for eslint, types, react-window, and globals packages
extension/src/viewer/state/index.ts Added export for ApplicationState module
extension/src/viewer/state/Runtime.ts Renamed detectRuntime() to getRuntime() and removed RUNTIME constant, refactored getURL() to call the function
extension/src/viewer/state/ApplicationState.ts New file extracting application state management logic from App.tsx
extension/src/viewer/localization/UseLocalization.ts Changed return type to nullable and memoized translation resolution
extension/src/viewer/hooks/UseTheme.ts Simplified to return nullable theme, removed ThemeColors from return type, refactored internal logic
extension/src/viewer/hooks/UseStorage.ts Changed to use factory function for storage, return nullable value during initialization, switched from useMemo to useCallback
extension/src/viewer/hooks/UseSettings.ts Changed return type to nullable, moved upgrade logic inside null check, switched from useMemo to useCallback
extension/src/viewer/hooks/UseJQ.ts Added null-safe access to settings with fallback to DefaultSettings, inlined JQ_WASM_FILE constant
extension/src/viewer/components/ViewerPlaceholder.tsx Memoized the result of getURL() call to avoid repeated runtime detection
extension/src/viewer/commons/Storage.ts Renamed SessionStorage to LocalStorage and changed from sessionStorage to localStorage, refactored from singleton to factory function
extension/src/viewer/App.tsx Split into App and LoadedApp components with loading state check, moved ApplicationState logic to separate file
extension/src/options/MainOptions.tsx Removed gotoPage from context, added as direct prop
extension/src/options/EditCustomTheme.tsx Removed gotoPage from context, added as direct prop
extension/src/options/Context.ts Removed gotoPage from OptionsContext
extension/src/options/App.tsx Added LoadedApp wrapper component with loading state, moved gotoPage out of context
extension/src/launcher/App.tsx Added conditional rendering based on theme loading state
extension/src/content/Activator.ts Changed from STORAGE singleton to getStorage() factory function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extension/src/viewer/commons/Storage.ts Outdated
Comment thread extension/src/viewer/hooks/UseStorage.ts Outdated
Comment thread extension/src/viewer/state/ApplicationState.ts
Comment thread extension/src/viewer/components/ViewerPlaceholder.tsx Outdated
@paolosimone paolosimone requested a review from Copilot November 2, 2025 07:03
Copy link
Copy Markdown
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

Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extension/src/viewer/state/ApplicationState.ts
@paolosimone paolosimone force-pushed the refactor-application-state branch from fddefee to 42f8292 Compare November 2, 2025 07:05
@paolosimone paolosimone merged commit 3f88e14 into main Nov 2, 2025
@paolosimone paolosimone deleted the refactor-application-state branch November 2, 2025 07:08
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