fix: close relation metadata cache races - #492
Merged
Merged
Conversation
Reviewer's GuideAdjusts workspace permission handling and relation metadata lifecycle to avoid races between share-change invalidation, database catalog loading, and relation fallback state while disabled, with tests covering the new behaviors. Sequence diagram for relation catalog request restart on invalidationsequenceDiagram
actor User
participant RelationCellMenu
participant useRelationData
participant DatabaseContext
participant WorkspaceCatalog
User->>RelationCellMenu: open relation menu
RelationCellMenu->>useRelationData: useRelationData(fieldId, { enabled: true })
useRelationData->>WorkspaceCatalog: getCachedWorkspaceDatabaseCatalog(workspaceId)
WorkspaceCatalog-->>useRelationData: undefined
useRelationData->>WorkspaceCatalog: getWorkspaceDatabaseCatalog(workspaceId) (initial)
useRelationData->>DatabaseContext: loadViews()
DatabaseContext-->>useRelationData: outline pending
WorkspaceCatalog->>WorkspaceCatalog: publishMockWorkspaceCatalog(workspaceCatalog)
WorkspaceCatalog-->>useRelationData: initial catalog snapshot
WorkspaceCatalog->>WorkspaceCatalog: publishMockWorkspaceCatalog(undefined)
WorkspaceCatalog-->>useRelationData: catalog invalidation while outline pending
DatabaseContext-->>useRelationData: outline resolves []
useRelationData->>WorkspaceCatalog: getWorkspaceDatabaseCatalog(workspaceId) (replacement)
WorkspaceCatalog-->>useRelationData: replacement catalog
useRelationData-->>RelationCellMenu: selectedView.name = Replacement Projects
Sequence diagram for relation fallback retirement while disabled and access revoke/restoresequenceDiagram
actor User
participant RelationCellMenu
participant useRelationData
participant DatabaseContext
participant EventEmitter
User->>RelationCellMenu: open relation menu (enabled: true)
RelationCellMenu->>useRelationData: useRelationData(fieldId, { enabled: true })
useRelationData->>DatabaseContext: loadViewMeta(viewId)
DatabaseContext-->>useRelationData: primaryView (Tasks)
useRelationData-->>RelationCellMenu: selectedView = Tasks
User->>RelationCellMenu: close relation menu (enabled: false)
RelationCellMenu->>useRelationData: rerender { enabled: false }
useRelationData->>useRelationData: [retire fallback metadata]
useRelationData->>EventEmitter: unsubscribe VIEW_ACCESS_REVOKED and VIEW_ACCESS_RESTORED
EventEmitter-->>useRelationData: VIEW_ACCESS_REVOKED (while disabled)
useRelationData-->>EventEmitter: no listener, event missed
User->>RelationCellMenu: reopen relation menu (enabled: true)
RelationCellMenu->>useRelationData: rerender { enabled: true }
useRelationData->>DatabaseContext: loadViewMeta(viewId)
DatabaseContext-->>useRelationData: error Access revoked
useRelationData-->>RelationCellMenu: selectedView remains undefined
Note over useRelationData,EventEmitter: In a restore scenario, VIEW_ACCESS_RESTORED fires while disabled
User->>RelationCellMenu: reopen after restore
useRelationData->>DatabaseContext: loadViewMeta(viewId)
DatabaseContext-->>useRelationData: primaryView (Tasks)
useRelationData-->>RelationCellMenu: selectedView = Tasks
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In the new
useEffectthat retires fallback metadata whenenabledis false,workspaceIdis in the dependency array but not referenced in the body; consider removing it to avoid unnecessary re-runs when the workspace changes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the new `useEffect` that retires fallback metadata when `enabled` is false, `workspaceId` is in the dependency array but not referenced in the body; consider removing it to avoid unnecessary re-runs when the workspace changes.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Summary
Validation
pnpm exec jest— 6 focused suites, 146 testspnpm lintpnpm buildgit diff --checkFollow-up to #491.
Summary by Sourcery
Harden workspace share invalidation and relation metadata revalidation to prevent stale or inaccessible relation data from resurfacing.
Bug Fixes:
Enhancements:
Tests: