Skip to content

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 into
mainfrom
lukasklingsbo/sdk-2351-refactoryet_another_json_isolate-drop-initialize-align-web
Oct 23, 2026
Merged

spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2351-refactoryet_another_json_isolate-drop-initialize-align-web

Conversation

@spydon

@spydon spydon commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Resolves SDK-2351.

Changes

initialize() is removed

It 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 in postgrest, 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

  • The web constructor is no longer const, and it exposes debugName like the IO one.
  • On web, dispose() now makes later calls throw a StateError, as IO already did.
  • Web encode awaited before encoding, so a caller could mutate the value before it was read. That broke the AsyncJsonCodec contract. 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 isolate

encode makes one pass over the value on the calling isolate. It replaces objects that are not JSON values with the result of their toJson() 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, and toJson runs 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 jsonEncode throws exactly the error it always did, without an isolate spawn. Values that cannot be encoded include a toJson that 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 a RemoteError when 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 its toJson methods run there.

The fallback to inline encoding for values that cannot be sent to another isolate stays. It is now only reachable through custom List or Map implementations, and has a test for that case.

Trade-off to note: running toJson on the calling isolate means visiting the whole payload there, where the old size estimate stopped after 64 KiB. Handing a payload to Isolate.run already copied all of it on the calling isolate, so this walk adds less than it seems. Lists and maps containing toJson objects 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 chrome for yet_another_json_isolate. The IO-only file is @TestOn('vm') and skips itself.

Tests

  • toJson is 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.
  • The original structure is left untouched. Error cases still throw JsonUnsupportedObjectError: toJson throwing, an unencodable toJson result, non-string keys, and NaN.
  • Every operation throws after dispose(), dispose() can be called twice, and debugName is exposed. These run on both VM and Chrome.
  • encode consumes the value before the caller can mutate it.
  • A large custom Map that holds a ReceivePort is encoded inline.
  • An unencodable value whose error cannot be sent between isolates throws JsonUnsupportedObjectError with the original cause. This test fails against the previous implementation, which threw a RemoteError.
  • A structure 600 levels deep encodes correctly, and a cyclic one throws JsonCyclicError.

… IO behavior, and keep small toJson objects off the isolate
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 6083d66 and 205dcdb.

📒 Files selected for processing: 16
  • .github/workflows/test.yml
  • MIGRATION.md
  • packages/postgrest/lib/src/postgrest.dart
  • packages/supabase/lib/src/supabase_client.dart
  • packages/supabase/test/client_test.dart
  • packages/supabase_functions/lib/src/functions_client.dart
  • packages/yet_another_json_isolate/README.md
  • packages/yet_another_json_isolate/benchmark/yet_another_json_isolate_benchmark.dart
  • packages/yet_another_json_isolate/example/yet_another_json_isolate_example.dart
  • packages/yet_another_json_isolate/lib/src/json_isolate_io.dart
  • packages/yet_another_json_isolate/lib/src/json_isolate_web.dart
  • packages/yet_another_json_isolate/lib/yet_another_json_isolate.dart
  • packages/yet_another_json_isolate/pubspec.yaml
  • packages/yet_another_json_isolate/test/yet_another_json_isolate_io_test.dart
  • packages/yet_another_json_isolate/test/yet_another_json_isolate_test.dart
  • sdk-compliance.yaml
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@spydon
spydon merged commit 69474c1 into main Oct 23, 2026
46 checks passed
@spydon
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 -->
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.

1 participant