-
Notifications
You must be signed in to change notification settings - Fork 578
Fix: PWA cache crash #794
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
Merged
Merged
Fix: PWA cache crash #794
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,11 +160,31 @@ export function restoreFromUICache( | |
|
|
||
| // Restore last selected worktree per project so the board doesn't | ||
| // reset to main branch after PWA memory eviction or tab discard. | ||
| // | ||
| // IMPORTANT: Only restore entries where path is null (main branch selection). | ||
| // Non-null paths point to worktree directories on disk that may have been | ||
| // deleted while the PWA was evicted. Restoring a stale worktree path causes | ||
| // the board to render with an invalid selection, and if the server can't | ||
| // validate it fast enough, the app enters an unrecoverable crash loop | ||
| // (the error boundary reloads, which restores the same bad cache). | ||
| // Main branch (path=null) is always valid and safe to restore. | ||
| if ( | ||
| cache.cachedCurrentWorktreeByProject && | ||
| Object.keys(cache.cachedCurrentWorktreeByProject).length > 0 | ||
| ) { | ||
| stateUpdate.currentWorktreeByProject = cache.cachedCurrentWorktreeByProject; | ||
| const sanitized: Record<string, { path: string | null; branch: string }> = {}; | ||
| for (const [projectPath, worktree] of Object.entries(cache.cachedCurrentWorktreeByProject)) { | ||
| if (worktree.path === null) { | ||
| // Main branch selection — always safe to restore | ||
| sanitized[projectPath] = worktree; | ||
| } | ||
| // Non-null paths are dropped; the app will re-discover actual worktrees | ||
| // from the server and the validation effect in use-worktrees will handle | ||
| // resetting to main if the cached worktree no longer exists. | ||
| } | ||
| if (Object.keys(sanitized).length > 0) { | ||
| stateUpdate.currentWorktreeByProject = sanitized; | ||
| } | ||
|
Comment on lines
+175
to
+187
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic for sanitizing the worktree cache can be written more concisely using functional programming constructs like // Main branch selection — always safe to restore
const sanitizedEntries = Object.entries(cache.cachedCurrentWorktreeByProject).filter(
([, worktree]) => worktree.path === null
);
if (sanitizedEntries.length > 0) {
stateUpdate.currentWorktreeByProject = Object.fromEntries(sanitizedEntries);
}
// Non-null paths are dropped; the app will re-discover actual worktrees
// from the server and the validation effect in use-worktrees will handle
// resetting to main if the cached worktree no longer exists. |
||
| } | ||
|
|
||
| // Restore the project context when the project object is available. | ||
|
|
||
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.
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.
To avoid using a magic string for the UI cache key (
'automaker-ui-cache'), it's good practice to define it as a constant here, alongside the other constants. This key is used incomponentDidCatchandhandleClearCacheAndReload.After adding this constant, you can replace the hardcoded string in both places.