Skip to content

fix(storage): make dedicated storage host opt-in via useNewHostname flag#1329

Merged
grdsdev merged 1 commit into
mainfrom
guilherme/sdk-789-fixstorage-_transformstorageurl-unconditionally-breaks
Mar 25, 2026
Merged

fix(storage): make dedicated storage host opt-in via useNewHostname flag#1329
grdsdev merged 1 commit into
mainfrom
guilherme/sdk-789-fixstorage-_transformstorageurl-unconditionally-breaks

Conversation

@grdsdev
Copy link
Copy Markdown
Contributor

@grdsdev grdsdev commented Mar 25, 2026

Summary

storage_client 2.5.0 introduced _transformStorageUrl() which unconditionally rewrites all storage URLs to use the dedicated storage host (*.storage.supabase.co). This host is not available on all projects, silently breaking every storage operation with StorageException: Invalid Storage request.

This PR implements Option B: make the URL transformation opt-in (useNewHostname defaults to false). Projects with the dedicated storage host enabled can opt in via StorageClientOptions(useNewHostname: true) in Supabase.initialize().

Changes

  • storage_client: Added useNewHostname parameter to SupabaseStorageClient (defaults to false)
  • supabase: Added useNewHostname field to StorageClientOptions, threaded through to SupabaseStorageClient
  • Tests: Reorganized URL construction tests into default behavior (useNewHostname: false) and opt-in behavior (useNewHostname: true) groups; added 6 new tests covering the default no-transform path

Root Cause

  • File: packages/storage_client/lib/src/storage_client.dart:45
  • Issue: _transformStorageUrl(url) was called unconditionally at construction time
  • Fix: useNewHostname ? _transformStorageUrl(url) : url

Testing

Reproduction Test

All 35 tests in storage_client pass, including 12 URL construction tests that explicitly verify both the default (no transform) and opt-in (transform) paths.

Test Coverage

  • 6 new tests: default behavior does not transform any Supabase host URLs
  • 6 existing tests: opt-in behavior preserves all original transformation cases
  • All other storage_client and supabase package tests continue to pass

Manual Testing

  • Test with a project that does NOT have *.storage.supabase.co enabled (default should work)
  • Test with a project that has the dedicated host enabled and useNewHostname: true

Risk Assessment

  • Breaking changes: Yes — projects relying on the automatic URL transformation will need to add StorageClientOptions(useNewHostname: true). This is intentional (Option B).
  • Migration: Add storageOptions: StorageClientOptions(useNewHostname: true) to Supabase.initialize() if your project has the dedicated storage host enabled.
  • Performance impact: Negligible (single boolean check at construction time)

Acceptance Criteria

  • Projects without dedicated storage host can use legacy URL format (default behavior)
  • useNewHostname: true flag available from StorageClientOptions through to SupabaseStorageClient
  • All existing URL transformation tests continue to pass (as opt-in tests)
  • New tests cover the useNewHostname: false default path
  • No breaking changes to the public StorageFileApi surface

Linear Issue

Closes: SDK-789
GitHub: #1328


🤖 Generated with Claude Code /take

_transformStorageUrl unconditionally rewrote all storage URLs to use
the dedicated storage host (*.storage.supabase.co), which is not
available on all projects. This silently broke every storage operation
with StorageException: Invalid Storage request.

Option B: change the default to opt-in (useNewHostname defaults to
false). Projects that have the dedicated storage host enabled can
opt in via StorageClientOptions(useNewHostname: true) in
Supabase.initialize().

The URL transformation logic and its tests are preserved; they now
run only when useNewHostname: true is passed.

Fixes: #1328
Linear: SDK-789

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 25, 2026 11:35
@github-actions github-actions Bot added the storage This issue or pull request is related to storage label Mar 25, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a regression in storage_client 2.5.0 where storage base URLs were always rewritten to the dedicated storage hostname (*.storage.supabase.co), breaking projects that don’t have that host enabled. It makes the rewrite behavior opt-in via a useNewHostname flag, defaulting to false, and wires the option through the supabase package.

Changes:

  • Add useNewHostname (default false) to SupabaseStorageClient to gate _transformStorageUrl() behind an opt-in flag.
  • Expose useNewHostname via StorageClientOptions in supabase and pass it through when initializing the storage client.
  • Reorganize and expand URL-construction tests to cover both default (no transform) and opt-in (transform) behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/supabase/lib/src/supabase_client_options.dart Adds StorageClientOptions.useNewHostname with documentation and default false.
packages/supabase/lib/src/supabase_client.dart Threads useNewHostname from StorageClientOptions into SupabaseStorageClient initialization.
packages/storage_client/lib/src/storage_client.dart Makes legacy→dedicated host rewrite conditional on useNewHostname.
packages/storage_client/test/basic_test.dart Splits URL construction tests into default vs opt-in groups and adds coverage for the default path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@grdsdev grdsdev requested review from a team, Vinzent03 and dshukertjr March 25, 2026 13:00
@grdsdev grdsdev merged commit a664082 into main Mar 25, 2026
19 of 20 checks passed
@grdsdev grdsdev deleted the guilherme/sdk-789-fixstorage-_transformstorageurl-unconditionally-breaks branch March 25, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storage This issue or pull request is related to storage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

storage_client 2.5.0: _transformStorageUrl breaks projects without dedicated storage host

3 participants