Refactor application state#110
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.
Contributor
There was a problem hiding this comment.
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.
fddefee to
42f8292
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.