Repository navigation
refactor(yet_another_json_isolate)!: drop initialize(), align web and IO behavior, and keep small toJson objects off the isolate - #2041
Merged
spydon merged 2 commits intoOct 23, 2026
Conversation
… IO behavior, and keep small toJson objects off the isolate
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 23 seconds. View limit details
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. Comment |
…e pass and encode unencodable values inline
spydon
deleted the
lukasklingsbo/sdk-2351-refactoryet_another_json_isolate-drop-initialize-align-web
branch
October 23, 2026 08:41
spydon
added a commit
that referenced
this pull request
Oct 23, 2026
…the v3 code (#2039) Fixes [SDK-2362](https://linear.app/supabase/issue/SDK-2362/docs-fix-readme-migrationmd-and-skill-content-that-disagrees-with-the). The READMEs, MIGRATION.md and the package skills contained code that throws, handlers that never fire, and breaking changes the guide did not mention. This PR fixes each finding of the ticket. Each one was checked against the current code first. ## Code that fails as written - **`SupabaseClient(url, key)` throws.** The first example in the `supabase` README and the two MIGRATION.md "After" snippets (`runWithClient` and `jsonCodec`) now pass `authOptions: AuthClientOptions(asyncStorage: MemoryAuthAsyncStorage())`. The README also says why the storage is needed. - **Realtime error handler.** The realtime skill told readers to use `onError` on `onStatusChange` to see a declined join. That handler never fires, because the failure arrives as a `channelError` status with `change.error`. The snippet now switches on the status. - **`onAuthStateChange` without `onError`.** The `supabase_flutter` README, the idioms skill and the auth-setup skill now pass `onError`. Each says that a token refresh that fails while offline is an error on the stream. The auth-setup skill no longer calls `onError` optional. - **supabase_test snippets relied on injected imports.** Of the two options in the ticket, I made the checker stop injecting imports (details below). The whole-library snippets now import `package:supabase/supabase.dart` and the generated schema themselves, as `package:my_app/supabase_schema.g.dart`. The text says to replace `my_app` with the package name. - **`..initialize()`.** Removed from the MIGRATION.md "After" snippet, matching #2041, which removed the method (SDK-2351). The snippet now keeps the codec in a variable and disposes it with the client, because a codec passed in belongs to the caller. ## Missing from MIGRATION.md - New section **Storage uploads return an `UploadResponse`**. It covers which field replaces the old `String`: `fullPath` for the uploads, `path` for the signed URL uploads, as v2 returned them. - New section **`exists()` only returns `false` for a missing object**. A missing bucket or an invalid token now throws instead of returning `false`. - Both sections, plus the existing **Broadcasts no longer fall back to the REST API**, are now listed under "Changes the compiler will not catch". - The realtime exceptions table no longer mentions `send()` or `ChannelEvent.fromValue`, which are not exported. It now names `track()` and `untrack()`, the public calls that throw a `StateError` before `subscribe()`. ## Out of date or misleading - **JSON path filters.** MIGRATION.md and the migrate-v3 skill now use `Books.metadata.jsonText('edition').eq('first')` instead of `PostgrestFilter.raw`. - **Typed embed gap.** MIGRATION.md's embedded selects section and the migrate-v3 skill's "`from()` remains only for" list now say that the typed API does not support filtering inside an embed or `!inner` yet (SDK-2247), and show the `from()` form to use until then. - **Deep links.** The `supabase_flutter` README now lists Linux and states which parameters the default rule treats as an auth callback. It also shows a `detectSessionInUriPredicate` that checks the same five parameters as the default rule, in the query and the fragment, and on native platforms also requires the redirect host. On the web the predicate receives the page URL, so the host is not checked there. It mentions `detectSessionInUri: false` too. - **supabase_lints.** The README warns that the package is the monorepo's own lint configuration and that its rules get stricter without a major version. It installs the package with `dart pub add dev:supabase_lints` instead of `any`, so the constraint never goes stale in the README. It also lists the strict rules: 80 columns, strict raw types and unawaited futures. It also explains that the DCM rules, including the `dart:io` ban at error level, apply only under `dcm analyze`, a separate licensed tool. The dot shorthand comment in `analysis_options.yaml` now says the real reason: shorthands need Dart 3.10, and the packages support 3.9.0. - **supabase_common.** The README now includes realtime and iceberg in its package and exception lists. - **supabase_functions.** The README now has a usage section, through `supabase.functions` and standalone, and describes how `data` is decoded for each content type. It notes that a legacy JWT anon key also needs `Authorization: Bearer <key>` for a function that verifies the JWT. The example sends the `apikey` header instead of `Authorization: Bearer <key>`, which fails with `sb_publishable_` keys, and now disposes the client. This covers the README and example item of SDK-2350. The API changes in that ticket are not part of this PR. ## Snippet checker `scripts/check_skill_snippets.dart` now: - **checks package READMEs** as well as skills. Many README snippets did not compile because of missing schema imports, and nothing checked them before. - **stops injecting imports into whole libraries.** That applies to `dart file` and `dart test-file` blocks, so they show the imports a user needs. An import that ends in `supabase_schema.g.dart` is pointed at the typegen golden. Function and test bodies still get their imports injected, since a body cannot hold imports. The harness needs no new dependencies, because every workspace package resolves through the shared package config. Six `supabase_flutter` README snippets use third-party packages: Apple, Google and Facebook sign in, `flutter_secure_storage`, Sentry and OpenTelemetry. They are now `dart skip`, so the harness does not pull those packages into the workspace. No README snippet was checked before, so this is not lost coverage. MIGRATION.md is still not checked: the skills only link it, and many of its blocks mix v2 and v3 code. AGENTS.md describes the new rules. ## Tests - `supabase_realtime`: a declined join is a `channelError` status carrying a `RealtimeException`, and the stream emits no error. This is the behavior the realtime skill now teaches. - `supabase_auth`: a refresh that gets no response is an `AuthRetryableFetchException` error on `onAuthStateChange`. This is the reason every listener now passes `onError`. - `melos run check-skill-snippets`: 103 snippets compile and the 24 test snippets pass. ## Left as is - The `onAuthStateChange` "After" snippets in MIGRATION.md's `AuthState` section still have no `onError`. They show the switch from `event` checks to sealed subtypes, and v2 listeners needed `onError` just as much, so it is not a migration step. ## Open decision - **supabase_lints:** the ticket offers two ways to fix the README, saying the package is internal-only or documenting its rules with a version constraint. I did both: a warning that it is the monorepo's own configuration, plus the rules and a `dart pub add` install. If it should be internal-only, the usage section can go. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Documentation** * Expanded Dart and Flutter guides with clearer setup instructions, generated-schema examples, and typed JSON-path filtering guidance. * Clarified that auth-state streams can report token-refresh and exchange errors, and that realtime join failures appear as channel-status changes. * Added Edge Functions usage, response, and error guidance, plus updates on storage behavior, deep-link handling, and typed-query limitations. * Updated migration and package guidance to reflect current API behavior and configuration requirements. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves SDK-2351.
Changes
initialize()is removedIt was a no-op kept for backwards compatibility that still asserted on a second call. It is gone from both implementations, from
sdk-compliance.yaml, and from the callers inpostgrest,supabase_functions,supabase, the benchmark and the example. The MIGRATION.md snippet no longer calls it, and the JSON codec section says to delete the call.Web and IO behave the same
const, and it exposesdebugNamelike the IO one.dispose()now makes later calls throw aStateError, as IO already did.encodeawaited before encoding, so a caller could mutate the value before it was read. That broke theAsyncJsonCodeccontract. It now encodes synchronously, like the IO inline path.Web runs inline, and the docs say so
The library doc, README, pubspec description and web class doc now state that on web every payload is processed inline on the main thread.
toJson()runs on the calling isolateencodemakes one pass over the value on the calling isolate. It replaces objects that are not JSON values with the result of theirtoJson()method and estimates the encoded size at the same time, replacing the separate size walk. A small model object is now encoded inline instead of spawning an isolate, andtoJsonruns on the calling isolate once for each place the object appears, so its side effects happen where the caller expects them. Lists and maps are only copied when something inside them is replaced.A value that cannot be encoded is encoded inline, so
jsonEncodethrows exactly the error it always did, without an isolate spawn. Values that cannot be encoded include atoJsonthat throws or returns an unencodable value, a map key that is not a string, and a number that is not finite. Previously such an error came back as aRemoteErrorwhen it held something that could not be sent between isolates. A structure nested deeper than 512 levels, which includes cyclic ones, skips the conversion and goes to an isolate as before, so itstoJsonmethods run there.The fallback to inline encoding for values that cannot be sent to another isolate stays. It is now only reachable through custom
ListorMapimplementations, and has a test for that case.Trade-off to note: running
toJsonon the calling isolate means visiting the whole payload there, where the old size estimate stopped after 64 KiB. Handing a payload toIsolate.runalready copied all of it on the calling isolate, so this walk adds less than it seems. Lists and maps containingtoJsonobjects are also copied on the calling isolate.CI runs the package on Chrome
The shared test file now covers the web variant, so the Dart test job runs
dart test -p chromeforyet_another_json_isolate. The IO-only file is@TestOn('vm')and skips itself.Tests
toJsonis called once on the calling isolate for a top-level object, for objects nested in lists and maps, for a large object, and for an object inside a large structure. The four side-effect tests fail against the previous implementation.JsonUnsupportedObjectError:toJsonthrowing, an unencodabletoJsonresult, non-string keys, and NaN.dispose(),dispose()can be called twice, anddebugNameis exposed. These run on both VM and Chrome.encodeconsumes the value before the caller can mutate it.Mapthat holds aReceivePortis encoded inline.JsonUnsupportedObjectErrorwith the original cause. This test fails against the previous implementation, which threw aRemoteError.JsonCyclicError.