Skip to content

test(supabase): verify shared YAJsonIsolate instance across sub-clients#1345

Merged
grdsdev merged 2 commits intomainfrom
grdsdev/share-yajson-isolate
Apr 7, 2026
Merged

test(supabase): verify shared YAJsonIsolate instance across sub-clients#1345
grdsdev merged 2 commits intomainfrom
grdsdev/share-yajson-isolate

Conversation

@grdsdev
Copy link
Copy Markdown
Contributor

@grdsdev grdsdev commented Apr 2, 2026

Summary

  • Adds tests that explicitly verify SupabaseClient shares a single YAJsonIsolate across PostgrestClient and FunctionsClient (the implementation was already correct)
  • Verifies that an injected isolate is properly disposed when SupabaseClient.dispose() is called
  • Verifies that creating a SupabaseClient without a custom isolate results in correct shared lifecycle management

Root Cause Analysis

The issue reported that each client was creating its own YAJsonIsolate. Reviewing the current code:

  • supabase_client.dart:142 — creates _isolate = isolate ?? (YAJsonIsolate()..initialize())
  • supabase_client.dart:306 — passes isolate: _isolate to PostgrestClient
  • supabase_client.dart:316 — passes isolate: _isolate to FunctionsClient
  • supabase_client.dart:277 — disposes _isolate in dispose()

The implementation was already correct. This PR adds test coverage to lock in that behavior.

Testing

  • 2 new tests added in packages/supabase/test/client_test.dart
  • All 35 tests pass

Acceptance Criteria

  • Single YAJsonIsolate created per SupabaseClient instance (already implemented)
  • SupabaseClient.dispose() cleans up the shared isolate (already implemented)
  • All existing tests pass
  • No public API breakage

Closes: SDK-815


🤖 Generated with Claude Code

Adds tests to explicitly verify that SupabaseClient shares a single
YAJsonIsolate instance with PostgrestClient and FunctionsClient (rather
than each spawning their own isolate), and that dispose() correctly
cleans up the shared isolate.

Linear: SDK-815

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Vinzent03
Copy link
Copy Markdown
Collaborator

Actually, I would disagree with the current behavior. If you pass a custom isolate to the supabase client, I don't think it should dispose it. Passing a custom one is a way to make isolate handling between many clients more efficient, which is not possible if it gets disposed by the client. The sublibraries like functions and postgrest only dispose their own isolate. While it is needed there, because the isolate typically comes from the supabase client, I think this design should be applied to the supabase client as well.

When a custom YAJsonIsolate is passed to SupabaseClient, the caller owns
its lifecycle and may be sharing it across multiple clients. Disposing it
from SupabaseClient.dispose() breaks that pattern.

Mirrors the _hasCustomIsolate guard already used in PostgrestClient and
FunctionsClient.

Linear: SDK-815

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@grdsdev grdsdev merged commit 22a587d into main Apr 7, 2026
12 checks passed
@grdsdev grdsdev deleted the grdsdev/share-yajson-isolate branch April 7, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants