From 70a8afb147eb049153450fec4fa35171ba7a42ca Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 00:55:11 +0000 Subject: [PATCH 01/10] Send a kept row as reuse markers where the phone already holds it CachedRow sent its kept node in full every frame, so with EDGE's subtree reuse on, a list whose rows are kept still went out whole whenever any row changed. It now builds a row against no hashes, so the kept node is always whole, and sends it the way EDGE's own walk sends a node: a reuse marker for any part the phone holds by id and hash, the rest in full. Nothing changes while a screen sets $forceFullFrames, because the hashes start empty every frame there. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/CachedRow.php | 65 ++++++++++------ tests/Unit/Devnull/CachedRowTest.php | 106 +++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 21 deletions(-) create mode 100644 tests/Unit/Devnull/CachedRowTest.php diff --git a/app/Devnull/CachedRow.php b/app/Devnull/CachedRow.php index 7f337124..c9d59a16 100644 --- a/app/Devnull/CachedRow.php +++ b/app/Devnull/CachedRow.php @@ -19,6 +19,11 @@ * when none of its ids is already in the frame. Otherwise, and for a row with no * keyed parent, whose ids would come from the frame's running count, the row * makes its node afresh. + * + * With EDGE's subtree reuse on, the row goes out as EDGE sends any node: a part + * of it the phone already holds, by id and content hash, is sent as a reuse + * marker and taken from the phone's last tree. So a row that hasn't changed + * costs the frame one marker, and a starred one only the parts the star touched. */ final class CachedRow extends Element { @@ -65,45 +70,63 @@ public function toArray( && array_intersect_key($this->nodeIds, $emittedIds) === []) { $emittedIds += $this->nodeIds; - return $this->node; + return self::send($this->node, $lastNodeHashes); } - $node = $this->row->toArray($registry, $nextId, $parentKeyPath, $indexInParent, $emittedIds, $lastNodeHashes); + // Built against no hashes, the row's node is whole, so it can be kept and sent again in any later frame. + $sentNothing = []; + $node = $this->row->toArray($registry, $nextId, $parentKeyPath, $indexInParent, $emittedIds, $sentNothing); $ids = []; + self::collectIds($node, $ids); + + $this->node = $node; + $this->nodePlace = $place; + $this->nodeRegistry = $registry; + $this->nodeIds = $ids; - if (self::collectFullIds($node, $ids)) { - $this->node = $node; - $this->nodePlace = $place; - $this->nodeRegistry = $registry; - $this->nodeIds = $ids; - } else { - $this->node = null; + return self::send($node, $lastNodeHashes); + } + + /** + * A node as this frame sends it: a reuse marker where the phone already holds + * it, by its id and hash, as EDGE's own walk does, and otherwise in full, its + * children each sent the same way, and its hash noted as what the phone holds + * next. With subtree reuse off the hashes start empty every frame, so every + * node goes in full. + * + * @param array $node + * @param array $lastNodeHashes + * @return array + */ + private static function send(array $node, array &$lastNodeHashes): array + { + if (($lastNodeHashes[$node['id']] ?? null) === $node['_hash']) { + return ['id' => $node['id'], 'type' => $node['type'], 'flags' => 1, '_hash' => $node['_hash']]; + } + + $lastNodeHashes[$node['id']] = $node['_hash']; + + if (isset($node['children'])) { + foreach ($node['children'] as $i => $child) { + $node['children'][$i] = self::send($child, $lastNodeHashes); + } } return $node; } /** - * Collects a node's ids, and its children's. False when any of them is a - * reuse marker, which only stands for a node the phone got in an earlier frame. + * Collects a node's ids, and its children's. * * @param array $node * @param array $ids */ - private static function collectFullIds(array $node, array &$ids): bool + private static function collectIds(array $node, array &$ids): void { - if ((($node['flags'] ?? 0) & 1) !== 0) { - return false; - } - $ids[$node['id']] = true; foreach ($node['children'] ?? [] as $child) { - if (! self::collectFullIds($child, $ids)) { - return false; - } + self::collectIds($child, $ids); } - - return true; } } diff --git a/tests/Unit/Devnull/CachedRowTest.php b/tests/Unit/Devnull/CachedRowTest.php new file mode 100644 index 00000000..531ecf59 --- /dev/null +++ b/tests/Unit/Devnull/CachedRowTest.php @@ -0,0 +1,106 @@ + $hashes + * @return array + */ +function cachedRowFrame(Element $list, CallbackRegistry $registry, array &$hashes): array +{ + $nextId = 1; + $emitted = []; + $frame = $list->toArray($registry, $nextId, '', 0, $emitted, $hashes); + $hashes = array_intersect_key($hashes, $emitted); + + return $frame; +} + +/** + * Each node of a frame, by id, and whether it went as a reuse marker. + * + * @param array $node + * @return array + */ +function cachedRowMarkers(array $node): array +{ + $markers = [$node['id'] => (($node['flags'] ?? 0) & 1) === 1]; + + foreach ($node['children'] ?? [] as $child) { + $markers += cachedRowMarkers($child); + } + + return $markers; +} + +function keptRow(string $key, string $body, string $time = '5m'): CachedRow +{ + return new CachedRow(Column::make(Text::make($body), Text::make($time))->key($key)); +} + +it('sends a kept row the phone already holds as a reuse marker', function () { + $registry = new CallbackRegistry; + $hashes = []; + $rows = [keptRow('c1', 'First'), keptRow('c2', 'Second')]; + + $first = cachedRowFrame(Column::make(...$rows)->key('list'), $registry, $hashes); + expect(array_filter(cachedRowMarkers($first)))->toBe([]); + + // A row goes on top: the list goes again, the two rows under it as markers. + $second = cachedRowFrame(Column::make(keptRow('c3', 'Third'), ...$rows)->key('list'), $registry, $hashes); + [$new, $c1, $c2] = $second['children']; + + expect($second['flags'] ?? 0)->toBe(0) + ->and($new['flags'] ?? 0)->toBe(0) + ->and($c1)->toBe(['id' => $first['children'][0]['id'], 'type' => 'column', 'flags' => 1, '_hash' => $first['children'][0]['_hash']]) + ->and($c2['flags'])->toBe(1); +}); + +it('sends only the parts of a row that changed', function () { + $registry = new CallbackRegistry; + $hashes = []; + + $first = cachedRowFrame(Column::make(keptRow('c1', 'First', '5m'))->key('list'), $registry, $hashes); + $second = cachedRowFrame(Column::make(keptRow('c1', 'First', '6m'))->key('list'), $registry, $hashes); + [$body, $time] = $second['children'][0]['children']; + + expect($second['children'][0]['flags'] ?? 0)->toBe(0) + ->and($body['flags'])->toBe(1) + ->and($body['id'])->toBe($first['children'][0]['children'][0]['id']) + ->and($time['flags'] ?? 0)->toBe(0) + ->and($time['props'] ?? null)->not->toBeNull(); +}); + +it('sends a kept row in full when the phone has lost it, and as a marker the frame after', function () { + $registry = new CallbackRegistry; + $hashes = []; + $list = Column::make(keptRow('c1', 'First'), keptRow('c2', 'Second'))->key('list'); + + $first = cachedRowFrame($list, $registry, $hashes); + + // EDGE drops every hash when the phone may have lost its tree, as on its heartbeat. + $hashes = []; + expect(cachedRowFrame($list, $registry, $hashes))->toBe($first); + + $third = cachedRowFrame($list, $registry, $hashes); + expect($third['flags'])->toBe(1); +}); + +it('sends every frame in full with subtree reuse off', function () { + $registry = new CallbackRegistry; + $list = Column::make(keptRow('c1', 'First'))->key('list'); + + $throwaway = []; + $first = cachedRowFrame($list, $registry, $throwaway); + $throwaway = []; + + expect(cachedRowFrame($list, $registry, $throwaway))->toBe($first) + ->and(array_filter(cachedRowMarkers($first)))->toBe([]); +}); From da5cce705c2fb13b4026eb20780cb3b747e89124 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:12:49 +0000 Subject: [PATCH 02/10] Send only what changed on the Log The Log sent every frame in full because EDGE's subtree reuse could refer to rows the phone never got, which drew the list blank after a pull to refresh. That is fixed in nativephp/mobile by NativePHP/mobile-air#699: the reader parses every frame instead of dropping some, a row's id is part of its hash, and a reader that still can't build a frame asks PHP for a full one. With that, a star on a 60 commit Log sends about 9 KB instead of 530 KB. This needs that fix. On mobile-air 4.8.0 without it, the Log goes blank again, so the new test skips itself there. The test replays every frame the way the phone's reader does and checks the result against a full frame after each step: a star, a thread, the next page, new commits on top, back to the top, a delete from the middle, the pill, the image viewer and a swipe to another log and back. The other screens that set the flag no longer point at the Log's. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 9 +- app/NativeComponents/Conversation.php | 2 +- app/NativeComponents/Log.php | 8 -- app/NativeComponents/Notifications.php | 3 +- app/NativeComponents/Profile.php | 6 +- app/NativeComponents/Remotes.php | 2 +- app/NativeComponents/Starred.php | 2 +- tests/Feature/Screens/LogsTest.php | 9 +- tests/Feature/Screens/PartialFramesTest.php | 100 ++++++++++++++++++ tests/Pest.php | 107 ++++++++++++++++++++ 10 files changed, 224 insertions(+), 24 deletions(-) create mode 100644 tests/Feature/Screens/PartialFramesTest.php diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 5f285779..fff9317d 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -226,11 +226,10 @@ class CommitDetail extends NativeComponent private ?RowCache $replyRows = null; /** - * Every frame goes in full, as on the Log (see Log::$forceFullFrames). A - * tap on the reply field mounts the thread's scroll view again under a new - * key, and EDGE's subtree reuse sent its unchanged rows as references to - * nodes the phone dropped with the old one, so the thread went blank as - * you started typing. + * Every frame goes in full. A tap on the reply field mounts the thread's + * scroll view again under a new key, and EDGE's subtree reuse sent its + * unchanged rows as references to nodes the phone dropped with the old + * one, so the thread went blank as you started typing. */ protected bool $forceFullFrames = true; diff --git a/app/NativeComponents/Conversation.php b/app/NativeComponents/Conversation.php index 9324fb2c..25ffdef6 100644 --- a/app/NativeComponents/Conversation.php +++ b/app/NativeComponents/Conversation.php @@ -176,7 +176,7 @@ class Conversation extends NativeComponent public const int PinnedLines = 3; /** - * Every frame goes in full, as on the Log (see Log::$forceFullFrames): messages come in at the bottom and their + * Every frame goes in full: messages come in at the bottom and their * reactions change in place, which EDGE's subtree reuse would otherwise miss. */ protected bool $forceFullFrames = true; diff --git a/app/NativeComponents/Log.php b/app/NativeComponents/Log.php index 276688e9..19ec6ca5 100644 --- a/app/NativeComponents/Log.php +++ b/app/NativeComponents/Log.php @@ -114,14 +114,6 @@ class Log extends NativeComponent use TalksToDevnull; use WatchesForCalls; - /** - * Every frame goes in full. EDGE's subtree reuse sometimes refers to rows - * the phone never got once a list has grown or reordered, and the phone - * drops them, which drew the log blank under a pull to refresh. EDGE's own - * answer for a screen whose lists change often is to send it in full. - */ - protected bool $forceFullFrames = true; - public const array Logs = ['following', 'latest', 'trending']; /** diff --git a/app/NativeComponents/Notifications.php b/app/NativeComponents/Notifications.php index a96fb82e..48f495ab 100644 --- a/app/NativeComponents/Notifications.php +++ b/app/NativeComponents/Notifications.php @@ -59,7 +59,8 @@ class Notifications extends NativeComponent use WritesInBackground; /** - * Every frame goes in full, as on the Log (see Log::$forceFullFrames). + * Every frame goes in full. EDGE's subtree reuse could refer to rows the + * phone never got once the list had changed, which drew it blank. */ protected bool $forceFullFrames = true; diff --git a/app/NativeComponents/Profile.php b/app/NativeComponents/Profile.php index b82daf61..79456f37 100644 --- a/app/NativeComponents/Profile.php +++ b/app/NativeComponents/Profile.php @@ -83,9 +83,9 @@ class Profile extends NativeComponent use WatchesForCalls; /** - * Every frame goes in full, as on the Log (see Log::$forceFullFrames). A tab - * tapped again goes back to the top in a list with a new key and the same - * rows, which EDGE's subtree reuse would otherwise never send. + * Every frame goes in full. A tab tapped again goes back to the top in a + * list with a new key and the same rows, which EDGE's subtree reuse would + * otherwise never send. */ protected bool $forceFullFrames = true; diff --git a/app/NativeComponents/Remotes.php b/app/NativeComponents/Remotes.php index 9f15bbc5..a4176d3e 100644 --- a/app/NativeComponents/Remotes.php +++ b/app/NativeComponents/Remotes.php @@ -89,7 +89,7 @@ class Remotes extends NativeComponent public const string LeaveAlert = 'remotes-leave'; /** - * Every frame goes in full, as on the Log (see Log::$forceFullFrames), since a row moves to the top when it + * Every frame goes in full, since a row moves to the top when it * has a new message. */ protected bool $forceFullFrames = true; diff --git a/app/NativeComponents/Starred.php b/app/NativeComponents/Starred.php index 98fd4021..862de09d 100644 --- a/app/NativeComponents/Starred.php +++ b/app/NativeComponents/Starred.php @@ -47,7 +47,7 @@ class Starred extends NativeComponent use TalksToDevnull; /** - * Every frame goes in full, as on the Log (see Log::$forceFullFrames), since rows leave the list from the middle. + * Every frame goes in full, since rows leave the list from the middle. */ protected bool $forceFullFrames = true; diff --git a/tests/Feature/Screens/LogsTest.php b/tests/Feature/Screens/LogsTest.php index b072768d..18118c5a 100644 --- a/tests/Feature/Screens/LogsTest.php +++ b/tests/Feature/Screens/LogsTest.php @@ -355,13 +355,14 @@ function ada(): array ->and(nodeByRef($screen, 'commit-c1')['id'])->toBe($row); }); -it('sends the Log, Notifications, profiles and commit pages in full every frame, as EDGE advises for lists that change often', function () { +it('sends only what changed on the Log, and Notifications, profiles and commit pages in full every frame', function () { Http::fake(['devnull.test/*' => Http::response(pageJson([]))]); + $sendsInFull = fn (string $screen): bool => (fn (): bool => $this->forceFullFrames)->call(Native::test($screen)->instance()); - foreach ([Log::class, Notifications::class, Profile::class, CommitDetail::class] as $screen) { - $instance = Native::test($screen)->instance(); + expect($sendsInFull(Log::class))->toBeFalse(); - expect((fn (): bool => $this->forceFullFrames)->call($instance))->toBeTrue(); + foreach ([Notifications::class, Profile::class, CommitDetail::class] as $screen) { + expect($sendsInFull($screen))->toBeTrue(); } }); diff --git a/tests/Feature/Screens/PartialFramesTest.php b/tests/Feature/Screens/PartialFramesTest.php new file mode 100644 index 00000000..22e0fc2c --- /dev/null +++ b/tests/Feature/Screens/PartialFramesTest.php @@ -0,0 +1,100 @@ + 'http://devnull.test']); + signIn(); + + // Frozen, so a relative time can't move between the phone's frame and the full one it's checked against. + $this->freezeSecond(); +}); + +/** + * A page of the log's commits, newest first, from "{$prefix}{$first}" on. + * + * @return list> + */ +function partialFrameCommits(string $prefix, int $first, int $count): array +{ + return array_map(fn (int $n): array => commitJson([ + 'id' => "{$prefix}{$n}", + 'body' => "Commit {$prefix}{$n}", + // Ada's, but c7 is yours, so you can delete it. + 'author' => "{$prefix}{$n}" === 'c7' ? userJson() : userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada']), + // One with a photo, for the image viewer. + ...($n === 5 ? ['images' => [['id' => "{$prefix}{$n}-i1", 'url' => "https://images.example.com/{$prefix}{$n}.jpg", 'width' => 1200, 'height' => 900, 'description' => null]]] : []), + ]), range($first, $first + $count - 1)); +} + +it('keeps the Log on the phone in step through refreshes, pages, threads, swipes and deletes', function () { + sendPartialFrames(); + holdRefreshes(); + + $state = ['new' => [], 'deleted' => []]; + serveApi(function (Request $request) use (&$state) { + $path = parse_url($request->url(), PHP_URL_PATH); + parse_str((string) parse_url($request->url(), PHP_URL_QUERY), $query); + $served = fn (array $commits): array => array_values(array_filter($commits, fn (array $commit): bool => ! in_array($commit['id'], $state['deleted'], true))); + + return match (true) { + $path === '/api/v1/log/following' && isset($query['cursor']) => Http::response(pageJson($served(partialFrameCommits('c', 20, 20)))), + // As devnull answers ?since=: the first page, and how many on it are newer than the commit named. + $path === '/api/v1/log/following' => Http::response([ + ...pageJson($first = $served([...$state['new'], ...partialFrameCommits('c', 0, 20)]), 'page2'), + 'new_commits_count' => isset($query['since']) ? max(0, (int) array_search($query['since'], array_column($first, 'id'), true)) : 0, + ]), + $path === '/api/v1/log/latest' => Http::response(pageJson(partialFrameCommits('l', 0, 20))), + $path === '/api/v1/commits/c3/replies' => Http::response(pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c3', 'body' => 'A reply'])])), + $request->method() === 'POST' && $path === '/api/v1/commits/c4/star' => Http::response(['data' => [...partialFrameCommits('c', 4, 1)[0], 'starred' => true, 'stars_count' => 1]]), + $request->method() === 'DELETE' && str_starts_with($path, '/api/v1/commits/') => (function () use (&$state, $path) { + $state['deleted'][] = substr($path, strlen('/api/v1/commits/')); + + return Http::response(null, 204); + })(), + $path === '/api/v1/me' => Http::response(['data' => userWithCountsJson(), 'unread_notifications_count' => 0]), + default => Http::response(['message' => "No fake for {$path}."], 404), + }; + }); + + $screen = finishRefreshes(Native::visit('/log')); + expectPhoneInStep($screen); + + // A star sends the starred row's changes, and every other row as a marker. + finishRefreshes($screen->call('toggleStar', 'c4')); + expectPhoneInStep($screen); + expect(nodesSentInFull($screen))->toBeLessThan(40); + + $steps = [ + 'open a thread' => fn () => finishRefreshes($screen->call('toggleReplies', 'c3')), + 'next page' => fn () => finishRefreshes($screen->call('loadMore')), + 'pull to refresh with new commits on top' => function () use ($screen, &$state) { + $state['new'] = partialFrameCommits('n', 0, 3); + finishRefreshes($screen->call('load')); + }, + 'back to the top in a new list' => fn () => $screen->call('backToTop', 0), + 'delete from the middle' => fn () => finishRefreshes($screen->call('deleteCommit', 'c7')), + 'new commits in the pill' => function () use ($screen, &$state) { + $state['new'] = [...partialFrameCommits('m', 0, 2), ...$state['new']]; + finishRefreshes($screen->call('checkForNewCommits')); + }, + 'tap the pill' => fn () => finishRefreshes($screen->call('showNewCommits')), + 'close the thread' => fn () => finishRefreshes($screen->call('toggleReplies', 'c3')), + 'open the image viewer' => fn () => $screen->call('openImage', 'c5', 0)->assertSet('viewerOpen', true), + 'close it' => fn () => $screen->call('closeImageViewer'), + 'swipe to Latest' => fn () => finishRefreshes($screen->changeTab('showPage', 1)), + 'swipe back' => fn () => finishRefreshes($screen->changeTab('showPage', 0)), + ]; + + foreach ($steps as $name => $step) { + $step(); + expectPhoneInStep($screen, $name); + } +}); diff --git a/tests/Pest.php b/tests/Pest.php index 670154f7..de1d0bb7 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -15,6 +15,7 @@ use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; use Native\Mobile\AsyncTask; +use Native\Mobile\Edge\NativeComponent; use Native\Mobile\Events\Async\AsyncTaskFailed; use Native\Mobile\Events\Async\AsyncTaskFinished; use Native\Mobile\Events\Gallery\MediaSelected; @@ -1115,3 +1116,109 @@ function skipWithoutSkia(): void test()->markTestSkipped('needs the Skia plugin installed'); } } + +/** + * Turns EDGE's subtree reuse on for the screens a test opens next, as every phone has it: a frame sends a node the + * phone already holds as a reuse marker. Skips the test where the installed nativephp/mobile can't keep the phone's + * tree in step with that (anything before NativePHP/mobile-air#699, whose reader asks for a full frame when it + * can't), since partial frames would draw lists blank there. + */ +function sendPartialFrames(): FakeBridge +{ + if (! defined(NativeComponent::class.'::EVENT_FULL_FRAME')) { + test()->markTestSkipped('needs nativephp/mobile with NativePHP/mobile-air#699'); + } + + $bridge = FakeBridge::enable(); + $bridge->runtimeFlags = 0x02; + + return $bridge; +} + +/** + * The tree the phone holds after every frame the screen has published, built as EDGE's reader builds it: a reuse + * marker takes the node with that id from the tree before. A marker for a node the phone doesn't hold fails the test. + * + * @return array + */ +function phoneTree(TestableComponent $screen): array +{ + $tree = null; + + foreach ($screen->bridge()->publishes as $n => $frame) { + $held = []; + $index = function (array $node) use (&$index, &$held): void { + $held[$node['id']] = $node; + foreach ($node['children'] ?? [] as $child) { + $index($child); + } + }; + if ($tree !== null) { + $index($tree); + } + + $build = function (array $node) use (&$build, $held, $n): array { + if ((($node['flags'] ?? 0) & 1) === 1) { + expect(array_key_exists($node['id'], $held))->toBeTrue("Frame {$n} reuses node {$node['id']} ({$node['type']}), which the phone doesn't hold."); + + return $held[$node['id']]; + } + + if (isset($node['children'])) { + $node['children'] = array_map($build, $node['children']); + } + + return $node; + }; + + $tree = $build($frame); + } + + expect($tree)->not->toBeNull('The screen has published nothing.'); + + return $tree; +} + +/** + * Expects the phone to hold what the screen would send it in full right now, so partial frames left nothing stale or + * missing. Draws one full frame to compare with, which the phone never gets. + */ +function expectPhoneInStep(TestableComponent $screen, string $after = ''): void +{ + $onPhone = phoneTree($screen); + $bridge = $screen->bridge(); + $flags = $bridge->runtimeFlags; + $sent = count($bridge->publishes); + + $bridge->runtimeFlags = 0; + $full = $screen->call('navTitle')->tree(); + $bridge->runtimeFlags = $flags; + $bridge->publishes = array_slice($bridge->publishes, 0, $sent); + + $strip = function (array $node) use (&$strip): array { + unset($node['_hash']); + if (isset($node['children'])) { + $node['children'] = array_map($strip, $node['children']); + } + + return $node; + }; + + expect($strip($onPhone))->toBe($strip($full), "The phone isn't in step after: {$after}"); +} + +/** + * How many nodes the screen's last frame sent in full, rather than as reuse markers. + */ +function nodesSentInFull(TestableComponent $screen): int +{ + $count = function (array $node) use (&$count): int { + if ((($node['flags'] ?? 0) & 1) === 1) { + return 0; + } + + return 1 + array_sum(array_map($count, $node['children'] ?? [])); + }; + + return $count(end($screen->bridge()->publishes)); +} From 76800247bc7bd5053c4c914600a1cb3e91997eb5 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:15:14 +0000 Subject: [PATCH 03/10] Send only what changed on profiles A profile went in full so that a tab tapped again, which puts the same rows in a list with a new key, still reached the phone. With a row's id in its hash (NativePHP/mobile-air#699), the new list no longer matches the old one, so it is sent as it should be. The test covers a star, a thread, the tab tapped again, and a swipe to Replies and back. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Profile.php | 7 --- tests/Feature/Screens/LogsTest.php | 8 ++- tests/Feature/Screens/PartialFramesTest.php | 69 +++++++++++++++++++++ 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/app/NativeComponents/Profile.php b/app/NativeComponents/Profile.php index 79456f37..cee28387 100644 --- a/app/NativeComponents/Profile.php +++ b/app/NativeComponents/Profile.php @@ -82,13 +82,6 @@ class Profile extends NativeComponent use TalksToDevnull; use WatchesForCalls; - /** - * Every frame goes in full. A tab tapped again goes back to the top in a - * list with a new key and the same rows, which EDGE's subtree reuse would - * otherwise never send. - */ - protected bool $forceFullFrames = true; - public string $username = ''; public const array Tabs = ['commits', 'replies']; diff --git a/tests/Feature/Screens/LogsTest.php b/tests/Feature/Screens/LogsTest.php index 18118c5a..5f90e96f 100644 --- a/tests/Feature/Screens/LogsTest.php +++ b/tests/Feature/Screens/LogsTest.php @@ -355,13 +355,15 @@ function ada(): array ->and(nodeByRef($screen, 'commit-c1')['id'])->toBe($row); }); -it('sends only what changed on the Log, and Notifications, profiles and commit pages in full every frame', function () { +it('sends only what changed on the Log and profiles, and Notifications and commit pages in full every frame', function () { Http::fake(['devnull.test/*' => Http::response(pageJson([]))]); $sendsInFull = fn (string $screen): bool => (fn (): bool => $this->forceFullFrames)->call(Native::test($screen)->instance()); - expect($sendsInFull(Log::class))->toBeFalse(); + foreach ([Log::class, Profile::class] as $screen) { + expect($sendsInFull($screen))->toBeFalse(); + } - foreach ([Notifications::class, Profile::class, CommitDetail::class] as $screen) { + foreach ([Notifications::class, CommitDetail::class] as $screen) { expect($sendsInFull($screen))->toBeTrue(); } }); diff --git a/tests/Feature/Screens/PartialFramesTest.php b/tests/Feature/Screens/PartialFramesTest.php index 22e0fc2c..90277231 100644 --- a/tests/Feature/Screens/PartialFramesTest.php +++ b/tests/Feature/Screens/PartialFramesTest.php @@ -98,3 +98,72 @@ function partialFrameCommits(string $prefix, int $first, int $count): array expectPhoneInStep($screen, $name); } }); + +/** + * Commits on a profile or an organization's page, by the author given, newest first. + * + * @param array $author + * @return list> + */ +function partialFramePageCommits(string $prefix, array $author): array +{ + return array_map(fn (int $n): array => commitJson([ + 'id' => "{$prefix}{$n}", + 'body' => "Commit {$prefix}{$n}", + 'author' => $author, + 'replies_count' => $n === 3 ? 1 : 0, + ]), range(0, 19)); +} + +/** + * The API for a page of commits that can be starred and have a thread: $routes answers the rest by path. + * + * @param array $routes + */ +function servePartialFramePage(array $routes, string $starred): void +{ + serveApi(function (Request $request) use ($routes, $starred) { + $path = parse_url($request->url(), PHP_URL_PATH); + $thread = str_replace('4', '3', $starred); + + return match (true) { + $request->method() === 'POST' && $path === "/api/v1/commits/{$starred}/star" => Http::response(['data' => commitJson(['id' => $starred, 'body' => "Commit {$starred}", 'starred' => true, 'stars_count' => 1])]), + $path === "/api/v1/commits/{$thread}/replies" => Http::response(pageJson([replyJson(['id' => 'r1', 'parent_id' => $thread, 'body' => 'A reply'])])), + $path === '/api/v1/me' => Http::response(['data' => userWithCountsJson(), 'unread_notifications_count' => 0]), + default => is_callable($routes[$path] ?? null) ? $routes[$path]($request) : Http::response($routes[$path] ?? ['message' => "No fake for {$path}."], isset($routes[$path]) ? 200 : 404), + }; + }); +} + +it('keeps a profile on the phone in step through stars, threads, its tabs and back to the top', function () { + sendPartialFrames(); + holdRefreshes(); + + $ada = userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada Lovelace', 'lane' => 1]); + servePartialFramePage([ + '/api/v1/users/ada' => [ + 'data' => userWithCountsJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada Lovelace', 'lane' => 1], commits: 20), + 'is_following' => false, 'activity' => null, 'streaks' => ['longest' => 0, 'current' => 0], 'pinned_commit' => null, + ], + '/api/v1/users/ada/commits' => fn (Request $request) => Http::response(pageJson(partialFramePageCommits(str_contains($request->url(), 'replies') ? 'r' : 'p', $ada))), + ], starred: 'p4'); + + $screen = finishRefreshes(Native::visit('/log/users/ada')); + expectPhoneInStep($screen, 'opening'); + + $steps = [ + 'a star' => fn () => finishRefreshes($screen->call('toggleStar', 'p4')), + 'open a thread' => fn () => finishRefreshes($screen->call('toggleReplies', 'p3')), + 'the tab tapped again, back to the top in a new list' => fn () => tapProfileTab($screen, 'commits'), + 'swipe to Replies' => fn () => finishRefreshes(tapProfileTab($screen, 'replies')), + 'swipe back' => fn () => finishRefreshes(tapProfileTab($screen, 'commits')), + 'close the thread' => fn () => finishRefreshes($screen->call('toggleReplies', 'p3')), + ]; + + foreach ($steps as $name => $step) { + $step(); + expectPhoneInStep($screen, $name); + } + + expect(nodesSentInFull($screen))->toBeLessThan(40); +}); From dd25b3cef1d3af14a68458d407d4b98ac28aa7cc Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:15:37 +0000 Subject: [PATCH 04/10] Send only what changed on organizations An organization's page is built like a profile's and went in full for the same reason: a tab tapped again puts the same rows in a list with a new key. That reaches the phone now (NativePHP/mobile-air#699). The test covers a star, a thread, the tab tapped again, and a swipe to Mentions and back. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Organization.php | 5 --- tests/Feature/Screens/LogsTest.php | 5 +-- tests/Feature/Screens/PartialFramesTest.php | 40 +++++++++++++++++++++ 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/app/NativeComponents/Organization.php b/app/NativeComponents/Organization.php index fb12ccf9..fdc7d9d8 100644 --- a/app/NativeComponents/Organization.php +++ b/app/NativeComponents/Organization.php @@ -53,11 +53,6 @@ class Organization extends NativeComponent use ShowsCommits; use TalksToDevnull; - /** - * Every frame goes in full, as on a profile (see Profile::$forceFullFrames). - */ - protected bool $forceFullFrames = true; - public const array Tabs = ['commits', 'mentions']; /** diff --git a/tests/Feature/Screens/LogsTest.php b/tests/Feature/Screens/LogsTest.php index 5f90e96f..fc37d401 100644 --- a/tests/Feature/Screens/LogsTest.php +++ b/tests/Feature/Screens/LogsTest.php @@ -7,6 +7,7 @@ use App\NativeComponents\CommitDetail; use App\NativeComponents\Log; use App\NativeComponents\Notifications; +use App\NativeComponents\Organization; use App\NativeComponents\Profile; use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; @@ -355,11 +356,11 @@ function ada(): array ->and(nodeByRef($screen, 'commit-c1')['id'])->toBe($row); }); -it('sends only what changed on the Log and profiles, and Notifications and commit pages in full every frame', function () { +it('sends only what changed on the Log, profiles and organizations, and Notifications and commit pages in full every frame', function () { Http::fake(['devnull.test/*' => Http::response(pageJson([]))]); $sendsInFull = fn (string $screen): bool => (fn (): bool => $this->forceFullFrames)->call(Native::test($screen)->instance()); - foreach ([Log::class, Profile::class] as $screen) { + foreach ([Log::class, Profile::class, Organization::class] as $screen) { expect($sendsInFull($screen))->toBeFalse(); } diff --git a/tests/Feature/Screens/PartialFramesTest.php b/tests/Feature/Screens/PartialFramesTest.php index 90277231..868eb299 100644 --- a/tests/Feature/Screens/PartialFramesTest.php +++ b/tests/Feature/Screens/PartialFramesTest.php @@ -1,5 +1,6 @@ toBeLessThan(40); }); + +it('keeps an organization on the phone in step through stars, threads, its tabs and back to the top', function () { + sendPartialFrames(); + holdRefreshes(); + + $laravel = ['type' => 'organization', 'id' => 'o-laravel', 'handle' => 'laravel', 'name' => 'Laravel', 'lane' => 0]; + servePartialFramePage([ + '/api/v1/organizations/laravel' => [ + 'data' => [ + 'handle' => 'laravel', 'name' => 'Laravel', 'avatar_url' => 'https://avatars.githubusercontent.com/u/958072', 'bio' => 'The PHP framework for web artisans.', + 'location' => null, 'website' => 'https://laravel.com', 'github_url' => 'https://github.com/laravel', 'html_url' => 'http://devnull.test/@laravel', + 'lane' => 0, 'followers_count' => 45, 'admins' => [userJson(['id' => 'u-taylor', 'handle' => 'taylorotwell', 'name' => 'Taylor Otwell'])], + ], + 'is_following' => false, 'can_claim' => false, 'settings_url' => null, + ], + '/api/v1/organizations/laravel/commits' => pageJson(partialFramePageCommits('o', $laravel)), + '/api/v1/organizations/laravel/mentions' => pageJson(partialFramePageCommits('m', userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada']))), + ], starred: 'o4'); + + $screen = finishRefreshes(Native::visit('/log/organizations/laravel')); + expectPhoneInStep($screen, 'opening'); + $tab = fn (string $tab) => $screen->changeTab($screen->get('tab') === $tab ? 'backToTop' : 'showPage', (int) array_search($tab, Organization::Tabs, true)); + + $steps = [ + 'a star' => fn () => finishRefreshes($screen->call('toggleStar', 'o4')), + 'open a thread' => fn () => finishRefreshes($screen->call('toggleReplies', 'o3')), + 'the tab tapped again, back to the top in a new list' => fn () => $tab('commits'), + 'swipe to Mentions' => fn () => finishRefreshes($tab('mentions')), + 'swipe back' => fn () => finishRefreshes($tab('commits')), + 'close the thread' => fn () => finishRefreshes($screen->call('toggleReplies', 'o3')), + ]; + + foreach ($steps as $name => $step) { + $step(); + expectPhoneInStep($screen, $name); + } + + expect(nodesSentInFull($screen))->toBeLessThan(40); +}); From 23cf7f6946255a17b6966b44944118fdcc5a97d7 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:16:44 +0000 Subject: [PATCH 05/10] Send only what changed on the commit page A tap into the reply field mounts the thread's scroll view again under a new key, and subtree reuse then pointed at rows the phone had dropped, so the thread went blank as you started typing. The new key now changes the scroll view's hash (NativePHP/mobile-air#699), so it goes out whole, and each letter typed after that sends only the reply bar. The test opens the earlier commits and the replies, taps into the field twice, and types. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 8 ---- tests/Feature/Screens/LogsTest.php | 8 ++-- tests/Feature/Screens/PartialFramesTest.php | 41 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index fff9317d..4dbfafab 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -225,14 +225,6 @@ class CommitDetail extends NativeComponent */ private ?RowCache $replyRows = null; - /** - * Every frame goes in full. A tap on the reply field mounts the thread's - * scroll view again under a new key, and EDGE's subtree reuse sent its - * unchanged rows as references to nodes the phone dropped with the old - * one, so the thread went blank as you started typing. - */ - protected bool $forceFullFrames = true; - public function mount(): void { $this->focusReply = $this->data('reply', false) === true; diff --git a/tests/Feature/Screens/LogsTest.php b/tests/Feature/Screens/LogsTest.php index fc37d401..e056856b 100644 --- a/tests/Feature/Screens/LogsTest.php +++ b/tests/Feature/Screens/LogsTest.php @@ -356,17 +356,15 @@ function ada(): array ->and(nodeByRef($screen, 'commit-c1')['id'])->toBe($row); }); -it('sends only what changed on the Log, profiles and organizations, and Notifications and commit pages in full every frame', function () { +it('sends only what changed on the Log, profiles, organizations and commit pages, and Notifications in full every frame', function () { Http::fake(['devnull.test/*' => Http::response(pageJson([]))]); $sendsInFull = fn (string $screen): bool => (fn (): bool => $this->forceFullFrames)->call(Native::test($screen)->instance()); - foreach ([Log::class, Profile::class, Organization::class] as $screen) { + foreach ([Log::class, Profile::class, Organization::class, CommitDetail::class] as $screen) { expect($sendsInFull($screen))->toBeFalse(); } - foreach ([Notifications::class, CommitDetail::class] as $screen) { - expect($sendsInFull($screen))->toBeTrue(); - } + expect($sendsInFull(Notifications::class))->toBeTrue(); }); it('asks Following and Latest what came in since the newest commit showing, and counts the pill by devnull', function () { diff --git a/tests/Feature/Screens/PartialFramesTest.php b/tests/Feature/Screens/PartialFramesTest.php index 868eb299..897b117c 100644 --- a/tests/Feature/Screens/PartialFramesTest.php +++ b/tests/Feature/Screens/PartialFramesTest.php @@ -207,3 +207,44 @@ function servePartialFramePage(array $routes, string $starred): void expect(nodesSentInFull($screen))->toBeLessThan(40); }); + +it('keeps the commit page on the phone in step while you open the thread and type a reply', function () { + sendPartialFrames(); + $grace = userJson(['id' => 'u3', 'handle' => 'grace', 'name' => 'Grace']); + fakeApi([ + 'GET /api/v1/commits/c2' => [commitPageJson( + commitJson(['id' => 'c2', 'parent_id' => 'c1', 'body' => 'The focused commit', 'replies_count' => 3]), + [ + commitJson(['id' => 'c0', 'body' => 'The root commit', 'author' => $grace]), + commitJson(['id' => 'c1', 'parent_id' => 'c0', 'body' => 'The parent commit', 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada'])]), + ], + )], + 'GET /api/v1/commits/c2/replies' => [pageJson(array_map(fn (int $n): array => replyJson(['id' => "r{$n}", 'parent_id' => 'c2', 'body' => "Reply {$n}", 'author' => $grace]), range(1, 3)))], + 'GET /api/v1/commits/c2/related' => [['data' => []]], + ]); + + $screen = Native::visit('/log/commits/c2'); + expectPhoneInStep($screen, 'opening'); + + $steps = [ + 'the earlier commits shown' => fn () => $screen->call('showEarlier'), + 'the replies opened' => fn () => $screen->call('toggleReplies'), + // The scroll view mounts again at the top, under a new key. + 'a tap into the reply field' => fn () => $screen->call('replyTapped'), + 'a letter typed' => fn () => $screen->set('reply', 'N'), + 'another' => fn () => $screen->set('reply', 'Ni'), + 'the replies hidden' => fn () => $screen->call('toggleReplies'), + 'the reply field tapped again' => fn () => $screen->call('replyTapped'), + 'the replies opened again' => fn () => $screen->call('toggleReplies'), + ]; + + $sentInFull = []; + foreach ($steps as $name => $step) { + $step(); + $sentInFull[$name] = nodesSentInFull($screen); + expectPhoneInStep($screen, $name); + } + + // A letter typed sends the field and what it changes, not the thread above it. + expect($sentInFull['another'])->toBeLessThan(40); +}); From 503b80476ce3cd71ab80ab32de75e3ebd775e137 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:17:19 +0000 Subject: [PATCH 06/10] Send only what changed on Starred Starred went in full because rows leave its list from the middle. The rows are keyed, so the frame after an unstar refers to the rows that stay by id, and with the reader parsing every frame (NativePHP/mobile-air#699) the phone has all of them. The test unstars rows from the middle and the top, with a thread open under one of them, and pulls to refresh. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Starred.php | 5 --- tests/Feature/Screens/LogsTest.php | 5 ++- tests/Feature/Screens/PartialFramesTest.php | 41 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/app/NativeComponents/Starred.php b/app/NativeComponents/Starred.php index 862de09d..35dcc24c 100644 --- a/app/NativeComponents/Starred.php +++ b/app/NativeComponents/Starred.php @@ -46,11 +46,6 @@ class Starred extends NativeComponent } use TalksToDevnull; - /** - * Every frame goes in full, since rows leave the list from the middle. - */ - protected bool $forceFullFrames = true; - /** @var list */ public array $commits = []; diff --git a/tests/Feature/Screens/LogsTest.php b/tests/Feature/Screens/LogsTest.php index e056856b..b857f2b3 100644 --- a/tests/Feature/Screens/LogsTest.php +++ b/tests/Feature/Screens/LogsTest.php @@ -9,6 +9,7 @@ use App\NativeComponents\Notifications; use App\NativeComponents\Organization; use App\NativeComponents\Profile; +use App\NativeComponents\Starred; use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; use Native\Mobile\Events\Async\AsyncTaskFailed; @@ -356,11 +357,11 @@ function ada(): array ->and(nodeByRef($screen, 'commit-c1')['id'])->toBe($row); }); -it('sends only what changed on the Log, profiles, organizations and commit pages, and Notifications in full every frame', function () { +it('sends only what changed on the Log, profiles, organizations, commit pages and Starred, and Notifications in full every frame', function () { Http::fake(['devnull.test/*' => Http::response(pageJson([]))]); $sendsInFull = fn (string $screen): bool => (fn (): bool => $this->forceFullFrames)->call(Native::test($screen)->instance()); - foreach ([Log::class, Profile::class, Organization::class, CommitDetail::class] as $screen) { + foreach ([Log::class, Profile::class, Organization::class, CommitDetail::class, Starred::class] as $screen) { expect($sendsInFull($screen))->toBeFalse(); } diff --git a/tests/Feature/Screens/PartialFramesTest.php b/tests/Feature/Screens/PartialFramesTest.php index 897b117c..c66bd93f 100644 --- a/tests/Feature/Screens/PartialFramesTest.php +++ b/tests/Feature/Screens/PartialFramesTest.php @@ -248,3 +248,44 @@ function servePartialFramePage(array $routes, string $starred): void // A letter typed sends the field and what it changes, not the thread above it. expect($sentInFull['another'])->toBeLessThan(40); }); + +it('keeps Starred on the phone in step as rows leave from the middle', function () { + sendPartialFrames(); + $starred = fn (int $n, bool $starred = true): array => commitJson(['id' => "s{$n}", 'body' => "Starred s{$n}", 'starred' => $starred, 'stars_count' => (int) $starred, 'replies_count' => $n === 6 ? 1 : 0, 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'lane' => 1])]); + $unstarred = []; + serveApi(function (Request $request) use ($starred, &$unstarred) { + $path = parse_url($request->url(), PHP_URL_PATH); + + if ($request->method() === 'DELETE' && preg_match('#^/api/v1/commits/(s\d+)/star$#', $path, $m)) { + $unstarred[] = $m[1]; + + return Http::response(['data' => $starred((int) substr($m[1], 1), false)]); + } + + return match ($path) { + '/api/v1/starred' => Http::response(pageJson(array_values(array_filter(array_map($starred, range(12, 1, -1)), fn (array $commit): bool => ! in_array($commit['id'], $unstarred, true))), null, 'http://devnull.test/api/v1/starred')), + '/api/v1/commits/s6/replies' => Http::response(pageJson([replyJson(['id' => 'r1', 'parent_id' => 's6', 'body' => 'A reply'])])), + default => Http::response(['message' => "No fake for {$path}."], 404), + }; + }); + + $screen = finishRefreshes(Native::visit('/profile/starred')); + expectPhoneInStep($screen, 'opening'); + + $steps = [ + 'one unstarred from the middle' => fn () => finishRefreshes($screen->call('toggleStar', 's8')), + 'a thread opened under it' => fn () => finishRefreshes($screen->call('toggleReplies', 's6')), + 'another unstarred above the thread' => fn () => finishRefreshes($screen->call('toggleStar', 's7')), + 'pull to refresh' => fn () => finishRefreshes($screen->call('load')), + 'the top one unstarred' => fn () => finishRefreshes($screen->call('toggleStar', 's12')), + ]; + + $sentInFull = []; + foreach ($steps as $name => $step) { + $step(); + $sentInFull[$name] = nodesSentInFull($screen); + expectPhoneInStep($screen, $name); + } + + expect($sentInFull['one unstarred from the middle'])->toBeLessThan(40); +}); From 04051cd4242fab82bd0cfacee49f3eeb59bbc7c6 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:18:33 +0000 Subject: [PATCH 07/10] Send only what changed on Notifications Notifications went in full for the same reason as the Log: subtree reuse could refer to rows the phone never got and draw the list blank. Those were frames the phone's reader dropped, which it no longer does (NativePHP/mobile-air#699). The test opens a group, brings two new notifications in on top, loads the next page, closes the group and turns every kind back on, which puts the list under a new key. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Notifications.php | 6 -- tests/Feature/Screens/LogsTest.php | 6 +- tests/Feature/Screens/PartialFramesTest.php | 61 +++++++++++++++++++++ 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/app/NativeComponents/Notifications.php b/app/NativeComponents/Notifications.php index 48f495ab..cd6a66d2 100644 --- a/app/NativeComponents/Notifications.php +++ b/app/NativeComponents/Notifications.php @@ -58,12 +58,6 @@ class Notifications extends NativeComponent use WatchesForCalls; use WritesInBackground; - /** - * Every frame goes in full. EDGE's subtree reuse could refer to rows the - * phone never got once the list had changed, which drew it blank. - */ - protected bool $forceFullFrames = true; - /** * How long a group's notifications take to fade in or out, and its * chevron to turn, in milliseconds: as long as replies take on the Log. diff --git a/tests/Feature/Screens/LogsTest.php b/tests/Feature/Screens/LogsTest.php index b857f2b3..b606d0b2 100644 --- a/tests/Feature/Screens/LogsTest.php +++ b/tests/Feature/Screens/LogsTest.php @@ -357,15 +357,13 @@ function ada(): array ->and(nodeByRef($screen, 'commit-c1')['id'])->toBe($row); }); -it('sends only what changed on the Log, profiles, organizations, commit pages and Starred, and Notifications in full every frame', function () { +it('sends only what changed on the timeline screens, not every frame in full', function () { Http::fake(['devnull.test/*' => Http::response(pageJson([]))]); $sendsInFull = fn (string $screen): bool => (fn (): bool => $this->forceFullFrames)->call(Native::test($screen)->instance()); - foreach ([Log::class, Profile::class, Organization::class, CommitDetail::class, Starred::class] as $screen) { + foreach ([Log::class, Profile::class, Organization::class, CommitDetail::class, Starred::class, Notifications::class] as $screen) { expect($sendsInFull($screen))->toBeFalse(); } - - expect($sendsInFull(Notifications::class))->toBeTrue(); }); it('asks Following and Latest what came in since the newest commit showing, and counts the pill by devnull', function () { diff --git a/tests/Feature/Screens/PartialFramesTest.php b/tests/Feature/Screens/PartialFramesTest.php index c66bd93f..321ad98e 100644 --- a/tests/Feature/Screens/PartialFramesTest.php +++ b/tests/Feature/Screens/PartialFramesTest.php @@ -289,3 +289,64 @@ function servePartialFramePage(array $routes, string $starred): void expect($sentInFull['one unstarred from the middle'])->toBeLessThan(40); }); + +/** + * A page of notifications, as devnull sends them. + * + * @param list> $groups + * @return array + */ +function partialFrameInbox(array $groups, ?string $cursor = null): array +{ + return [...pageJson($groups, $cursor, path: 'http://devnull.test/api/v1/notifications'), 'filters' => ['type' => 'all'], 'read_at' => now()->toIso8601ZuluString()]; +} + +it('keeps Notifications on the phone in step as new ones come in, groups open and the kinds change', function () { + sendPartialFrames(); + holdRefreshes(); + + $notification = fn (string $id, string $type = 'starred', int $events = 1): array => notificationJson($type, [ + 'id' => $id, + 'event_count' => $events, + 'actor' => userJson(['id' => "u-{$id}", 'handle' => "person{$id}", 'name' => "Person {$id}", 'lane' => 2]), + 'commit' => notificationCommitJson(['id' => "c-{$id}", 'body' => "About {$id}"]), + ]); + $state = ['new' => []]; + serveApi(function (Request $request) use ($notification, &$state) { + $path = parse_url($request->url(), PHP_URL_PATH); + $all = [...$state['new'], $notification('g1', events: 3), ...array_map(fn (int $n): array => $notification("n{$n}"), range(1, 15))]; + + return match (true) { + $path === '/api/v1/notifications' && str_contains($request->url(), 'cursor=page2') => Http::response(partialFrameInbox(array_map(fn (int $n): array => $notification("o{$n}"), range(1, 10)))), + $path === '/api/v1/notifications' => Http::response(partialFrameInbox($all, 'page2')), + $path === '/api/v1/notifications/g1/group' => Http::response(pageJson([$notification('g1-older'), $notification('g1-oldest')])), + $path === '/api/v1/me' => Http::response(['data' => userWithCountsJson(), 'unread_notifications_count' => 0]), + default => Http::response(['message' => "No fake for {$path}."], 404), + }; + }); + + $screen = finishRefreshes(Native::visit('/notifications')); + expect(treeShows(phoneTree($screen), 'About n15'))->toBeTrue(); + expectPhoneInStep($screen, 'opening'); + + $steps = [ + 'a group opened' => fn () => finishRefreshes($screen->call('toggleGroup', 'g1')), + 'two new ones on top' => function () use ($screen, &$state, $notification) { + $state['new'] = [$notification('new2', 'followed'), $notification('new1', 'mentioned')]; + finishRefreshes($screen->call('load')); + }, + 'the next page' => fn () => finishRefreshes($screen->call('loadMore')), + 'the group closed' => fn () => finishRefreshes($screen->call('toggleGroup', 'g1')), + 'every kind shown again, in a new list' => fn () => finishRefreshes($screen->call('showAll')), + ]; + + $sentInFull = []; + foreach ($steps as $name => $step) { + $step(); + $sentInFull[$name] = nodesSentInFull($screen); + expectPhoneInStep($screen, $name); + } + + expect(treeShows(phoneTree($screen), 'Person new1'))->toBeTrue() + ->and($sentInFull['the group closed'])->toBeLessThan(40); +}); From 5baffc2522d69eb3110856ea5be1c6b44bca5d1a Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:19:22 +0000 Subject: [PATCH 08/10] Send only what changed on Remotes Remotes went in full because a conversation with a new message moves to the top. Its rows are keyed, so the move refers to them by id, and the tab tapped again now reaches the phone as a new list (NativePHP/mobile-air#699). The test moves two conversations to the top from the middle and lower down, taps the tab again, swipes to Fetched and back, and checks the order the phone ends up with. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Remotes.php | 6 --- tests/Feature/Screens/LogsTest.php | 3 +- tests/Feature/Screens/PartialFramesTest.php | 51 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/app/NativeComponents/Remotes.php b/app/NativeComponents/Remotes.php index a4176d3e..92bf354f 100644 --- a/app/NativeComponents/Remotes.php +++ b/app/NativeComponents/Remotes.php @@ -88,12 +88,6 @@ class Remotes extends NativeComponent public const string LeaveAlert = 'remotes-leave'; - /** - * Every frame goes in full, since a row moves to the top when it - * has a new message. - */ - protected bool $forceFullFrames = true; - /** @var list */ public array $conversations = []; diff --git a/tests/Feature/Screens/LogsTest.php b/tests/Feature/Screens/LogsTest.php index b606d0b2..2eaf4fcb 100644 --- a/tests/Feature/Screens/LogsTest.php +++ b/tests/Feature/Screens/LogsTest.php @@ -9,6 +9,7 @@ use App\NativeComponents\Notifications; use App\NativeComponents\Organization; use App\NativeComponents\Profile; +use App\NativeComponents\Remotes; use App\NativeComponents\Starred; use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; @@ -361,7 +362,7 @@ function ada(): array Http::fake(['devnull.test/*' => Http::response(pageJson([]))]); $sendsInFull = fn (string $screen): bool => (fn (): bool => $this->forceFullFrames)->call(Native::test($screen)->instance()); - foreach ([Log::class, Profile::class, Organization::class, CommitDetail::class, Starred::class, Notifications::class] as $screen) { + foreach ([Log::class, Profile::class, Organization::class, CommitDetail::class, Starred::class, Notifications::class, Remotes::class] as $screen) { expect($sendsInFull($screen))->toBeFalse(); } }); diff --git a/tests/Feature/Screens/PartialFramesTest.php b/tests/Feature/Screens/PartialFramesTest.php index 321ad98e..cc33f34f 100644 --- a/tests/Feature/Screens/PartialFramesTest.php +++ b/tests/Feature/Screens/PartialFramesTest.php @@ -1,5 +1,7 @@ toBeTrue() ->and($sentInFull['the group closed'])->toBeLessThan(40); }); + +it('keeps Remotes on the phone in step as a conversation with a new message moves to the top', function () { + sendPartialFrames(); + $this->travelTo('2026-10-19 15:30:00'); + app(Account::class)->rememberRemotes(new Remotes(requests: true)); + + // Ten conversations, the newest message first. A new message puts its conversation on top. + $latest = array_combine(range(1, 10), array_map(fn (int $n): string => sprintf('2026-10-19T%02d:00:00.000000Z', 14 - $n % 10), range(1, 10))); + $conversation = fn (int $n): array => conversationJson([ + 'id' => "conv-{$n}", + 'partner' => userJson(['id' => "u{$n}", 'handle' => "person{$n}", 'name' => "Person {$n}", 'lane' => $n % 7]), + 'last_message' => remoteMessageJson(['id' => $n, 'body' => "Message for {$n} at {$latest[$n]}"]), + 'last_message_at' => $latest[$n], + ]); + serveApi(function (Request $request) use (&$latest, $conversation) { + parse_str((string) parse_url($request->url(), PHP_URL_QUERY), $query); + $ids = array_keys($latest); + usort($ids, fn (int $a, int $b): int => strcmp($latest[$b], $latest[$a])); + + return Http::response(remotesInboxJson(($query['tab'] ?? 'open') === 'open' ? array_map($conversation, $ids) : [])); + }); + + $screen = finishRefreshes(Native::visit('/remotes')); + expectPhoneInStep($screen, 'opening'); + + $steps = [ + 'a message in the middle one, which moves to the top' => function () use ($screen, &$latest) { + $latest[6] = '2026-10-19T15:20:00.000000Z'; + finishRefreshes($screen->call('pollInbox')); + }, + 'another, from further down' => function () use ($screen, &$latest) { + $latest[9] = '2026-10-19T15:25:00.000000Z'; + finishRefreshes($screen->call('pollInbox')); + }, + 'the tab tapped again, back to the top in a new list' => fn () => $screen->call('backToTop', 0), + 'swipe to Fetched' => fn () => finishRefreshes($screen->changeTab('showPage', 1)), + 'swipe back' => fn () => finishRefreshes($screen->changeTab('showPage', 0)), + 'a poll with nothing new' => fn () => finishRefreshes($screen->call('pollInbox')), + ]; + + foreach ($steps as $name => $step) { + $step(); + expectPhoneInStep($screen, $name); + } + + $rows = findNode(phoneTree($screen), fn (array $node): bool => ($node['ref'] ?? null) === 'remotes')['children']; + expect(array_slice(array_column($rows, 'ref'), 0, 3))->toBe(['remote-conv-9', 'remote-conv-6', 'remote-conv-10']) + ->and($rows)->toHaveCount(10); +}); From a13dcbaa1f5c924e3ba94b6cbcbb15e87f1501a6 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:19:53 +0000 Subject: [PATCH 09/10] Send only what changed on Search Search went in full because a new term replaces every row. New rows are new ids, which go out in full anyway, and rows a term shares with the last one are referred to by id, which the phone now always holds (NativePHP/mobile-air#699). The test picks a term, types more of it, switches to a term with the same commits in another order, goes back, and clears the field. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Search.php | 5 --- tests/Feature/Screens/LogsTest.php | 3 +- tests/Feature/Screens/PartialFramesTest.php | 35 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/NativeComponents/Search.php b/app/NativeComponents/Search.php index d05cd1a9..e66bf30a 100644 --- a/app/NativeComponents/Search.php +++ b/app/NativeComponents/Search.php @@ -63,11 +63,6 @@ class Search extends NativeComponent */ public const int ShortestCommitTerm = 3; - /** - * Every frame goes in full, as on Starred, since a new term replaces every row. - */ - protected bool $forceFullFrames = true; - public string $query = ''; /** diff --git a/tests/Feature/Screens/LogsTest.php b/tests/Feature/Screens/LogsTest.php index 2eaf4fcb..13d6f739 100644 --- a/tests/Feature/Screens/LogsTest.php +++ b/tests/Feature/Screens/LogsTest.php @@ -10,6 +10,7 @@ use App\NativeComponents\Organization; use App\NativeComponents\Profile; use App\NativeComponents\Remotes; +use App\NativeComponents\Search; use App\NativeComponents\Starred; use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; @@ -362,7 +363,7 @@ function ada(): array Http::fake(['devnull.test/*' => Http::response(pageJson([]))]); $sendsInFull = fn (string $screen): bool => (fn (): bool => $this->forceFullFrames)->call(Native::test($screen)->instance()); - foreach ([Log::class, Profile::class, Organization::class, CommitDetail::class, Starred::class, Notifications::class, Remotes::class] as $screen) { + foreach ([Log::class, Profile::class, Organization::class, CommitDetail::class, Starred::class, Notifications::class, Remotes::class, Search::class] as $screen) { expect($sendsInFull($screen))->toBeFalse(); } }); diff --git a/tests/Feature/Screens/PartialFramesTest.php b/tests/Feature/Screens/PartialFramesTest.php index cc33f34f..14e028f7 100644 --- a/tests/Feature/Screens/PartialFramesTest.php +++ b/tests/Feature/Screens/PartialFramesTest.php @@ -401,3 +401,38 @@ function partialFrameInbox(array $groups, ?string $cursor = null): array expect(array_slice(array_column($rows, 'ref'), 0, 3))->toBe(['remote-conv-9', 'remote-conv-6', 'remote-conv-10']) ->and($rows)->toHaveCount(10); }); + +it('keeps Search on the phone in step as each term replaces every row', function () { + sendPartialFrames(); + serveApi(function (Request $request) { + parse_str((string) parse_url($request->url(), PHP_URL_QUERY), $query); + $term = (string) ($query['q'] ?? ''); + $found = fn (int $count, string $prefix): array => array_map(fn (int $n): array => commitJson(['id' => "{$prefix}{$n}", 'body' => "{$term} result {$n}"]), range(1, $count)); + + return match (parse_url($request->url(), PHP_URL_PATH)) { + '/api/v1/search/users' => Http::response(['data' => [userJson(['id' => 'id-ada', 'handle' => 'ada', 'name' => 'Ada', 'is_followed' => false, 'follows_you' => false])]]), + // The same commits come back for two terms, in a different order, as a search can find them. + '/api/v1/search/commits' => Http::response(['data' => str_starts_with($term, 'php') ? $found(8, 'c') : array_reverse($found(8, 'c'))]), + default => Http::response(pageJson([])), + }; + }); + + $screen = Native::visit('/log/search'); + expectPhoneInStep($screen, 'opening'); + + $steps = [ + 'a term picked' => fn () => finishRefreshes($screen->call('pick', 'php')), + 'a letter more' => fn () => finishRefreshes($screen->set('query', 'phpx')), + 'another term, the same commits in another order' => function () use ($screen) { + finishRefreshes($screen->set('query', 'laravel')); + expect(treeShows(phoneTree($screen), 'laravel result 8'))->toBeTrue(); + }, + 'back to the first term' => fn () => finishRefreshes($screen->set('query', 'php')), + 'the field cleared' => fn () => finishRefreshes($screen->set('query', '')), + ]; + + foreach ($steps as $name => $step) { + $step(); + expectPhoneInStep($screen, $name); + } +}); From 31c0eb4b3e247ebc128b0722847f1cee4a335729 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:20:44 +0000 Subject: [PATCH 10/10] Send only what changed in a Remotes thread A thread went in full because messages come in at the bottom and their reactions change in place. Both are ordinary changes to keyed rows, and the frames that carried them are no longer dropped by the phone's reader (NativePHP/mobile-air#699). The test polls in a message and a reaction, types, hearts a message, replies and sends, loads older messages above, and polls again. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Conversation.php | 6 -- tests/Feature/Screens/LogsTest.php | 3 +- tests/Feature/Screens/PartialFramesTest.php | 70 +++++++++++++++++++++ 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/app/NativeComponents/Conversation.php b/app/NativeComponents/Conversation.php index 25ffdef6..464f5f56 100644 --- a/app/NativeComponents/Conversation.php +++ b/app/NativeComponents/Conversation.php @@ -175,12 +175,6 @@ class Conversation extends NativeComponent public const int PinnedLines = 3; - /** - * Every frame goes in full: messages come in at the bottom and their - * reactions change in place, which EDGE's subtree reuse would otherwise miss. - */ - protected bool $forceFullFrames = true; - /** * Who the thread is with, from the route: a username, or an org's id. */ diff --git a/tests/Feature/Screens/LogsTest.php b/tests/Feature/Screens/LogsTest.php index 13d6f739..e4a44294 100644 --- a/tests/Feature/Screens/LogsTest.php +++ b/tests/Feature/Screens/LogsTest.php @@ -5,6 +5,7 @@ use App\Devnull\ResponseCache; use App\Devnull\Timeline; use App\NativeComponents\CommitDetail; +use App\NativeComponents\Conversation; use App\NativeComponents\Log; use App\NativeComponents\Notifications; use App\NativeComponents\Organization; @@ -363,7 +364,7 @@ function ada(): array Http::fake(['devnull.test/*' => Http::response(pageJson([]))]); $sendsInFull = fn (string $screen): bool => (fn (): bool => $this->forceFullFrames)->call(Native::test($screen)->instance()); - foreach ([Log::class, Profile::class, Organization::class, CommitDetail::class, Starred::class, Notifications::class, Remotes::class, Search::class] as $screen) { + foreach ([Log::class, Profile::class, Organization::class, CommitDetail::class, Starred::class, Notifications::class, Remotes::class, Search::class, Conversation::class] as $screen) { expect($sendsInFull($screen))->toBeFalse(); } }); diff --git a/tests/Feature/Screens/PartialFramesTest.php b/tests/Feature/Screens/PartialFramesTest.php index 14e028f7..45bfa771 100644 --- a/tests/Feature/Screens/PartialFramesTest.php +++ b/tests/Feature/Screens/PartialFramesTest.php @@ -436,3 +436,73 @@ function partialFrameInbox(array $groups, ?string $cursor = null): array expectPhoneInStep($screen, $name); } }); + +it('keeps a Remotes thread on the phone in step as messages come in at the bottom and reactions change in place', function () { + sendPartialFrames(); + $this->travelTo('2026-10-19 15:30:00'); + $viewer = '0199e5c4-0000-7000-8000-000000000001'; + + $message = fn (int $id, bool $mine = false): array => remoteMessageJson([ + 'id' => $id, + 'user_id' => $mine ? $viewer : 'u2', + 'client_id' => sprintf('9f0f6f3e-0000-4000-8000-%012d', $id), + 'body' => "Message {$id}", + 'created_at' => sprintf('2026-10-19T15:%02d:00Z', $id), + ]); + $state = ['messages' => array_map(fn (int $id): array => $message($id, $id % 3 === 0), range(11, 22)), 'changes' => []]; + serveApi(function (Request $request) use (&$state, $message, $viewer) { + $path = parse_url($request->url(), PHP_URL_PATH); + parse_str((string) parse_url($request->url(), PHP_URL_QUERY), $query); + + return match (true) { + $request->method() === 'GET' && $path === '/api/v1/remotes/@ada/messages' && isset($query['before']) => Http::response(threadJson(array_map($message, range(1, 10)))), + $request->method() === 'GET' && $path === '/api/v1/remotes/@ada/messages' && isset($query['after']) => Http::response(threadJson( + array_values(array_filter($state['messages'], fn (array $m): bool => $m['id'] > (int) $query['after'])), + ['reactions_version' => count($state['changes']), 'reaction_changes' => $state['changes']], + )), + $request->method() === 'GET' && $path === '/api/v1/remotes/@ada/messages' => Http::response(threadJson($state['messages'], ['has_older' => true, 'read_through_id' => 22])), + $request->method() === 'POST' && $path === '/api/v1/remotes/@ada/messages' => Http::response(['data' => remoteMessageJson([ + 'id' => 99, 'user_id' => $viewer, 'client_id' => json_decode($request->body(), true)['client_id'], 'body' => json_decode($request->body(), true)['body'], + ])], 201), + str_ends_with($path, '/reactions') && $request->method() === 'POST' => Http::response(['reactions' => [['user_id' => $viewer, 'emoji' => json_decode($request->body(), true)['emoji']]]]), + $path === '/api/v1/me' => Http::response(currentUserJson()), + default => Http::response(['usage' => []], $request->method() === 'GET' ? 200 : 204), + }; + }); + + $screen = finishRefreshes(Native::visit('/remotes/conversations/ada')); + expectPhoneInStep($screen, 'opening'); + + $steps = [ + 'a message in at the bottom, and a reaction on one above' => function () use ($screen, &$state, $message) { + $state['messages'][] = $message(23); + $state['changes'] = [['id' => 15, 'reactions' => [['user_id' => 'u2', 'emoji' => '🚀']]]]; + finishRefreshes($screen->call('poll')); + }, + 'a letter typed' => fn () => $screen->set('draft', 'o'), + 'a few more' => function () use ($screen) { + $screen->set('draft', 'on my way'); + expect(treeShows(phoneTree($screen), 'on my way'))->toBeTrue(); + }, + 'a heart on one of theirs' => fn () => finishRefreshes($screen->call('heart', 20)), + 'a reply begun' => fn () => $screen->call('reply', 21), + 'sent' => fn () => finishRefreshes($screen->call('send')), + 'older messages above' => fn () => finishRefreshes($screen->call('loadOlder')), + 'another in, and the reaction taken off' => function () use ($screen, &$state, $message) { + $state['messages'][] = $message(24); + $state['changes'] = [...$state['changes'], ['id' => 15, 'reactions' => []]]; + finishRefreshes($screen->call('poll')); + }, + ]; + + $sentInFull = []; + foreach ($steps as $name => $step) { + $step(); + $sentInFull[$name] = nodesSentInFull($screen); + expectPhoneInStep($screen, $name); + } + + expect(treeShows(phoneTree($screen), 'Message 24'))->toBeTrue() + ->and(treeShows(phoneTree($screen), 'Message 1"'))->toBeTrue() + ->and($sentInFull['a few more'])->toBeLessThan(40); +});