Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 9 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Central YAML (base), Repository UI (inherited), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis pull request refactors the storage explorer's bucket handling to properly detect and react to bucket switching. The Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/studio/components/interfaces/Storage/FilesBuckets/BucketTable.tsx`:
- Around line 98-112: Guard the state reset so it only runs for real navigation
events: update handleNavigation (the function used by BucketTableRow) to narrow
the union event type (React.MouseEvent | React.KeyboardEvent) and only call
snap.setSelectedBucket(bucket) and handleBucketNavigation(event) when the event
indicates navigation — for mouse events ensure it’s a primary/middle click
(check (event as React.MouseEvent).button === 0 or === 1 or check event.type for
"auxclick" and button === 1), and for keyboard events only proceed on Enter or
Space (check event.key === "Enter" or event.key === " " / "Spacebar"); if the
check fails, return early without mutating snap or navigating. Ensure this logic
is used for the handler attached to BucketTableRow (onClick, onAuxClick,
onKeyDown).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Repository UI (inherited), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 7fd96fe2-5f89-43bd-bee0-e1f3f3b36d63
📒 Files selected for processing (2)
apps/studio/components/interfaces/Storage/FilesBuckets/BucketTable.tsxe2e/studio/features/storage.spec.ts
joshenlim
left a comment
There was a problem hiding this comment.
Verified changes on preview! just pushed up some very minor nits
There was a problem hiding this comment.
♻️ Duplicate comments (1)
apps/studio/components/interfaces/Storage/FilesBuckets/BucketTable.tsx (1)
99-112:⚠️ Potential issue | 🟠 MajorGuard state reset so it runs only for actual navigation inputs
On Line 99–103,
snap.setSelectedBucket(bucket)runs for everyonKeyDownandonAuxClickevent wired on Line 110–112, including non-navigation interactions (e.g. arrow keys/right-click). That can reset explorer state without navigating.Proposed fix
- const handleNavigation = (event: MouseEvent | KeyboardEvent) => { - // Reset the Storage Explorer state here to avoid race conditions with loading effects in StorageExplorer - snap.setSelectedBucket(bucket) - handleBucketNavigation(event) - } + const handleNavigation = (event: MouseEvent | KeyboardEvent) => { + const isKeyboardNav = + event.type === 'keydown' && + ((event as KeyboardEvent).key === 'Enter' || (event as KeyboardEvent).key === ' ') + const isPrimaryClick = event.type === 'click' && (event as MouseEvent).button === 0 + const isMiddleClick = event.type === 'auxclick' && (event as MouseEvent).button === 1 + + if (!isKeyboardNav && !isPrimaryClick && !isMiddleClick) return + + snap.setSelectedBucket(bucket) + handleBucketNavigation(event) + }As per coding guidelines: “Comment only when the issue must be resolved before merge — otherwise remain silent.”
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/studio/components/interfaces/Storage/FilesBuckets/BucketTable.tsx` around lines 99 - 112, The state reset snap.setSelectedBucket(bucket) in handleNavigation runs for every onKeyDown/onAuxClick event; change handleNavigation to first detect event type and only call snap.setSelectedBucket(bucket) for actual navigation inputs: for MouseEvent, require primary (button === 0) or middle button (button === 1) and ignore right-click/contextmenu (button === 2); for KeyboardEvent, only proceed when event.key is 'Enter' or ' ' (Space); keep calling handleBucketNavigation(event) as before. Update the function signature/guards in handleNavigation to narrow event types (e.g., instanceof MouseEvent / KeyboardEvent or check 'key' in event) and apply these checks before invoking snap.setSelectedBucket, leaving BucketTableRow handlers (onClick, onAuxClick, onKeyDown) intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@apps/studio/components/interfaces/Storage/FilesBuckets/BucketTable.tsx`:
- Around line 99-112: The state reset snap.setSelectedBucket(bucket) in
handleNavigation runs for every onKeyDown/onAuxClick event; change
handleNavigation to first detect event type and only call
snap.setSelectedBucket(bucket) for actual navigation inputs: for MouseEvent,
require primary (button === 0) or middle button (button === 1) and ignore
right-click/contextmenu (button === 2); for KeyboardEvent, only proceed when
event.key is 'Enter' or ' ' (Space); keep calling handleBucketNavigation(event)
as before. Update the function signature/guards in handleNavigation to narrow
event types (e.g., instanceof MouseEvent / KeyboardEvent or check 'key' in
event) and apply these checks before invoking snap.setSelectedBucket, leaving
BucketTableRow handlers (onClick, onAuxClick, onKeyDown) intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Repository UI (inherited), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 0f19f76b-db5a-4d57-99d8-a06f7c62a487
📒 Files selected for processing (1)
apps/studio/components/interfaces/Storage/FilesBuckets/BucketTable.tsx
🎭 Playwright Test ResultsDetails
Flaky testsFeatures › cron-jobs.spec.ts › Cron Jobs Integration › Cron Jobs CRUD Operations › can view cron jobs page Skipped testsFeatures › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/studio/state/storage-explorer.tsx (1)
1877-1900:⚠️ Potential issue | 🟠 MajorBucket-change detection is stale and can skip state reset on return navigation.
bucketRef.currentis initialized once (Line 1877) but never updated.hasBucketChanged(Line 1893) then compares against a stale value, so a flow likeA → B → Acan miss the reset on the secondA, allowing stale explorer state to persist.Proposed fix
- const bucketRef = useRef(bucket?.id) + const bucketRef = useRef<string | undefined>(undefined) useEffect(() => { const hasDataReady = !!project?.ref const storeAlreadyLoaded = state.projectRef === project?.ref const hasBucketChanged = bucket?.id !== bucketRef.current if ( !isPaused && hasDataReady && isSuccessSettings && (!storeAlreadyLoaded || hasBucketChanged) ) { const clientEndpoint = storageEndpoint ?? hostEndpoint ?? '' const resumableUploadUrl = `${clientEndpoint}/storage/v1/upload/resumable` setState( createStorageExplorerState({ projectRef: project?.ref ?? '', bucketId: bucket?.id, connectionString: project.connectionString ?? '', resumableUploadUrl, clientEndpoint, }) ) + bucketRef.current = bucket?.id } }, [🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/studio/state/storage-explorer.tsx` around lines 1877 - 1900, bucketRef.current is only set once and never updated, so hasBucketChanged (computed from bucket?.id !== bucketRef.current) can be stale and skip resets on return navigation; update the ref after you detect/handle the change inside the useEffect (or compute hasBucketChanged from a fresh value) so bucketRef.current reflects the current bucket id — modify the useEffect that contains bucketRef, hasBucketChanged, and state.projectRef to assign bucketRef.current = bucket?.id after performing the reset/logic so subsequent navigations (A → B → A) correctly detect the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@apps/studio/state/storage-explorer.tsx`:
- Around line 1877-1900: bucketRef.current is only set once and never updated,
so hasBucketChanged (computed from bucket?.id !== bucketRef.current) can be
stale and skip resets on return navigation; update the ref after you
detect/handle the change inside the useEffect (or compute hasBucketChanged from
a fresh value) so bucketRef.current reflects the current bucket id — modify the
useEffect that contains bucketRef, hasBucketChanged, and state.projectRef to
assign bucketRef.current = bucket?.id after performing the reset/logic so
subsequent navigations (A → B → A) correctly detect the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Repository UI (inherited), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 9f84594b-7104-4546-bf1d-4623f047b79f
📒 Files selected for processing (3)
apps/studio/components/interfaces/Storage/FilesBuckets/BucketTable.tsxapps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.tsxapps/studio/state/storage-explorer.tsx
| }: BucketTableRowProps) => { | ||
| const router = useRouter() | ||
| const { getPolicyCount } = useBucketPolicyCount() | ||
| const snap = useStorageExplorerStateSnapshot() |
There was a problem hiding this comment.
You don't need this change, right?
There was a problem hiding this comment.
Yeah I actually don't need to change that file at all
…-displayed-when-switching
This comment has been minimized.
This comment has been minimized.
Braintrust eval report
|
## Context Taking a slightly different approach to [this PR](#43370) Original problem was that if you opened some folders while in a bucket and then switched to a different bucket, the folder UI will persists (folders from Bucket A will render when landing on Bucket B) ## Changes involved - Shift `StorageExplorerStateContextProvider` into `[bucketId].tsx]` instead of `ProjectContext` - The valtio store here only applies for the storage explorer so having it so high in the project's context was unnecessary - This also just implies that the valtio store will automatically reset whenever the bucket changes - Simplify storage explorer valtio store by initializing the store with the bucket - We'll initialize the selected bucket with the store now (Same as previous PR) - Removes unnecessary `setSelectedBucket` method which required a separate `useEffect` in `StorageExplorer.tsx` ## To test - [ ] Verify that the original is resolved - [ ] General smoke test of the storage explorer - i've also re-added the e2e test that Gildas wrote up in his PR
Problem
When navigating between buckets after having selected a folder, the storage view shows the previous folder content.
Solution
Set the selected bucket before navigating to it, preventing a race condition with Valtio updates and the effect that loads the bucket content.
How to test
Results: