From 46f6a99ec77319ead91cc4f2e88463eeb93906cc Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 20:27:55 +0000 Subject: [PATCH 01/18] =?UTF-8?q?Ask=20for=20your=20past=C3=A9is=20once=20?= =?UTF-8?q?a=20frame,=20not=20once=20a=20row?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With pastéis mode off, the screen passes $pasteis as null, and both RowInputs::for() and commit-actions treated null as "not given" and asked the account again. That's a query on the phone, where the cache is the app's SQLite database, so every row on the Log cost one on every frame, kept or not: 24 queries a frame on a log of 20. Null is now an answer. The account is only asked when the screen passed nothing at all. The same goes for $viewer, which is null when you're signed out. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/RowInputs.php | 6 ++++-- .../native/partials/commit-actions.blade.php | 8 ++++--- tests/Feature/Screens/LogRowCacheTest.php | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/Devnull/RowInputs.php b/app/Devnull/RowInputs.php index d96cbca2..d80e3fee 100644 --- a/app/Devnull/RowInputs.php +++ b/app/Devnull/RowInputs.php @@ -26,13 +26,15 @@ final class RowInputs */ public static function for(Commit $commit, array $scope): array { - $viewer = $scope['viewer'] ?? app(Account::class)->user(); + // The screen's own answer, null included: null is a real answer (signed out, pastéis mode off), so it's + // only read from the account when the screen gave none. Reading it again cost a query a row on a phone. + $viewer = array_key_exists('viewer', $scope) ? $scope['viewer'] : app(Account::class)->user(); $ownership = $scope['ownership'] ?? app(Account::class)->ownership(); return [ 'viewer' => $viewer?->id, 'organizations' => $ownership->organizationIds, - 'pasteis' => $scope['pasteis'] ?? app(Account::class)->pasteis(), + 'pasteis' => array_key_exists('pasteis', $scope) ? $scope['pasteis'] : app(Account::class)->pasteis(), 'stashed' => $scope['stashed'] ?? [], 'unfolded' => $scope['unfolded'] ?? [], 'expandable' => isset($scope['threads']), diff --git a/resources/views/native/partials/commit-actions.blade.php b/resources/views/native/partials/commit-actions.blade.php index b8371dc7..5118560f 100644 --- a/resources/views/native/partials/commit-actions.blade.php +++ b/resources/views/native/partials/commit-actions.blade.php @@ -22,7 +22,9 @@ A commit with a quote or a reply you started and didn't send marks that button, as the web does with stash@{0} beside its label. That doesn't fit the row, so here it's a dot after the label, inside the button. - The screen passes the names of the drafts it has kept ($stashed, see App\Devnull\Stash). + The screen passes the names of the drafts it has kept ($stashed, see App\Devnull\Stash). It passes you ($viewer) + and your pastéis ($pasteis) too, and null is an answer: a row only asks the account when the screen gave neither, + since asking is a query on a phone, and with pastéis mode off every row asked again. Each action is at least 44pt wide and 36pt tall to tap, as Apple asks. The row has no negative vertical margins: Android draws a negative margin as an offset and keeps the space, so the row sat 6pt lower there than on iOS, and @@ -52,7 +54,7 @@ @php($repliesCount ??= $commit->repliesCount) @php($iconSize = $compact ? 14 : 16) @php($labelSize = $compact ? 'text-xs' : 'text-[13px]') -@php($viewer ??= app(\App\Devnull\Account::class)->user()) +@php($viewer = array_key_exists('viewer', get_defined_vars()) ? $viewer : app(\App\Devnull\Account::class)->user()) @php($ownership ??= app(\App\Devnull\Account::class)->ownership()) @php($stashed ??= []) @php($hasQuoteStash = in_array('quote-'.$commit->id, $stashed, true)) @@ -63,7 +65,7 @@ @php($endDot ??= null) @php($starPop = \App\Devnull\Pop::transform($popping['star-'.$commit->id] ?? null, 'star')) @php($pastelPop = \App\Devnull\Pop::transform($popping['pastel-'.$commit->id] ?? null, 'pastel')) -@php($pasteis ??= app(\App\Devnull\Account::class)->pasteis()) +@php($pasteis = array_key_exists('pasteis', get_defined_vars()) ? $pasteis : app(\App\Devnull\Account::class)->pasteis()) @php($showsPastel = $pasteis !== null && ! $commit->author->isOrganization) @php($canGivePastel = $showsPastel && $viewer !== null && ! $isOwn && $commit->isApproved()) @php($pastelLabel = \App\Devnull\Display::count($commit->pasteisCount, 'pastel', 'pastéis')) diff --git a/tests/Feature/Screens/LogRowCacheTest.php b/tests/Feature/Screens/LogRowCacheTest.php index 8dc278df..343af969 100644 --- a/tests/Feature/Screens/LogRowCacheTest.php +++ b/tests/Feature/Screens/LogRowCacheTest.php @@ -6,6 +6,9 @@ use App\Devnull\ImageCache; use App\Devnull\Stash; use App\NativeComponents\Log; +use Illuminate\Cache\Events\CacheHit; +use Illuminate\Cache\Events\CacheMissed; +use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\View; use Native\Mobile\Testing\Native; @@ -109,3 +112,21 @@ function expectKeptRowsToMatchFreshOnes(TestableComponent $screen, array $before $screen->tap('star-c1'); expect($built)->toBe(['c1']); }); + +it('asks the account for you and your pastéis once a frame, not once a row', function () { + $screen = Native::visit('/log')->tap('replies-c2'); + $reads = []; + Event::listen([CacheHit::class, CacheMissed::class], function (CacheHit|CacheMissed $event) use (&$reads) { + $reads[$event->key] = ($reads[$event->key] ?? 0) + 1; + }); + + // Pastéis mode is off: null is the answer, not a reason to ask again. + $screen->call('isRanked'); + expect($reads['devnull.pasteis'] ?? 0)->toBe(1); + + // Every row built afresh asks no more often. + $reads = []; + Closure::bind(fn () => $this->rowCaches = [], $screen->instance(), Log::class)(); + $screen->call('isRanked'); + expect($reads['devnull.pasteis'] ?? 0)->toBe(1); +}); From ec5a08ce15bfa5bd5d3be48e5b6d69947e04858e Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 20:30:40 +0000 Subject: [PATCH 02/18] Keep skeleton, loading, end and day rows with a list's commits Every frame built the rows around the commits afresh: the skeleton rows of a log or tab with nothing loaded, the loading row at the end of a list, the root commit row, the day markers and the last-visit marker, and a profile's pinned commit. On the Log that was five skeleton and loading rows on every frame, about a third of a frame where nothing changed. They now go through the list's RowCache like its commits, on the Log, profiles, organizations, Starred and Search. Each is kept against what it draws, so a loading row that stops pulsing when you swipe away is built again. Co-Authored-By: Claude Opus 5.5 --- .../views/native/partials/feed.blade.php | 26 ++++++++++++++----- .../views/native/partials/log-page.blade.php | 12 ++++++--- .../partials/organization-page.blade.php | 16 +++++++++--- .../native/partials/profile-page.blade.php | 23 ++++++++++++---- resources/views/native/search.blade.php | 4 ++- resources/views/native/starred.blade.php | 12 ++++++--- tests/Feature/Screens/LogRowCacheTest.php | 22 ++++++++++++++++ 7 files changed, 93 insertions(+), 22 deletions(-) diff --git a/resources/views/native/partials/feed.blade.php b/resources/views/native/partials/feed.blade.php index 5a9ebb31..c594571b 100644 --- a/resources/views/native/partials/feed.blade.php +++ b/resources/views/native/partials/feed.blade.php @@ -6,8 +6,8 @@ The commit's rail runs on past them when its author's run goes on below. A commit its author carried on in replies to themselves shows "Show thread". - Given a $rowCache (see App\Devnull\RowCache), commits and replies that haven't changed since the last frame are - drawn from it rather than built again. Given a $rowWindow (see App\Devnull\RowWindow), rows far from the screen + Given a $rowCache (see App\Devnull\RowCache), commits, replies and markers that haven't changed since the last frame + are drawn from it rather than built again. Given a $rowWindow (see App\Devnull\RowWindow), rows far from the screen go as placeholders with the keys their partials give them, so the phone keeps each one's place and height. --}} @php @@ -17,11 +17,18 @@ @endphp @foreach ($rows as $feedIndex => $row) @if ($row->isDayMarker()) - @if ($rowWindow?->place($feedIndex) ?? true) + @php + $markerDraws = $rowWindow?->place($feedIndex) ?? true; + @endphp + @if (! $markerDraws) + @php + $rowWindow->placeholder('day-'.$row->label); + @endphp + @elseif ($rowCache === null) @include('native.partials.day-marker', ['label' => $row->label, 'lane' => $row->previousLane]) @else @php - $rowWindow->placeholder('day-'.$row->label); + $rowCache->include('day-'.$row->label, [], 'native.partials.day-marker', ['label' => $row->label, 'lane' => $row->previousLane], []); @endphp @endif @elseif ($row->isWhoToFollow()) @@ -33,11 +40,18 @@ @endphp @endif @elseif ($row->isLastVisitMarker()) - @if ($rowWindow?->place($feedIndex) ?? true) + @php + $markerDraws = $rowWindow?->place($feedIndex) ?? true; + @endphp + @if (! $markerDraws) + @php + $rowWindow->placeholder('last-visit'); + @endphp + @elseif ($rowCache === null) @include('native.partials.last-visit-marker', ['lane' => $row->previousLane]) @else @php - $rowWindow->placeholder('last-visit'); + $rowCache->include('last-visit', [], 'native.partials.last-visit-marker', ['lane' => $row->previousLane], []); @endphp @endif @else diff --git a/resources/views/native/partials/log-page.blade.php b/resources/views/native/partials/log-page.blade.php index 1e2073d9..4b18be87 100644 --- a/resources/views/native/partials/log-page.blade.php +++ b/resources/views/native/partials/log-page.blade.php @@ -26,7 +26,9 @@ class="w-full flex-1 bg-theme-surface {{ $embedded ? '' : \App\Devnull\Display:: > @if (! $page['loaded'] && $page['error'] === null) @foreach (range(1, 3) as $skeleton) - @include('native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading commits', 'pulse' => $page['showing']]) + @php + $page['rowCache']->include('loading-'.$skeleton, [], 'native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading commits', 'pulse' => $page['showing']], []); + @endphp @endforeach @endif @@ -45,9 +47,13 @@ class="w-full flex-1 bg-theme-surface {{ $embedded ? '' : \App\Devnull\Display:: @if ($page['lastCommit']) @if ($page['nextCursor'] !== null) - @include('native.partials.rail-loading', ['pulse' => $page['showing']]) + @php + $page['rowCache']->include('loading-more', [], 'native.partials.rail-loading', ['pulse' => $page['showing']], []); + @endphp @else - @include('native.partials.rail-end', ['lane' => $page['lastCommit']->lane(), 'message' => "That's the root commit. There's nothing before it."]) + @php + $page['rowCache']->include('root-commit', [], 'native.partials.rail-end', ['lane' => $page['lastCommit']->lane(), 'message' => "That's the root commit. There's nothing before it."], []); + @endphp @endif @endif diff --git a/resources/views/native/partials/organization-page.blade.php b/resources/views/native/partials/organization-page.blade.php index 234d444d..52f38ad7 100644 --- a/resources/views/native/partials/organization-page.blade.php +++ b/resources/views/native/partials/organization-page.blade.php @@ -21,7 +21,9 @@ class="w-full flex-1 bg-theme-surface" ]) @elseif (! $page['loaded']) @foreach (range(1, 3) as $skeleton) - @include('native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading commits', 'pulse' => $page['showing']]) + @php + $page['rowCache']->include('loading-'.$skeleton, [], 'native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading commits', 'pulse' => $page['showing']], []); + @endphp @endforeach @elseif ($page['isEmpty']) @if ($page['tab'] === 'mentions') @@ -36,11 +38,17 @@ class="w-full flex-1 bg-theme-surface" @if ($page['loaded'] && ! $page['isEmpty']) @if ($page['nextCursor'] !== null) - @include('native.partials.rail-loading', ['pulse' => $page['showing']]) + @php + $page['rowCache']->include('loading-more', [], 'native.partials.rail-loading', ['pulse' => $page['showing']], []); + @endphp @elseif ($page['tab'] === 'mentions') - @include('native.partials.rail-end', ['lane' => $user->lane(), 'message' => "That's the first mention of {$user->handle()}."]) + @php + $page['rowCache']->include('root-commit', [], 'native.partials.rail-end', ['lane' => $user->lane(), 'message' => "That's the first mention of {$user->handle()}."], []); + @endphp @else - @include('native.partials.rail-end', ['lane' => $user->lane(), 'message' => "That's {$user->handle()}'s root commit."]) + @php + $page['rowCache']->include('root-commit', [], 'native.partials.rail-end', ['lane' => $user->lane(), 'message' => "That's {$user->handle()}'s root commit."], []); + @endphp @endif @endif @endif diff --git a/resources/views/native/partials/profile-page.blade.php b/resources/views/native/partials/profile-page.blade.php index 9b1c5f66..80d0cadb 100644 --- a/resources/views/native/partials/profile-page.blade.php +++ b/resources/views/native/partials/profile-page.blade.php @@ -4,6 +4,8 @@ The pager draws the header and the tabs at the top of this list, so they scroll with it. As on the Log, each tab has its own list, a new $page['listKey'] puts it back at the top, and only the tab you're on asks for its next page. + The pinned commit, the skeleton rows and the row at the end are kept in the tab's row cache with its commits, so + a frame only builds what changed. --}} @if (! $page['loaded'] && $page['error'] === null) @foreach (range(1, 3) as $skeleton) - @include('native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading commits', 'pulse' => $page['showing']]) + @php + $page['rowCache']->include('loading-'.$skeleton, [], 'native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading commits', 'pulse' => $page['showing']], []); + @endphp @endforeach @endif @@ -39,18 +43,27 @@ class="w-full flex-1 bg-theme-surface" Pinned - @include('native.partials.commit-row', ['commit' => $page['pinnedCommit'], 'previousLane' => null, 'continuesRun' => false, 'rowKey' => 'pinned-'.$page['pinnedCommit']->id]) + @php + $rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]); + $page['rowCache']->include('pinned-'.$page['pinnedCommit']->id, \App\Devnull\RowInputs::for($page['pinnedCommit'], $rowScope), 'native.partials.commit-row', ['commit' => $page['pinnedCommit'], 'previousLane' => null, 'continuesRun' => false, 'rowKey' => 'pinned-'.$page['pinnedCommit']->id], $rowScope); + @endphp @endif @include('native.partials.feed', ['rows' => $page['rows'], 'threads' => $page['threads'], 'rowCache' => $page['rowCache']]) @if (! $page['isEmpty'] || $page['pinnedCommit']) @if ($page['nextCursor'] !== null) - @include('native.partials.rail-loading', ['pulse' => $page['showing']]) + @php + $page['rowCache']->include('loading-more', [], 'native.partials.rail-loading', ['pulse' => $page['showing']], []); + @endphp @elseif ($page['tab'] === 'replies') - @include('native.partials.rail-end', ['lane' => $user->lane(), 'message' => $isMe ? 'That was your first reply.' : "That's {$user->handle()}'s first reply."]) + @php + $page['rowCache']->include('root-commit', [], 'native.partials.rail-end', ['lane' => $user->lane(), 'message' => $isMe ? 'That was your first reply.' : "That's {$user->handle()}'s first reply."], []); + @endphp @else - @include('native.partials.rail-end', ['lane' => $user->lane(), 'message' => $isMe ? 'That was your first commit. Everyone starts somewhere.' : "That's {$user->handle()}'s root commit."]) + @php + $page['rowCache']->include('root-commit', [], 'native.partials.rail-end', ['lane' => $user->lane(), 'message' => $isMe ? 'That was your first commit. Everyone starts somewhere.' : "That's {$user->handle()}'s root commit."], []); + @endphp @endif @endif diff --git a/resources/views/native/search.blade.php b/resources/views/native/search.blade.php index 663f1740..581e42eb 100644 --- a/resources/views/native/search.blade.php +++ b/resources/views/native/search.blade.php @@ -50,7 +50,9 @@ @if ($commitsFoundFor === null && $error === null) @foreach (range(1, 3) as $skeleton) - @include('native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Searching commits']) + @php + $rowCache->include('loading-'.$skeleton, [], 'native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Searching commits'], []); + @endphp @endforeach @elseif ($commitsFoundFor !== null && $commits === []) @include('native.partials.empty', [ diff --git a/resources/views/native/starred.blade.php b/resources/views/native/starred.blade.php index 20ce9d17..de2b723b 100644 --- a/resources/views/native/starred.blade.php +++ b/resources/views/native/starred.blade.php @@ -23,7 +23,9 @@ @if (! $loaded && $error === null) @foreach (range(1, 3) as $skeleton) - @include('native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading starred commits']) + @php + $rowCache->include('loading-'.$skeleton, [], 'native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading starred commits'], []); + @endphp @endforeach @endif @@ -40,9 +42,13 @@ @if ($lastCommit) @if ($nextCursor !== null) - @include('native.partials.rail-loading') + @php + $rowCache->include('loading-more', [], 'native.partials.rail-loading', [], []); + @endphp @else - @include('native.partials.rail-end', ['lane' => $lastCommit->lane(), 'message' => "You've reached the end of your starred commits."]) + @php + $rowCache->include('root-commit', [], 'native.partials.rail-end', ['lane' => $lastCommit->lane(), 'message' => "You've reached the end of your starred commits."], []); + @endphp @endif @endif diff --git a/tests/Feature/Screens/LogRowCacheTest.php b/tests/Feature/Screens/LogRowCacheTest.php index 343af969..6cc3a817 100644 --- a/tests/Feature/Screens/LogRowCacheTest.php +++ b/tests/Feature/Screens/LogRowCacheTest.php @@ -130,3 +130,25 @@ function expectKeptRowsToMatchFreshOnes(TestableComponent $screen, array $before $screen->call('isRanked'); expect($reads['devnull.pasteis'] ?? 0)->toBe(1); }); + +it('keeps the skeleton, loading and day rows, and draws them as building them again would', function () { + $built = []; + View::composer(['native.partials.rail-loading', 'native.partials.day-marker'], function ($view) use (&$built) { + $built[] = $view->name(); + }); + + // Latest is beside Following and has nothing kept, so it shows skeleton rows; Following ends in a loading row. + keep('log/following', pageJson([commitJson(['id' => 'c9', 'created_at' => now()->subDays(2)->toIso8601ZuluString()])], 'next')); + $screen = Native::visit('/log'); + $built = []; + + $screen->call('isRanked'); + expect($built)->toBe([]); + + // Swiping to Latest stops the loading row pulsing on Following, and starts the skeletons pulsing on Latest. + foreach (['latest', 'following'] as $log) { + $before = $screen->tree(); + tapLogTab($screen, $log); + expectKeptRowsToMatchFreshOnes($screen, $before); + } +}); From 52864fa2d42844d47d4fd363bfb1777f7706bd74 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 20:32:01 +0000 Subject: [PATCH 03/18] Make the log beside yours from what's kept only when that changes Every frame read the answer kept for the log beside yours and made its first commits afresh, with their bodies parsed again. New commits then missed the timeline laid out for them last frame and the rows kept for them, so each was hashed again too. The preview is now kept with a hash of what it was made from, and only made again when that changes, as it does when a star or a delete reaches the kept answer. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Log.php | 42 +++++++++++++++++++++--------- tests/Feature/Screens/LogsTest.php | 21 +++++++++++++++ 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/app/NativeComponents/Log.php b/app/NativeComponents/Log.php index 2ef269c0..a3dd5046 100644 --- a/app/NativeComponents/Log.php +++ b/app/NativeComponents/Log.php @@ -251,6 +251,14 @@ class Log extends NativeComponent */ private array $rowCaches = []; + /** + * The logs beside yours as they were last drawn, by log: what was kept + * for them, hashed, and what they showed (see previewState()). + * + * @var array}> + */ + private array $previews = []; + /** * Which rows of each log are drawn. * @@ -438,6 +446,10 @@ private function openAfresh(): void * A log you're not on: the first few commits kept for it, as it will * open, or skeleton rows with nothing kept, or while it's two swipes away. * + * Every frame draws it, so its commits are only made again when what's + * kept for them changes. Made afresh, they cost the frame as much again + * to lay out and to check against the rows kept for them. + * * @return array */ private function previewState(string $log): array @@ -445,19 +457,25 @@ private function previewState(string $log): array $beside = abs(array_search($log, self::Logs, true) - array_search($this->log, self::Logs, true)) === 1; $json = $beside && ! $this->skeletonFrame ? $this->cached('log/'.$log) : null; $kept = is_array($json['data'] ?? null) ? $json['data'] : []; - $page = $json === null ? null : Page::fromArray(['data' => array_slice($kept, 0, self::PreviewCommits)] + $json, Commit::fromArray(...)); + $shown = $json === null ? null : [array_slice($kept, 0, self::PreviewCommits), count($kept) > self::PreviewCommits, array_diff_key($json, ['data' => true])]; + $key = hash('xxh3', serialize($shown)); + + if (($this->previews[$log][0] ?? null) !== $key) { + $page = $json === null ? null : Page::fromArray(['data' => array_slice($kept, 0, self::PreviewCommits)] + $json, Commit::fromArray(...)); + + $this->previews[$log] = [$key, [ + 'commits' => $page->items ?? [], + // Rows past the preview are left out, with a skeleton row for them, as for the next page. + 'nextCursor' => count($kept) > self::PreviewCommits ? 'preview' : $page?->nextCursor, + 'threads' => [], + 'latestCommits' => [], + 'suggestions' => array_values(array_map(Commit::fromArray(...), array_filter(is_array($json['suggestions'] ?? null) ? $json['suggestions'] : [], is_array(...)))), + 'loaded' => $page !== null, + 'error' => null, + ]]; + } - return [ - 'commits' => $page->items ?? [], - // Rows past the preview are left out, with a skeleton row for them, as for the next page. - 'nextCursor' => count($kept) > self::PreviewCommits ? 'preview' : $page?->nextCursor, - 'threads' => [], - 'latestCommits' => [], - 'suggestions' => array_values(array_map(Commit::fromArray(...), array_filter(is_array($json['suggestions'] ?? null) ? $json['suggestions'] : [], is_array(...)))), - 'loaded' => $page !== null, - 'lastVisitAt' => $this->lastVisitSeenAt($log), - 'error' => null, - ]; + return [...$this->previews[$log][1], 'lastVisitAt' => $this->lastVisitSeenAt($log)]; } public function isRanked(): bool diff --git a/tests/Feature/Screens/LogsTest.php b/tests/Feature/Screens/LogsTest.php index 615b43c6..b072768d 100644 --- a/tests/Feature/Screens/LogsTest.php +++ b/tests/Feature/Screens/LogsTest.php @@ -2,6 +2,7 @@ use App\Devnull\Client; use App\Devnull\FirstFrame; +use App\Devnull\ResponseCache; use App\Devnull\Timeline; use App\NativeComponents\CommitDetail; use App\NativeComponents\Log; @@ -277,6 +278,26 @@ function ada(): array } }); +it('keeps the commits shown for the log beside yours until what was kept for it changes', function () { + holdRefreshes(); + keep('log/latest', pageJson([commitJson(['id' => 'l1', 'body' => 'Latest 1', 'author' => ada()])])); + + $screen = Native::visit('/log'); + $previews = fn (): array => Closure::bind(fn (): array => $this->previews, $screen->instance(), Log::class)(); + $shown = $previews()['latest'][1]['commits'][0]; + + // Drawn again with nothing changed, the commit is the one made last frame, so its row is the one kept for it. + $screen->call('isRanked'); + expect($previews()['latest'][1]['commits'][0])->toBe($shown); + + // A star given on another screen changes what was kept for Latest, and its preview shows it. + app(ResponseCache::class)->starChanged('l1', true); + $screen->call('isRanked'); + + expect($previews()['latest'][1]['commits'][0])->not->toBe($shown) + ->and(nodeByRef($screen, 'star-l1')['props']['a11y_label'])->toStartWith('Unstar commit'); +}); + it('leaves the log two swipes away as skeleton rows until you are beside it', function () { holdRefreshes(); keep('log/trending', pageJson(array_map(fn (int $n): array => commitJson(['id' => "t{$n}", 'body' => "Trending {$n}"]), range(1, 5)))); From 54c09f657b9405f13862450fc7775d9979c9c59f Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 20:34:12 +0000 Subject: [PATCH 04/18] Draw a kept poll row again when your lane colour changes A poll you can vote on draws its Vote button in your lane colour, which the row reads from the screen. RowInputs didn't have it, so after you changed your colour the Log kept the old one on that button until the row changed for some other reason. The kept-row test now also changes your colour and joins you to an organization whose commit is showing, and checks the kept rows against rows built afresh, as it did for stars, times and threads. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/RowInputs.php | 2 ++ tests/Feature/Screens/LogRowCacheTest.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/Devnull/RowInputs.php b/app/Devnull/RowInputs.php index d80e3fee..51cd32cd 100644 --- a/app/Devnull/RowInputs.php +++ b/app/Devnull/RowInputs.php @@ -48,6 +48,8 @@ public static function for(Commit $commit, array $scope): array 'poll' => [$scope['pollChoices'][$commit->id] ?? null, in_array($commit->id, $scope['voting'] ?? [], true)], 'selected' => ($scope['selectedCommit'] ?? null) === $commit->id, 'video' => $commit->linkPreview?->embed === null ? null : VideoDetails::card($commit->linkPreview), + // A poll's Vote button wears your lane colour. + 'colour' => $scope['myColour'] ?? null, ]; } diff --git a/tests/Feature/Screens/LogRowCacheTest.php b/tests/Feature/Screens/LogRowCacheTest.php index 6cc3a817..52ce1e71 100644 --- a/tests/Feature/Screens/LogRowCacheTest.php +++ b/tests/Feature/Screens/LogRowCacheTest.php @@ -3,6 +3,7 @@ use App\Devnull\Account; use App\Devnull\Data\Pasteis; use App\Devnull\Data\StashedDraft; +use App\Devnull\Data\User; use App\Devnull\ImageCache; use App\Devnull\Stash; use App\NativeComponents\Log; @@ -27,6 +28,11 @@ 'GET /api/v1/log/following' => [pageJson([ commitJson(['id' => 'c3', 'body' => $long, 'preview_segments' => [['type' => 'text', 'text' => substr($long, 0, 270).'…']]]), commitJson(['id' => 'c2', 'replies_count' => 1, 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada', 'avatar_url' => 'https://avatars.githubusercontent.com/u/2?v=4'])]), + commitJson(['id' => 'p1', 'body' => 'Tabs or spaces?', 'author' => $grace, 'poll' => [ + 'id' => 'poll1', 'closes_at' => now()->addDay()->toIso8601ZuluString(), 'is_closed' => false, 'has_voted' => false, + 'options' => [['id' => 'o1', 'label' => 'Tabs'], ['id' => 'o2', 'label' => 'Spaces']], + ]]), + commitJson(['id' => 'g1', 'body' => 'From the organization', 'author' => userJson(['type' => 'organization', 'id' => 'o1', 'handle' => 'acme', 'name' => 'Acme'])]), commitJson(['id' => 'c1', 'body' => 'The oldest commit', 'author' => $grace]), ])], 'GET /api/v1/commits/c2/replies' => [pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'A reply in place'])])], @@ -72,6 +78,16 @@ function expectKeptRowsToMatchFreshOnes(TestableComponent $screen, array $before app(Account::class)->rememberPasteis(new Pasteis); $screen->call('isRanked'); }, + // An organization's commit is yours once you're in it, whoever posted it. + 'joining an organization' => function () use ($screen) { + app(Account::class)->rememberOrganizations([User::fromArray(userJson(['type' => 'organization', 'id' => 'o1', 'handle' => 'acme', 'name' => 'Acme']))]); + $screen->call('isRanked'); + }, + // A poll's Vote button wears your lane colour. + 'your colour' => function () use ($screen) { + app(Account::class)->remember(User::fromArray(userJson(['lane' => 5]))); + $screen->call('isRanked'); + }, ]; foreach ($changes as $change) { From efb9b3b45455393d9c41983e40203bd96a6d9a6f Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 20:36:39 +0000 Subject: [PATCH 05/18] Build only the row a draft is for, not every row RowInputs kept every row against the whole list of stashed drafts and unfolded commits, though a row only shows its own: a dot on its Quote or Reply button, and its body whole once you tapped Show more. Starting a draft anywhere, as the first letter of a quote or a reply does, built every row on the screen again. Each row is now kept against its own drafts and its own unfolding. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/RowInputs.php | 5 +++-- tests/Feature/Screens/LogRowCacheTest.php | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Devnull/RowInputs.php b/app/Devnull/RowInputs.php index 51cd32cd..41b62a77 100644 --- a/app/Devnull/RowInputs.php +++ b/app/Devnull/RowInputs.php @@ -35,8 +35,9 @@ public static function for(Commit $commit, array $scope): array 'viewer' => $viewer?->id, 'organizations' => $ownership->organizationIds, 'pasteis' => array_key_exists('pasteis', $scope) ? $scope['pasteis'] : app(Account::class)->pasteis(), - 'stashed' => $scope['stashed'] ?? [], - 'unfolded' => $scope['unfolded'] ?? [], + // Only this commit's own drafts and unfolding: a draft started anywhere used to build every row again. + 'stashed' => [in_array('quote-'.$commit->id, $scope['stashed'] ?? [], true), in_array('reply-'.$commit->id, $scope['stashed'] ?? [], true)], + 'unfolded' => in_array($commit->id, $scope['unfolded'] ?? [], true), 'expandable' => isset($scope['threads']), 'opened' => array_key_exists($commit->id, $scope['threads'] ?? []) && ! in_array($commit->id, $scope['closingThreads'] ?? [], true), 'faded' => in_array($commit->id, $scope['fadedRows'] ?? [], true), diff --git a/tests/Feature/Screens/LogRowCacheTest.php b/tests/Feature/Screens/LogRowCacheTest.php index 52ce1e71..aeb27bac 100644 --- a/tests/Feature/Screens/LogRowCacheTest.php +++ b/tests/Feature/Screens/LogRowCacheTest.php @@ -127,6 +127,12 @@ function expectKeptRowsToMatchFreshOnes(TestableComponent $screen, array $before $screen->tap('star-c1'); expect($built)->toBe(['c1']); + + // A draft marks the button of the commit it's for, and only that row. + $built = []; + app(Stash::class)->put(app(Account::class)->user()?->id, 'reply-c1', new StashedDraft('Half a reply')); + $screen->call('isRanked'); + expect($built)->toBe(['c1']); }); it('asks the account for you and your pastéis once a frame, not once a row', function () { From c92aef9de4d457dd0bde34cb39937839f353ace3 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 20:36:39 +0000 Subject: [PATCH 06/18] Keep a commit page's commits between frames, as its replies are The commit a page is about, what it replies to, the rest of its series and the related commits were built again on every frame. Typing a reply draws a frame a few times a second, so each letter built every commit above the reply bar. They now go through the page's RowCache with its replies. The commit the page is about is also kept against what it shows of its thread (whether its replies are open, and how many) and your timezone, which its time's label is in. The test changes each of those, and the time, and checks the kept rows against rows built afresh. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 4 +- .../views/native/commit-detail.blade.php | 10 +++++ .../native/partials/related-commits.blade.php | 8 ++-- tests/Feature/Screens/RowCacheScreensTest.php | 42 +++++++++++++++++-- 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index d103ecc6..13b2000e 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -289,7 +289,9 @@ class CommitDetail extends NativeComponent public string $openedId = ''; /** - * The replies from the last frame, so a render only builds the replies that changed, as the Log does its rows. + * The page's rows from the last frame, so a render only builds the ones that changed, as the Log does its rows: + * the commit, what it replies to and the rest of its series, its replies, and the related commits. Typing a reply + * draws a frame a few times a second, and each used to build every commit above the reply bar again. */ private ?RowCache $replyRows = null; diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index d5f4c550..a6b0a73f 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -62,6 +62,16 @@ + @elseif ($pageRow['partial'] === 'native.partials.commit-row') + {{-- + The commits are kept like the replies, so typing a reply only builds the reply bar. A row's + data says where its commit sits in the tree: its rail, its place in its author's thread, and + for a commit above, how many replies its button counts. RowInputs has whether those are open. + The commit the page is about also shows its own replies' toggle and count, and its time in your + timezone, which only the page knows. + --}} + @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) + @php($replyRows->include($pageRow['key'], [...\App\Devnull\RowInputs::for($pageRow['data']['commit'], $rowScope), 'focused' => $pageRow['data']['focused'] ? [$repliesShown, $replyCount, app(\App\Devnull\Timezone::class)->yours()] : null], $pageRow['partial'], $pageRow['data'], $rowScope)) @elseif ($pageRow['reply'] === null) @include($pageRow['partial'], $pageRow['data']) @else diff --git a/resources/views/native/partials/related-commits.blade.php b/resources/views/native/partials/related-commits.blade.php index af215186..2ada9d41 100644 --- a/resources/views/native/partials/related-commits.blade.php +++ b/resources/views/native/partials/related-commits.blade.php @@ -2,7 +2,8 @@ Other threads, in relevance order, on a fresh rail below this thread as on the web. They start closed under a header with their count, which opens them in place and closes them again, its chevron turning as they do (see CommitDetail::toggleRelated()). Each commit fades and slides into place a little after the one above it, and fades - out together as they close. The header is the whole row, so it's an easy target at the foot of the page. + out together as they close. The header is the whole row, so it's an easy target at the foot of the page. Their rows + are kept with the page's other rows (see CommitDetail::$replyRows), so a frame only builds the ones that changed. --}} @php($relatedOpen = $relatedShown && ! $relatedClosing) @php($relatedLabel = \App\Devnull\Display::count(count($relatedRows), 'related commit', 'related commits')) @@ -18,7 +19,8 @@ @if ($relatedShown) @foreach ($relatedRows as $relatedRow) - @include('native.partials.commit-row', [ + @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) + @php($replyRows->include('related-'.$relatedRow->commit->id, \App\Devnull\RowInputs::for($relatedRow->commit, $rowScope), 'native.partials.commit-row', [ 'commit' => $relatedRow->commit, 'previousLane' => $relatedRow->previousLane, 'continuesRun' => $relatedRow->continuesRun, @@ -29,7 +31,7 @@ 'threadBelow' => false, 'withTail' => ! $loop->last, 'expandable' => false, - ]) + ], $rowScope)) @endforeach @endif diff --git a/tests/Feature/Screens/RowCacheScreensTest.php b/tests/Feature/Screens/RowCacheScreensTest.php index d7c547cd..8290b6c3 100644 --- a/tests/Feature/Screens/RowCacheScreensTest.php +++ b/tests/Feature/Screens/RowCacheScreensTest.php @@ -1,5 +1,6 @@ tap('replies-c2')->assertSee('Second reply'); - // The commits above the replies read what the screen shows of the thread, so they're built every time. "Show - // more" is a row of its own, so the last reply of a page stays as it was when the next page comes. - expect(rowsBuiltBy(fn () => $screen->call('navTitle')))->toBe(['c2']) - ->and(rowsBuiltBy(fn () => $screen->call('loadMoreReplies')->assertSee('Third reply')))->toBe(['c2', 'r3']); + // The commits above the replies are kept like the replies, and "Show more" is a row of its own, so the last reply + // of a page stays as it was when the next page comes. Only the reply that page brings is built. + expect(rowsBuiltBy(fn () => $screen->call('navTitle')))->toBe([]) + ->and(rowsBuiltBy(fn () => $screen->call('loadMoreReplies')->assertSee('Third reply')))->toBe(['r3']); expectKeptRowsMatchFreshOnes($screen, CommitDetail::class, 'replyRows', null); }); + +it("keeps a commit page's commits between renders, and builds the commit again when what it shows of its thread changes", function () { + fakeApi([ + 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'replies_count' => 1, 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada'])]), [commitJson(['id' => 'c1', 'body' => 'What it replies to'])])], + 'GET /api/v1/commits/c2/replies' => [pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'First reply'])])], + 'GET /api/v1/commits/c2/related' => [['data' => [commitJson(['id' => 'x1', 'body' => 'Another thread'])]]], + 'POST /api/v1/commits/c2/star' => [['data' => commitJson(['id' => 'c2', 'replies_count' => 1, 'stars_count' => 1, 'starred' => true, 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada'])])]], + ]); + $screen = finishRefreshes(Native::visit('/log/commits/c2'))->tap('related-commits-toggle'); + + // Typing a reply only builds the commit it replies to once, when the draft is first kept, which its row marks. + expect(rowsBuiltBy(fn () => $screen->input('reply-input', 'N')))->toBe(['c2']) + ->and(rowsBuiltBy(fn () => $screen->input('reply-input', 'Nice')))->toBe([]); + + $changes = [ + 'its replies opened' => fn () => $screen->tap('replies-c2')->assertSee('First reply'), + 'a star' => fn () => $screen->tap('star-c2'), + 'its replies closed' => fn () => $screen->tap('replies-c2'), + 'the time' => function () use ($screen) { + $this->travel(2)->hours(); + $screen->call('navTitle')->assertSee('2h'); + }, + 'your timezone' => function () use ($screen) { + app(Account::class)->rememberTimezone('Asia/Tokyo'); + $screen->call('navTitle'); + }, + ]; + + foreach ($changes as $change) { + $change(); + expectKeptRowsMatchFreshOnes($screen, CommitDetail::class, 'replyRows', null); + } +}); From b5c19cdfc9d753f7d476df2d0195974467aeae55 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 25 Nov 2026 12:15:39 +0000 Subject: [PATCH 07/18] Check a commit page's kept commits through its newer thread states Since #187 was started, main's commit page grew a few ways for a commit row to change without its commit changing: the replies of a commit above it open and fold in place, tapping a commit in the tree moves the page to it, and an author's replies to themselves read as a thread under the commit. Each of these now gets the same check as the rest: the kept rows must match rows built afresh. That covers an ancestor's replies opening, fading out and folded, the page moving up, back down and down to a reply, and a self thread with its replies opened and closed, the time passing and the page moving to a later part. Typing a reply still only builds the commit it replies to, once. Co-Authored-By: Claude Opus 5.5 --- tests/Feature/Screens/RowCacheScreensTest.php | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/tests/Feature/Screens/RowCacheScreensTest.php b/tests/Feature/Screens/RowCacheScreensTest.php index 8290b6c3..f050b9fd 100644 --- a/tests/Feature/Screens/RowCacheScreensTest.php +++ b/tests/Feature/Screens/RowCacheScreensTest.php @@ -129,3 +129,89 @@ function expectKeptRowsMatchFreshOnes(TestableComponent $screen, string $class, expectKeptRowsMatchFreshOnes($screen, CommitDetail::class, 'replyRows', null); } }); + +it("keeps a commit page's commits right as the replies of a commit above open and fold, and as the page moves", function () { + $person = fn (string $handle, int $lane): array => userJson(['id' => 'u-'.$handle, 'handle' => $handle, 'name' => ucfirst($handle), 'lane' => $lane]); + $c1 = commitJson(['id' => 'c1', 'body' => 'The commit above', 'replies_count' => 2, 'author' => $person('ada', 1)]); + $c2 = commitJson(['id' => 'c2', 'parent_id' => 'c1', 'body' => 'The focused commit', 'replies_count' => 1, 'author' => $person('grace', 2)]); + $x1 = replyJson(['id' => 'x1', 'parent_id' => 'c1', 'body' => 'Another reply above', 'replies_count' => 1, 'author' => $person('linus', 4)]); + $x2 = replyJson(['id' => 'x2', 'parent_id' => 'x1', 'body' => 'A reply to the other reply', 'author' => $person('alan', 5)]); + $r1 = replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'A reply below', 'author' => $person('ken', 6)]); + fakeApi([ + 'GET /api/v1/commits/c2' => [commitPageJson($c2, [$c1])], + 'GET /api/v1/commits/c1' => [commitPageJson($c1)], + 'GET /api/v1/commits/r1' => [commitPageJson($r1, [$c1, $c2])], + 'GET /api/v1/commits/c1/related' => [['data' => []]], + 'GET /api/v1/commits/c2/related' => [['data' => []]], + 'GET /api/v1/commits/r1/related' => [['data' => []]], + 'GET /api/v1/commits/c1/replies' => [pageJson([$c2, $x1])], + 'GET /api/v1/commits/c2/replies' => [pageJson([$r1])], + 'GET /api/v1/commits/x1/replies' => [pageJson([$x2])], + 'GET /api/v1/commits/r1/replies' => [pageJson([])], + 'GET /api/v1/commits/x2/replies' => [pageJson([])], + ]); + // Held, so the frame while the replies above fade out is drawn too. + holdRefreshes(); + $screen = finishRefreshes(Native::visit('/log/commits/c2', ['replies' => true]))->assertSee('A reply below'); + + finishRefreshes($screen->tap('replies-c1'))->assertSee('Another reply above'); + expectKeptRowsMatchFreshOnes($screen, CommitDetail::class, 'replyRows', null); + + // With the replies above open, a frame builds none of the commits, and typing a reply only builds the commit it + // replies to, once, when the draft is first kept. + expect(rowsBuiltBy(fn () => $screen->call('navTitle')))->toBe([]) + ->and(rowsBuiltBy(fn () => $screen->input('reply-input', 'N')))->toBe(['c2']) + ->and(rowsBuiltBy(fn () => $screen->input('reply-input', 'Nice')))->toBe([]); + + $changes = [ + 'a reply above opens its own' => fn () => finishRefreshes($screen->tap('replies-x1'))->assertSee('A reply to the other reply'), + 'the replies above fading out' => fn () => expect($screen->tap('replies-c1')->get('closingThreads'))->toBe(['c1']), + 'the replies above folded' => fn () => finishRefreshes($screen)->assertDontSee('Another reply above'), + 'the page moved up to the commit above' => fn () => finishRefreshes($screen->tap('commit-c1'))->assertSet('id', 'c1'), + 'the page moved back down' => fn () => finishRefreshes($screen->tap('thread-reply-c2'))->assertSet('id', 'c2'), + 'the page moved down to a reply' => fn () => finishRefreshes($screen->tap('thread-reply-r1'))->assertSet('id', 'r1'), + 'the replies above opened over the reply' => fn () => finishRefreshes($screen->tap('replies-c1'))->assertSee('Another reply above'), + ]; + + foreach ($changes as $change) { + $change(); + expectKeptRowsMatchFreshOnes($screen, CommitDetail::class, 'replyRows', null); + } +}); + +it("keeps a commit page's commits right on a thread its author wrote as replies to themselves", function () { + $ada = userJson(['id' => 'u-ada', 'handle' => 'ada', 'name' => 'Ada', 'lane' => 2]); + $part = fn (string $id, ?string $parent, int $minutes, array $overrides = []): array => commitJson(['id' => $id, 'parent_id' => $parent, 'body' => "Ada's {$id}", 'author' => $ada, 'created_at' => now()->subMinutes($minutes)->toIso8601ZuluString(), ...$overrides]); + fakeApi([ + 'GET /api/v1/commits/c1' => [commitPageJson($part('c1', null, 30, ['replies_count' => 2]))], + 'GET /api/v1/commits/p2' => [commitPageJson($part('p2', 'c1', 25), [$part('c1', null, 30, ['replies_count' => 2])])], + 'GET /api/v1/commits/c1/related' => [['data' => []]], + 'GET /api/v1/commits/p2/related' => [['data' => []]], + 'GET /api/v1/commits/c1/replies' => [pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'Grace answers', 'created_at' => now()->subMinutes(28)->toIso8601ZuluString()]), $part('p2', 'c1', 25)])], + 'GET /api/v1/commits/p2/replies' => [pageJson([replyJson(['id' => 'x1', 'parent_id' => 'p2', 'body' => 'Under part two']), $part('p3', 'p2', 20)])], + 'GET /api/v1/commits/p3/replies' => [pageJson([replyJson(['id' => 'y1', 'parent_id' => 'p3', 'body' => 'Under the last part'])])], + 'GET /api/v1/commits/r1/replies' => [pageJson([])], + 'GET /api/v1/commits/x1/replies' => [pageJson([])], + 'GET /api/v1/commits/y1/replies' => [pageJson([])], + ]); + $screen = finishRefreshes(Native::visit('/log/commits/c1'))->assertSee("Ada's p3")->assertSee('Under the last part'); + + // Typing a reply builds the commit the page is about once, for its draft, and none of the parts after it. + expect(rowsBuiltBy(fn () => $screen->input('reply-input', 'N')))->toBe(['c1']) + ->and(rowsBuiltBy(fn () => $screen->input('reply-input', 'Nice')))->toBe([]); + + $changes = [ + 'its replies opened' => fn () => $screen->tap('replies-c1')->assertSee('Grace answers'), + 'its replies closed' => fn () => finishRefreshes($screen->tap('replies-c1')), + 'the time' => function () use ($screen) { + $this->travel(2)->hours(); + $screen->call('navTitle'); + }, + 'the page moved to a later part' => fn () => finishRefreshes($screen->tap('commit-p2')->assertSet('id', 'p2')), + ]; + + foreach ($changes as $change) { + $change(); + expectKeptRowsMatchFreshOnes($screen, CommitDetail::class, 'replyRows', null); + } +}); From d6e784ea4e18ad8b8d5dda87ba4c63947e21d8d2 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 00:55:11 +0000 Subject: [PATCH 08/18] 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 8521514565c4d281c522f1625fb530c6052af4e4 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:12:49 +0000 Subject: [PATCH 09/18] 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 13b2000e..17fa1da5 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -296,11 +296,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 a65a36f2..a375fb1b 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 a3dd5046..d63cbb06 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 f9ad023b..365ddffd 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 32a670cf..663e8f88 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 38cc75fc..6af30cc4 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; @@ -1208,3 +1209,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 720c29957de0791a96351c4747cc15e401c78c80 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:15:14 +0000 Subject: [PATCH 10/18] 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 365ddffd..bafdcc21 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 e16fcd6364ef8e12320305dc79e29c2cfc2216e9 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:15:37 +0000 Subject: [PATCH 11/18] 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 78bf193d..3ed3fa4b 100644 --- a/app/NativeComponents/Organization.php +++ b/app/NativeComponents/Organization.php @@ -54,11 +54,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 8983537fed57cd53d01da064f8d5e92860d60ddd Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:16:44 +0000 Subject: [PATCH 12/18] 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 17fa1da5..a061e7cb 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -295,14 +295,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 data(string $key, mixed $default = null): mixed { return $this->embedded ? ($this->conversationData[$key] ?? $default) : parent::data($key, $default); 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 dffc4aee9c5417d6b62423a0563d5576bf59288d Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:17:19 +0000 Subject: [PATCH 13/18] 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 833ae1e49fecc77701fd14f82ad402b67e1d6549 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:18:33 +0000 Subject: [PATCH 14/18] 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 825499e9d665177c0e38cbedbbc85e16b7cb5394 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:19:22 +0000 Subject: [PATCH 15/18] 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 663e8f88..1e93e4bb 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 516a95f36fe490031175ad9c7486f681634e85f2 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:19:53 +0000 Subject: [PATCH 16/18] 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 afbc04dd..ab3fdf1e 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 71d3c07c6f0440e397093e98c623e2b9887668ea Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 01:20:44 +0000 Subject: [PATCH 17/18] 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 a375fb1b..93b01241 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); +}); From a4f7fcf577a880d5cdf03bca0aaed6c81692a3d5 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 25 Nov 2026 12:18:56 +0000 Subject: [PATCH 18/18] Keep the commit page in step on the phone as it moves around its tree The commit page's commits are now kept between frames and sent as reuse markers where the phone holds them. On main the page also moves to another commit in its tree without a new scroll view, and the commits above open their replies in place. The partial frames case for the commit page now moves up to the parent, opens and folds the root's replies, moves back down and then down to a reply, and checks the phone's tree against a full frame after each step. Co-Authored-By: Claude Opus 5.5 --- tests/Feature/Screens/PartialFramesTest.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/Feature/Screens/PartialFramesTest.php b/tests/Feature/Screens/PartialFramesTest.php index 45bfa771..988742d4 100644 --- a/tests/Feature/Screens/PartialFramesTest.php +++ b/tests/Feature/Screens/PartialFramesTest.php @@ -210,7 +210,7 @@ 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 () { +it('keeps the commit page on the phone in step while you open the thread, type a reply and move around its tree', function () { sendPartialFrames(); $grace = userJson(['id' => 'u3', 'handle' => 'grace', 'name' => 'Grace']); fakeApi([ @@ -223,6 +223,15 @@ function servePartialFramePage(array $routes, string $starred): void )], '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' => []]], + 'GET /api/v1/commits/c0/replies' => [pageJson([ + commitJson(['id' => 'c1', 'parent_id' => 'c0', 'body' => 'The parent commit', 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada'])]), + replyJson(['id' => 'x1', 'parent_id' => 'c0', 'body' => 'Another reply to the root']), + ])], + 'GET /api/v1/commits/c1/replies' => [pageJson([commitJson(['id' => 'c2', 'parent_id' => 'c1', 'body' => 'The focused commit', 'replies_count' => 3])])], + 'GET /api/v1/commits/c1/related' => [['data' => []]], + 'GET /api/v1/commits/r2/replies' => [pageJson([])], + 'GET /api/v1/commits/r2/related' => [['data' => []]], + 'GET /api/v1/commits/x1/replies' => [pageJson([])], ]); $screen = Native::visit('/log/commits/c2'); @@ -238,6 +247,12 @@ function servePartialFramePage(array $routes, string $starred): void 'the replies hidden' => fn () => $screen->call('toggleReplies'), 'the reply field tapped again' => fn () => $screen->call('replyTapped'), 'the replies opened again' => fn () => $screen->call('toggleReplies'), + // The page moves to a commit above, keeping its scroll view and the commits it shows, and back down. + 'the page moved up' => fn () => $screen->call('openCommit', 'c1')->assertSet('id', 'c1'), + 'the replies above opened' => fn () => $screen->call('toggleReplies', 'c0')->assertSee('Another reply to the root'), + 'the replies above folded' => fn () => $screen->call('toggleReplies', 'c0')->assertDontSee('Another reply to the root'), + 'the page moved back down' => fn () => $screen->call('openCommit', 'c2')->assertSet('id', 'c2'), + 'the page moved down to a reply' => fn () => $screen->call('openCommit', 'r2')->assertSet('id', 'r2'), ]; $sentInFull = [];