Skip to content

fix: storage view is not reset when switching buckets - #43370

Merged
djhi merged 8 commits into
masterfrom
fe-2666-bug-with-storage-ui-wrong-contents-displayed-when-switching
Mar 5, 2026
Merged

djhi merged 8 commits into
masterfrom
fe-2666-bug-with-storage-ui-wrong-contents-displayed-when-switching

Conversation

@djhi

@djhi djhi commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

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

  1. Create 2 buckets
  2. In one of them, create a folder and upload some files
  3. Go back to the bucket list
  4. Open the other bucket

Results:

  • It should not show the previous bucket content anymore
  • It should not show an empty 2nd column either

@djhi
djhi requested a review from a team as a code owner March 4, 2026 08:44
@vercel

vercel Bot commented Mar 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

9 Skipped Deployments
Project Deployment Actions Updated (UTC)
cms Ignored Ignored Mar 5, 2026 9:00am
studio Ignored Ignored Mar 5, 2026 9:00am
design-system Skipped Skipped Mar 5, 2026 9:00am
docs Skipped Skipped Mar 5, 2026 9:00am
learn Skipped Skipped Mar 5, 2026 9:00am
studio-self-hosted Skipped Skipped Mar 5, 2026 9:00am
studio-staging Skipped Skipped Mar 5, 2026 9:00am
ui-library Skipped Skipped Mar 5, 2026 9:00am
zone-www-dot-com Skipped Skipped Mar 5, 2026 9:00am

Request Review

@supabase

supabase Bot commented Mar 4, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 4a5ca663-b3a8-4843-be36-18dfb880ee35

📥 Commits

Reviewing files that changed from the base of the PR and between 1af1d4e and 524a33d.

📒 Files selected for processing (1)
  • e2e/studio/features/storage.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/studio/features/storage.spec.ts

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Fixed storage view not properly resetting when switching between buckets, ensuring each bucket displays only its own contents.
  • Tests

    • Added end-to-end test to verify storage view refreshes correctly when navigating between buckets.

Walkthrough

This pull request refactors the storage explorer's bucket handling to properly detect and react to bucket switching. The createStorageExplorerState function now accepts an optional bucketId parameter and includes it in the state object. The StorageExplorerStateContextProvider uses a useRef to track the current bucket and compares it during effect execution to detect bucket changes, triggering state reinitialization when switching occurs. The StorageExplorer component is updated to retrieve bucketId from the state snapshot instead of URL parameters, and dependency arrays are adjusted accordingly. An end-to-end test is added to verify that the storage view resets when navigating between different buckets.

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between dfd5461 and a65c66f.

📒 Files selected for processing (2)
  • apps/studio/components/interfaces/Storage/FilesBuckets/BucketTable.tsx
  • e2e/studio/features/storage.spec.ts

@joshenlim joshenlim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified changes on preview! just pushed up some very minor nits

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
apps/studio/components/interfaces/Storage/FilesBuckets/BucketTable.tsx (1)

99-112: ⚠️ Potential issue | 🟠 Major

Guard state reset so it runs only for actual navigation inputs

On Line 99–103, snap.setSelectedBucket(bucket) runs for every onKeyDown and onAuxClick event 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

📥 Commits

Reviewing files that changed from the base of the PR and between a65c66f and d05d1b8.

📒 Files selected for processing (1)
  • apps/studio/components/interfaces/Storage/FilesBuckets/BucketTable.tsx

@github-actions

github-actions Bot commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  143 passed
flaky  5 flaky
skipped  4 skipped

Details

stats  152 tests across 20 suites
duration  10 minutes, 2 seconds
commit  524a33d

Flaky tests

Features › cron-jobs.spec.ts › Cron Jobs Integration › Cron Jobs CRUD Operations › can view cron jobs page
Features › database.spec.ts › Database › Schema Visualizer › actions works as expected
Features › realtime-inspector.spec.ts › Realtime Inspector › Broadcast Messages › broadcast modal validates JSON payload
Features › sql-editor.spec.ts › SQL Editor › should check if SQL editor is working as expected
Features › table-editor.spec.ts › table editor › filtering rows works as expected

Skipped tests

Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@djhi
djhi marked this pull request as draft March 4, 2026 09:48
@blacksmith-sh

This comment has been minimized.

@djhi
djhi marked this pull request as ready for review March 4, 2026 13:58

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟠 Major

Bucket-change detection is stale and can skip state reset on return navigation.

bucketRef.current is initialized once (Line 1877) but never updated. hasBucketChanged (Line 1893) then compares against a stale value, so a flow like A → B → A can miss the reset on the second A, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 21c791b and 1af1d4e.

📒 Files selected for processing (3)
  • apps/studio/components/interfaces/Storage/FilesBuckets/BucketTable.tsx
  • apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.tsx
  • apps/studio/state/storage-explorer.tsx

}: BucketTableRowProps) => {
const router = useRouter()
const { getPolicyCount } = useBucketPolicyCount()
const snap = useStorageExplorerStateSnapshot()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this change, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I actually don't need to change that file at all

@blacksmith-sh

This comment has been minimized.

@djhi
djhi requested a review from ivasilov March 5, 2026 09:25
@djhi
djhi merged commit 9ce3bdf into master Mar 5, 2026
23 checks passed
@djhi
djhi deleted the fe-2666-bug-with-storage-ui-wrong-contents-displayed-when-switching branch March 5, 2026 11:10
@github-actions

github-actions Bot commented Mar 5, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1772709153)

Score Average Improvements Regressions
Completeness 97.2% (+11pp) 3 🟢 -
Conciseness 0% (+0pp) - -
Goal Completion 97.2% (+10pp) 4 🟢 -
Tool Usage 100% (+0pp) - -
Correctness 100% (+8pp) 1 🟢 -
Docs Faithfulness 58.3% (-6pp) - 2 🔴
URL Validity 100% (+9pp) - -
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 93.3% (-7.000000000000001pp) - 1 🔴
Time_to_first_token 0.32tok (+0.1tok) - 12 🔴
Llm_calls 8.53 (+0.14) 5 🟢 3 🔴
Tool_calls 3.19 (+0.08) 6 🟢 4 🔴
Errors 0 (-0.03) 1 🟢 -
Llm_errors 0 (-0.03) 1 🟢 -
Tool_errors 0 (+0) - -
Prompt_tokens 50929.42tok (-4209.06tok) 8 🟢 4 🔴
Prompt_cached_tokens 28241.78tok (+6293.33tok) 10 🟢 2 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Completion_tokens 2703.86tok (+149.31tok) 3 🟢 9 🔴
Completion_reasoning_tokens 1934.22tok (+19.56tok) 4 🟢 8 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 53633.28tok (-4059.75tok) 8 🟢 4 🔴
Estimated_cost 0.01$ (0$) 8 🟢 4 🔴
Duration 40.57s (-6.4s) 9 🟢 3 🔴
Llm_duration 79.45s (-13.04s) 9 🟢 3 🔴

joshenlim added a commit that referenced this pull request Mar 9, 2026
## 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
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.

3 participants