Repository navigation
Fix native composer lag with revision-gated updates #3574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9a0c725
Fix composer lag with revision-gated native updates
juliusmarminge 36e16bc
Make composer controlled updates revision-aware
juliusmarminge 276cbb6
Fix native composer revision gating
juliusmarminge 12bfd15
Reduce native composer echo lag
juliusmarminge 22ca1f8
Stop trimming composer snapshots in render effect
juliusmarminge 1d0a86a
Prune acknowledged native composer events
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { describe, expect, it } from "@effect/vitest"; | ||
|
|
||
| import { | ||
| acknowledgeComposerNativeEvent, | ||
| isComposerNativeEcho, | ||
| resolveComposerControlledEventCount, | ||
| } from "./composerEditorRevision"; | ||
|
|
||
| describe("acknowledgeComposerNativeEvent", () => { | ||
| it("advances to newer native text revisions", () => { | ||
| expect(acknowledgeComposerNativeEvent(4, 5)).toBe(5); | ||
| }); | ||
|
|
||
| it("accepts a duplicate event from the current native revision", () => { | ||
| expect(acknowledgeComposerNativeEvent(5, 5)).toBe(5); | ||
| }); | ||
|
|
||
| it("rejects events older than the latest native text revision", () => { | ||
| expect(acknowledgeComposerNativeEvent(5, 4)).toBeNull(); | ||
| }); | ||
|
|
||
| it("rejects malformed revision counters", () => { | ||
| expect(acknowledgeComposerNativeEvent(5, Number.NaN)).toBeNull(); | ||
| expect(acknowledgeComposerNativeEvent(5, 5.5)).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("isComposerNativeEcho", () => { | ||
| const snapshots = [{ eventCount: 3, value: "native", selection: { start: 6, end: 6 } }]; | ||
|
|
||
| it("matches the exact native text revision and selection", () => { | ||
| expect(isComposerNativeEcho("native", { start: 6, end: 6 }, 3, snapshots)).toBe(true); | ||
| }); | ||
|
|
||
| it("does not claim parent-driven selection or repeated-text updates", () => { | ||
| expect(isComposerNativeEcho("native", { start: 2, end: 2 }, 3, snapshots)).toBe(false); | ||
| expect(isComposerNativeEcho("native", { start: 6, end: 6 }, 4, snapshots)).toBe(false); | ||
| expect(isComposerNativeEcho("parent edit", { start: 6, end: 6 }, 3, snapshots)).toBe(false); | ||
| }); | ||
|
|
||
| it("matches value and revision when selection is uncontrolled", () => { | ||
| expect(isComposerNativeEcho("native", null, 3, snapshots)).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe("resolveComposerControlledEventCount", () => { | ||
| const snapshots = [ | ||
| { eventCount: 0, value: "", selection: { start: 0, end: 0 } }, | ||
| { eventCount: 2, value: "a", selection: { start: 1, end: 1 } }, | ||
| { eventCount: 4, value: "ab", selection: { start: 2, end: 2 } }, | ||
| ]; | ||
|
|
||
| it("tags a delayed parent value with the native revision that produced it", () => { | ||
| expect(resolveComposerControlledEventCount("a", { start: 1, end: 1 }, 4, snapshots)).toBe(2); | ||
| }); | ||
|
|
||
| it("does not acknowledge the pre-edit parent value as the latest revision", () => { | ||
| expect(resolveComposerControlledEventCount("", { start: 0, end: 0 }, 4, snapshots)).toBe(0); | ||
| }); | ||
|
|
||
| it("acknowledges the latest native value at the latest revision", () => { | ||
| expect(resolveComposerControlledEventCount("ab", { start: 2, end: 2 }, 4, snapshots)).toBe(4); | ||
| }); | ||
|
|
||
| it("allows an unmatched parent-driven edit at the latest native revision", () => { | ||
| expect(resolveComposerControlledEventCount("/plan ", { start: 6, end: 6 }, 4, snapshots)).toBe( | ||
| 4, | ||
| ); | ||
| }); | ||
|
|
||
| it("uses the newest revision when selection events repeat the same value", () => { | ||
| expect( | ||
| resolveComposerControlledEventCount("ab", { start: 1, end: 1 }, 5, [ | ||
| ...snapshots, | ||
| { eventCount: 5, value: "ab", selection: { start: 1, end: 1 } }, | ||
| ]), | ||
| ).toBe(5); | ||
| }); | ||
|
|
||
| it("keeps a stale selection paired with current text behind the native revision", () => { | ||
| expect(resolveComposerControlledEventCount("ab", { start: 1, end: 1 }, 4, snapshots)).toBe(3); | ||
| }); | ||
|
|
||
| it("does not control selection when no selection prop is provided", () => { | ||
| expect(resolveComposerControlledEventCount("ab", null, 4, snapshots)).toBe(4); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium
ios/T3ComposerEditorView.swift:362setControlledDocumentJsonguards withdocument.mostRecentEventCount >= nativeEventCount, which accepts payloads where the two counts are equal. After a native edit emits eventN(incrementingnativeEventCounttoN), React updatesmostRecentEventCounttoNbut may not have produced the updatedvalueyet (e.g. async/debouncedonChangeText). The staledocument.valuetagged withNpasses the>=guard andapplyControlledDocumentoverwrites the newer native text, silently dropping the user's edit. Consider tightening the gate so equal-count payloads are rejected, or otherwise ensuring the document value is only applied when React has confirmed it reflects the latest native event.🚀 Reply "fix it for me" or copy this AI Prompt for your agent: