From ecaadf936bd82b170683caff88b62354b2c4dd35 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 20:27:55 +0000 Subject: [PATCH 1/6] =?UTF-8?q?Ask=20for=20your=20past=C3=A9is=20once=20a?= =?UTF-8?q?=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 7e70e67c..188236f5 100644 --- a/app/Devnull/RowInputs.php +++ b/app/Devnull/RowInputs.php @@ -24,13 +24,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 2c3ad106b5a7451545d1ea6b3a2304e3e01571ad Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 20:30:40 +0000 Subject: [PATCH 2/6] 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 74d9e1da..ac57b37f 100644 --- a/resources/views/native/partials/feed.blade.php +++ b/resources/views/native/partials/feed.blade.php @@ -5,8 +5,8 @@ with "Show more" under the last, and a reply's own replies opened under it one step in (see App\Devnull\ThreadRows). The commit's rail runs on past them when its author's run goes on below. - 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 @@ -16,11 +16,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()) @@ -32,11 +39,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 ebee83bc..13f32dfe 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" > @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" @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 c97e6bee..a478e0d5 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 29f914c8..bcd42a72 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 61117acc..34fcede2 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 ac42f0e6eb77b1fe614c9853bc1b5a6b9968719b Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 20:32:01 +0000 Subject: [PATCH 3/6] 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 5d3dc681..276688e9 100644 --- a/app/NativeComponents/Log.php +++ b/app/NativeComponents/Log.php @@ -244,6 +244,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. * @@ -431,6 +439,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 @@ -438,19 +450,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 3b920893e18955795768a4eee86b3bb2321ef785 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 20:34:12 +0000 Subject: [PATCH 4/6] 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 188236f5..207b153c 100644 --- a/app/Devnull/RowInputs.php +++ b/app/Devnull/RowInputs.php @@ -43,6 +43,8 @@ public static function for(Commit $commit, array $scope): array 'tombstoneReplies' => array_key_exists($commit->id, $scope['tombstoneReplies'] ?? []), 'shown' => [self::changing($commit), $commit->quotedCommit === null ? null : self::changing($commit->quotedCommit)], 'poll' => [$scope['pollChoices'][$commit->id] ?? null, in_array($commit->id, $scope['voting'] ?? [], true)], + // 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 5e3c17adbb09a9bc0b08f11b45c0e82195970cf4 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 20:36:39 +0000 Subject: [PATCH 5/6] 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 207b153c..e87342d4 100644 --- a/app/Devnull/RowInputs.php +++ b/app/Devnull/RowInputs.php @@ -33,8 +33,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 edb1490b27f54ee911f8642e97aa5fd72116b8a0 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 20:36:39 +0000 Subject: [PATCH 6/6] 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 | 5 ++- .../native/partials/related-commits.blade.php | 8 ++-- tests/Feature/Screens/RowCacheScreensTest.php | 41 +++++++++++++++++-- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 7e6d818b..5f285779 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -219,7 +219,9 @@ class CommitDetail extends NativeComponent public int $scrollKey = 0; /** - * 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 0f717874..9f73ee65 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -41,7 +41,7 @@ @foreach ($rows as $row) @php($isFocused = $row->commit->id === $commit?->id) @php($hasThread = $isFocused && $repliesShown && $replies !== []) - @include('native.partials.commit-row', [ + @php($threadRow = [ 'commit' => $row->commit, 'previousLane' => $row->previousLane, 'continuesRun' => $row->continuesRun, @@ -53,6 +53,9 @@ 'withTail' => ! $loop->last, 'hairline' => ! ($loop->last && $relatedBelow), ]) + {{-- Kept like the replies, so typing a reply only builds the reply bar. The commit a page is about also shows its replies' toggle and count, and its time in your timezone. --}} + @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) + @php($replyRows->include('thread-'.$row->commit->id, [...\App\Devnull\RowInputs::for($row->commit, $rowScope), 'focused' => $isFocused ? [$repliesShown, $replyCount, app(\App\Devnull\Timezone::class)->yours()] : null], 'native.partials.commit-row', $threadRow, $rowScope)) @if ($isFocused && $repliesShown && $replies === [] && ! $repliesLoaded && $error === null) diff --git a/resources/views/native/partials/related-commits.blade.php b/resources/views/native/partials/related-commits.blade.php index 452eaedf..9c886017 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, @@ -28,7 +30,7 @@ 'seriesExpanded' => false, 'threadBelow' => false, 'withTail' => ! $loop->last, - ]) + ], $rowScope)) @endforeach @endif diff --git a/tests/Feature/Screens/RowCacheScreensTest.php b/tests/Feature/Screens/RowCacheScreensTest.php index 902cbd0d..2befa18d 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. The last - // reply of a page changes when the next page comes, since it no longer carries "more". - expect(rowsBuiltBy(fn () => $screen->call('navTitle')))->toBe(['c2']) - ->and(rowsBuiltBy(fn () => $screen->call('loadMoreReplies')->assertSee('Third reply')))->toBe(['c2', 'r2', 'r3']); + // The last reply of a page changes when the next page comes, since it no longer carries "more". + expect(rowsBuiltBy(fn () => $screen->call('navTitle')))->toBe([]) + ->and(rowsBuiltBy(fn () => $screen->call('loadMoreReplies')->assertSee('Third reply')))->toBe(['r2', '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); + } +});