feat(entities): auto-refetch when realtime broadcast is truncated#165
Closed
theunreal wants to merge 2 commits into
Closed
feat(entities): auto-refetch when realtime broadcast is truncated#165theunreal wants to merge 2 commits into
theunreal wants to merge 2 commits into
Conversation
Server-side BASE-40236 slims oversize entity broadcasts to fit under the
Redis pubsub cap, signaling the slim with `_truncated: true` on the event
data. Customer apps that render the truncated fields would otherwise
display placeholder text until refresh.
The SDK now detects `_truncated` in `entities.X.subscribe` and transparently
refetches the full record over HTTP before invoking the user callback, so
deployed customer code keeps working without changes. Concurrent subscribers
in the same browser fan out to a single HTTP call via an in-flight
debounce keyed by `${entityName}:${id}:${timestamp}`. On refetch failure
the SDK falls through with the partial payload and logs a warning, so the
failure mode is no worse than today's drop-and-stale.
Delete events skip refetch — the record no longer exists.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The wire flag is set only when the server falls back to a stub payload
because the original record was too big for realtime transport. Calling
it "truncated" was misleading — we don't truncate fields in that path,
we replace the whole payload with `{id, _oversize: true}`. `_oversize`
names the actual cause and tells the SDK why a refetch is needed.
Coordinated with the matching backend rename.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Collaborator
Author
|
Superseded by #167 — recreated from a base-repo branch so that secrets/OIDC-dependent checks (claude-review, claude-docs-draft, publish-preview) can run. |
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.
Why
Realtime entity broadcasts have a transport size limit. Records with very large fields (e.g. base64-encoded media, long markdown) can exceed the limit and get dropped — subscribers see stale state until refresh.
The Base44 backend now slims oversize broadcasts to fit under the limit and signals it with
_oversize: trueon the eventdata. Without this SDK change, customer apps that read the truncated fields would render placeholder text until refresh.This change makes the recovery transparent: the SDK detects
_oversizeand refetches the full record over HTTP before invoking the user callback. Existing app code keeps working with no changes.What
In
entities.X.subscribe(callback):event.type !== "delete"andevent.data._oversize, call the entity GET endpoint and replaceevent.datawith the response.(entityName, id, timestamp)via an in-flightMap<string, Promise<T>>. The cache entry clears 5 s after the promise settles so late subscribers can still piggy-back.Wire contract is preserved: the server always emits
dataas an object containing at minimumid, so older SDK clients that don't know about_oversizecontinue to receive a structurally valid event.Tests
tests/unit/entities-subscribe.test.ts— 5 new tests, all 11 pass:data._oversizeis true_oversizeis set_oversizeis absent(entity, id, timestamp)— only one HTTP callFull suite: 158 / 158 pass. `npm run lint` and `npm run build` clean.
Backward compatibility
_oversize. Pure passthrough._oversizeflag never appears, so this code path is dormant.Versioning
Recommend a minor bump (
0.8.x → 0.9.0) since this is additive behavior.