Skip to content

fix storage.download() returns stale/cached data after file updates - #41855

Closed
Adityakk9031 wants to merge 2 commits into
supabase:masterfrom
Adityakk9031:#41841
Closed

Adityakk9031 wants to merge 2 commits into
supabase:masterfrom
Adityakk9031:#41841

Conversation

@Adityakk9031

@Adityakk9031 Adityakk9031 commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

Issue
storage.download() returns stale data because it uses the default fetch behavior which may cache responses, and the method currently provides no way to pass Cache-Control headers or options to opt-out of this caching (e.g. no-store). This is particularly problematic in environments like Supabase Edge Functions (Deno).

Solution
Updated the documentation in
apps/docs/content/guides/storage/quickstart.mdx
to provide a verified workaround. The guide now includes an example of using createSignedUrl combined with fetch(..., { cache: 'no-store' }) to ensure fresh data retrieval.

Includes inline comments to clarify URL validity and blob usage, incorporating review feedback for better developer experience.

closes:#41841

Summary by CodeRabbit

  • Documentation
    • Updated Storage Quickstart (JavaScript) download section with an admonition about cached/stale downloads. Adds guidance on obtaining the freshest file by using signed download links and fetching with cache control to bypass caches, and includes a code example demonstrating the approach.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel

vercel Bot commented Jan 12, 2026 •

Copy link
Copy Markdown

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

Project Deployment Review Updated (UTC)
design-system Ready Ready Preview, Comment Jan 12, 2026 0:41am

@vercel

vercel Bot commented Jan 12, 2026

Copy link
Copy Markdown

@Adityakk9031 is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jan 12, 2026
@coderabbitai

coderabbitai Bot commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds an Admonition to the Storage Quickstart documentation noting that downloaded files can be stale due to caching and shows how to fetch the latest version by creating a signed URL and using fetch with cache: 'no-store'.

Changes

Cohort / File(s) Summary
Storage Download Documentation
apps/docs/content/guides/storage/quickstart.mdx
Added an Admonition in the JavaScript Download section explaining caching behavior and a code example that creates a signed URL and fetches the file with cache: 'no-store' to obtain a fresh copy (+19 lines).
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description addresses the issue and provides context, but lacks key template sections like 'What kind of change', explicit 'current behavior', 'new behavior', and 'CONTRIBUTING.md' acknowledgment. Ensure the description follows the template structure: confirm CONTRIBUTING.md review, explicitly state this is a 'docs update', clearly articulate current vs. new behavior, and add any relevant screenshots or context.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: documenting a workaround for storage.download() returning stale cached data.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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: 0

🧹 Nitpick comments (2)
apps/docs/content/guides/storage/quickstart.mdx (2)

199-216: Documentation addition looks good overall.

The workaround is appropriate for the caching issue described in the linked issue. A few minor suggestions to improve clarity:

  1. The blob variable is created but not shown being used—consider adding a brief comment or showing what to do with it (e.g., // Use blob as needed).
  2. Consider adding basic error handling or a note that production code should check response.ok.
  3. The 60-second expiry is fine, but a brief inline comment explaining it's the URL validity duration could help newcomers.
📝 Suggested improvement for the code example
 const { data } = await supabase.storage
   .from('avatars')
-  .createSignedUrl('public/avatar1.png', 60)
+  .createSignedUrl('public/avatar1.png', 60) // URL valid for 60 seconds

 if (data) {
   const response = await fetch(data.signedUrl, { cache: 'no-store' })
   const blob = await response.blob()
+  // Use blob as needed (e.g., create object URL, read as text, etc.)
 }

218-257: Consider adding similar cache workaround notes for other SDK tabs.

The caching issue may also affect Dart, Swift, and Python SDKs depending on the underlying HTTP client behavior. Users of those SDKs might encounter the same stale data problem but won't see any guidance.

You may want to verify whether the other SDKs (Dart, Swift, Python) have similar caching behavior and, if so, add equivalent workarounds or at minimum a note directing users to a common solution.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b24778c and a63dc3c.

📒 Files selected for processing (1)
  • apps/docs/content/guides/storage/quickstart.mdx
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-01-05T23:42:52.357Z
Learnt from: kallebysantos
Repo: supabase/supabase PR: 41727
File: apps/docs/content/guides/functions/auth.mdx:93-93
Timestamp: 2026-01-05T23:42:52.357Z
Learning: When reviewing MDX documentation that uses CodeSample components in Supabase docs, it's acceptable for CodeSample meta attributes to display generic example file names (e.g., hello/index.ts) to illustrate templating. Do not flag these as file-path mismatches unless the docs claim an exact reference to a real file. If you encounter such code samples, ensure the surrounding text clarifies that the names are placeholders to be adapted by users, and suggest adding a note explaining how to map the template to a real project path.

Applied to files:

  • apps/docs/content/guides/storage/quickstart.mdx

@mandarini

mandarini commented Feb 4, 2026 •

Copy link
Copy Markdown
Contributor

Hi @Adityakk9031!

Thank you for documenting a workaround for this issue. However, we're going to close this PR because we're fixing the root cause in the SDK instead.

Why We're Not Merging This

While your workaround technically works, it has some issues:

  1. Misuse of createSignedUrl() - This method is for private buckets, but your example path suggests a public file
  2. Bypasses SDK features - Manual fetch() loses error handling, authentication, and RLS enforcement
  3. Missing context - The issue is specific to Edge Functions (Deno runtime), not universal
  4. Overly complex - Requires two API calls instead of one
  5. Wrong layer - This is an SDK limitation, not something users should work around

The Proper Fix

We're fixing this in the SDK itself by exposing fetch parameters in the download() method: supabase/supabase-js#2090

Once released, the clean solution will be:

// Edge Functions - bypass cache
const { data, error } = await supabase.storage
  .from('avatars')
  .download('file.png', {}, { cache: 'no-store' })

// Default (browsers/Node.js)
const { data, error } = await supabase.storage
  .from('avatars')
  .download('file.png')

And I'll make sure to document this.

Thank you very much for contributing to Supabase! Your contributions is what makes our tools better 💚

@mandarini mandarini closed this Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants