Skip to content

refactor: drop retry dependency in favor of an in-house helper - #1571

Merged
spydon merged 2 commits into
mainfrom
refactor/inline-retry
Jul 9, 2026
Merged

spydon merged 2 commits into
mainfrom
refactor/inline-retry

Conversation

@spydon

@spydon spydon commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What

Removes the retry package from both gotrue and storage_client, replacing it with a small self-contained RetryOptions/retry helper (lib/src/retry.dart) in each package.

  • gotrue used the top-level retry() (token refresh).
  • storage_client used RetryOptions(...).retry(...) (request retries).

Why

Both packages pulled in retry for the same narrow use: exponential backoff gated by a retryIf predicate. The helper is ~40 lines and mirrors the package's behavior exactly:

  • 200 ms delay factor, 2^attempt backoff
  • 25% jitter (randomizationFactor)
  • 30 s max delay
  • 8 max attempts by default

gotrue's time-budget retryIf depends on these exact defaults, so they are preserved.

Testing

  • New retry_test.dart in gotrue covers success-after-retries, maxAttempts cutoff, retryIf short-circuit, RetryOptions.retry (the storage usage shape), and exponential/capped delay math — all pass.
  • dart analyze clean for both packages.

Note: the helper is duplicated in each package because they are published independently and there is no shared internal utility package.

@spydon
spydon requested a review from a team as a code owner July 9, 2026 10:05
@spydon
spydon force-pushed the refactor/inline-retry branch from 8218f4b to 3b2af42 Compare July 9, 2026 12:41
@spydon
spydon changed the base branch from main to refactor/supabase-drop-rxdart July 9, 2026 12:41
spydon added a commit that referenced this pull request Jul 9, 2026
Introduces a new published supabase_common package and moves the
non-breaking shared/duplicated code into it:

- ToSnakeCase enum extension (was duplicated in gotrue and storage_client)
- Platform detection (was duplicated in supabase and supabase_flutter,
  keeping the extra isRunningInFlutterTest flag)
- buildClientInfoHeader for the X-Client-Info header (simple and
  platform-aware forms) used by all client packages
- isSuccessStatusCode 2xx helper
- FetchOptions (was duplicated internally in gotrue and storage_client)
- Base64Url, PKCE and uuid helpers (moved out of gotrue, also fixing an
  intra-gotrue duplication in jwt.dart)
- A unified ReplaySubject replacing gotrue's _ReplaySubject and
  supabase's _BehaviorSubject
- The in-house retry helper (was duplicated in gotrue and storage_client
  by #1571)

Refs #1572
spydon added a commit that referenced this pull request Jul 9, 2026
Introduces a new published supabase_common package and moves the
non-breaking shared/duplicated code into it:

- ToSnakeCase enum extension (was duplicated in gotrue and storage_client)
- Platform detection (was duplicated in supabase and supabase_flutter,
  keeping the extra isRunningInFlutterTest flag)
- buildClientInfoHeader for the X-Client-Info header (simple and
  platform-aware forms) used by all client packages
- isSuccessStatusCode 2xx helper
- FetchOptions (was duplicated internally in gotrue and storage_client)
- Base64Url, PKCE and uuid helpers (moved out of gotrue, also fixing an
  intra-gotrue duplication in jwt.dart)
- A unified ReplaySubject replacing gotrue's _ReplaySubject and
  supabase's _BehaviorSubject
- The in-house retry helper (was duplicated in gotrue and storage_client
  by #1571)

supabase_common is excluded from the SDK compliance public-API scan via
.sdk-parse-ignore: its symbols are consumed across packages and so cannot
be marked @internal without tripping invalid_use_of_internal_member.

Refs #1572
Base automatically changed from refactor/supabase-drop-rxdart to main July 9, 2026 13:49

@o-santi o-santi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note: the helper is duplicated in each package because they are published independently and there is no shared internal utility package.

I would strongly recommend on creating a shared utility package for this use case. Even though it is the only one currently, in my experience a lot more shared code will appear, and you'll see the number of duplicated "utilities" grow over time.

Tr00d commented Jul 9, 2026

Copy link
Copy Markdown

@o-santi There's another PR specifically for this, a new common package for reusability

spydon added 2 commits July 9, 2026 15:52
Both gotrue and storage_client used the retry package for the same
thing: exponential backoff with a retryIf predicate. gotrue used the
top-level retry() and storage_client used RetryOptions.

Replaces it with a small self-contained RetryOptions/retry helper in
each package that mirrors the retry package's behavior (200ms delay
factor, 2^attempt backoff, 25% jitter, 30s max delay, 8 max attempts by
default).
@spydon
spydon force-pushed the refactor/inline-retry branch from 3b2af42 to 358f8e1 Compare July 9, 2026 13:53
@spydon
spydon enabled auto-merge (squash) July 9, 2026 13:53
spydon added a commit that referenced this pull request Jul 9, 2026
Introduces a new published supabase_common package and moves the
non-breaking shared/duplicated code into it:

- ToSnakeCase enum extension (was duplicated in gotrue and storage_client)
- Platform detection (was duplicated in supabase and supabase_flutter,
  keeping the extra isRunningInFlutterTest flag)
- buildClientInfoHeader for the X-Client-Info header (simple and
  platform-aware forms) used by all client packages
- isSuccessStatusCode 2xx helper
- FetchOptions (was duplicated internally in gotrue and storage_client)
- Base64Url, PKCE and uuid helpers (moved out of gotrue, also fixing an
  intra-gotrue duplication in jwt.dart)
- A unified ReplaySubject replacing gotrue's _ReplaySubject and
  supabase's _BehaviorSubject
- The in-house retry helper (was duplicated in gotrue and storage_client
  by #1571)

supabase_common is excluded from the SDK compliance public-API scan via
.sdk-parse-ignore: its symbols are consumed across packages and so cannot
be marked @internal without tripping invalid_use_of_internal_member.

Refs #1572
@spydon
spydon merged commit b81d212 into main Jul 9, 2026
31 checks passed
@spydon
spydon deleted the refactor/inline-retry branch July 9, 2026 13:58
spydon added a commit that referenced this pull request Jul 9, 2026
Introduces a new published supabase_common package and moves the
non-breaking shared/duplicated code into it:

- ToSnakeCase enum extension (was duplicated in gotrue and storage_client)
- Platform detection (was duplicated in supabase and supabase_flutter,
  keeping the extra isRunningInFlutterTest flag)
- buildClientInfoHeader for the X-Client-Info header (simple and
  platform-aware forms) used by all client packages
- isSuccessStatusCode 2xx helper
- FetchOptions (was duplicated internally in gotrue and storage_client)
- Base64Url, PKCE and uuid helpers (moved out of gotrue, also fixing an
  intra-gotrue duplication in jwt.dart)
- A unified ReplaySubject replacing gotrue's _ReplaySubject and
  supabase's _BehaviorSubject
- The in-house retry helper (was duplicated in gotrue and storage_client
  by #1571)

supabase_common is excluded from the SDK compliance public-API scan via
.sdk-parse-ignore: its symbols are consumed across packages and so cannot
be marked @internal without tripping invalid_use_of_internal_member.

Refs #1572
spydon added a commit that referenced this pull request Jul 9, 2026
Introduces a new published supabase_common package and moves the
non-breaking shared/duplicated code into it:

- ToSnakeCase enum extension (was duplicated in gotrue and storage_client)
- Platform detection (was duplicated in supabase and supabase_flutter,
  keeping the extra isRunningInFlutterTest flag)
- buildClientInfoHeader for the X-Client-Info header (simple and
  platform-aware forms) used by all client packages
- isSuccessStatusCode 2xx helper
- FetchOptions (was duplicated internally in gotrue and storage_client)
- Base64Url, PKCE and uuid helpers (moved out of gotrue, also fixing an
  intra-gotrue duplication in jwt.dart)
- A unified ReplaySubject replacing gotrue's _ReplaySubject and
  supabase's _BehaviorSubject
- The in-house retry helper (was duplicated in gotrue and storage_client
  by #1571)

supabase_common is excluded from the SDK compliance public-API scan via
.sdk-parse-ignore: its symbols are consumed across packages and so cannot
be marked @internal without tripping invalid_use_of_internal_member.

Refs #1572
spydon added a commit that referenced this pull request Jul 9, 2026
## What

Introduces a new published `supabase_common` package and moves the
**non-breaking** shared/duplicated code from #1572 into it.

**Stacked:** `main` ← #1569 (drop rxdart) ← #1571 (drop retry, in-house
helper) ← **this PR**.

> [!NOTE]
> Review/merge in stack order. Retarget this PR's base as each parent
merges (→ `refactor/inline-retry`, then `refactor/supabase-drop-rxdart`,
then `main`).

## Moved into `supabase_common`

| Item | Was |
|------|-----|
| `ToSnakeCase` enum extension | duplicated (byte-for-byte) in `gotrue`
+ `storage_client` |
| Platform detection (`platform_io`/`platform_stub`) | duplicated in
`supabase` + `supabase_flutter` (kept the extra
`isRunningInFlutterTest`) |
| `buildClientInfoHeader` (`X-Client-Info`) | built in all 7 client
packages (simple + platform-aware forms) |
| `isSuccessStatusCode` (2xx) | inlined/duplicated in `gotrue`,
`storage_client`, `postgrest`, `functions_client` |
| `FetchOptions` | duplicated internally in `gotrue` + `storage_client`
|
| `Base64Url` / PKCE / uuid helpers | `gotrue`-only; also fixes an
intra-`gotrue` duplication in `jwt.dart` |
| `ReplaySubject` | unifies gotrue's `_ReplaySubject` and supabase's
`_BehaviorSubject` |
| `retry` / `RetryOptions` helper | the in-house copy #1571 added to
`gotrue` + `storage_client` (identical); `@internal` dropped since it is
now used across packages |

## Not included

- **Tier 3** (shared exception base, HTTP fetch wrappers, `RetryTimer`)
— breaking, tracked under v3 (#1278).

## Notes

- `supabase_common` is an internal, published package (client packages
cannot depend on an unpublished local package). Its README flags it as
internal with breaking changes expected.
- Registered in the workspace, `test.yml` (`DART_PACKAGES` + Coveralls
carryforward), and `release-pana.yml`.
- No public API changes: every moved symbol was either internal or
re-exported so consumers importing from the client packages are
unaffected.

## Verification

- `dart analyze` clean across the whole workspace.
- `supabase_common` unit tests pass (ToSnakeCase, client-info header,
isSuccessStatusCode, Base64Url, PKCE, uuid, ReplaySubject
sync/async/replay/hooks/addStream, retry).
- `gotrue` (constants/helper), `functions_client` (full suite), and
`supabase` (utilities) tests pass locally. Backend-dependent suites run
in CI.

Refs #1572
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