Skip to content

Open the share panel at its full size the first time - #646

Merged
richshaw merged 8 commits into
mainfrom
claude/relaxed-dijkstra-cpx7zo
Oct 26, 2026
Merged

richshaw merged 8 commits into
mainfrom
claude/relaxed-dijkstra-cpx7zo

Conversation

@richshaw

@richshaw richshaw commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Fixes the polish point in #574's comment: the share panel opened small and grew on its first open on a page.

The problem

The share panel's code (the panel and its QR encoder) loaded only when the panel first opened, or as Publish and share was pressed. So the first open showed the heading and a spinner, then grew by about 200 px when the code arrived. A second open on the same page was fine.

Loading the code earlier isn't enough on its own. lazy waits a turn on a promise even when the module is already loaded, so the first render still shows the fallback, and React then keeps a fallback on screen for at least 300 ms (FALLBACK_THROTTLE_MS). I measured it: with the early load alone, the spinner still showed for about 280 ms.

The fix

  • The code loads after the page does. Share and Publish and share start loading the panel's code once a draft's or an open signup's page is idle (usePrefetchSharePanel, requestIdleCallback with a 2 s timeout). Safari has no requestIdleCallback, so there it starts 200 ms after the page shows. Closed and archived signups show neither button, so they don't load it.
  • Once the code is in, the panel shows in the same render. The panel's lazy now lives in load-share-panel.ts. Once the code has loaded, it gets an object whose then calls back at once, which lazy takes in the same render, so no fallback shows. The object isn't a real promise, so it stays private to that file and reaches nothing but lazy.
  • A failed load isn't kept. Only a load that worked is kept. A failed early load is tried again when the panel opens, and the fallback (the link, its copy button and "Couldn’t load the other ways to share. Reload to try again.") shows only if that fails too, as before.

Measured

Production build, with the click about 1 s after the page loads. The "before" numbers are the owner's, from pnpm dev; my own dev run of main gave the same picture, a spinner for about 280 ms on each.

How it opened Before After
Share, computer spinner, then 238 → 434 px 434 px from the first frame, no spinner
Share, phone spinner, then 270 → 462 px 462 px from the first frame, no spinner
Publish and share, computer spinner, then 260 → 456 px 456 px from the first frame, no spinner
Publish and share, phone spinner, then 270 → 462 px 462 px from the first frame, no spinner

The spinner can still show when the code hasn't arrived by the time of the click: a very slow connection with an instant click, or a failed early load. Then the panel loads and works as before.

Choices this makes

  • Every draft or open signup page now fetches about 7.5 kB gzip after it loads, whether or not the organizer shares. That is once per deploy, since the file is cached. Fetching only on hover or focus would miss taps on a phone, which have no hover.
  • No taller fallback. The owner suggested this as an alternative. With the code usually in, the fallback is rare, and its right height depends on the message and the phone or computer layout, so I left it as it is.

Tests

  • Unit: prefetch-share-panel.test.tsx (new):

    • the code is asked for once the page is idle and not before;
    • it isn't asked for if the page goes before it's idle;
    • Safari's 200 ms wait;
    • the first open shows the whole panel in the same render once the page's own load is in;
    • the first open shows the fallback while the code is still loading.

    load-share-panel.test.tsx: a load that failed ahead isn't kept, so opening tries again. Each of these tests fails when the fix is broken in the way it covers: an early load that doesn't keep the panel, a lazy that always waits on a promise, and a failed load that is kept.

  • Passed on c0ec83d, with main through Add a help page on closing and reopening a signup #650 merged in: pnpm lint && pnpm typecheck && pnpm knip && pnpm test (1770), pnpm build && pnpm budgets with CI's build settings, and the full chromium e2e with CI=1 (88). Each earlier time main moved (Show the whole keyboard focus ring on the signup tabs #601, then Say which slot someone is taking in the sign-up sheet, "You're in." and the signed-up bar #602, Let a closed signup be reopened, through the service and the REST API #604 and Give the AI connector a reopen_signup tool #605), the head passed the unit tests, the budgets and the publish and share e2e specs; the only conflicts were the CHANGELOG, where both sides' entries are kept, and budgets.json, below.

  • Independent checks: a code review by an agent that didn't write the change found nothing blocking, and this PR's second commit fixes its findings. The reviewer checked the instant then against Next's bundled React 19.2 (production and development) as well as the react 19.0 the tests use. A tophat on the production build, at 1280 and 390, passed:

    • fast and slow clicks;
    • a delayed or failed panel file, and recovery after a failure;
    • focus on Copy link, Escape back to Share, a second open;
    • a closed signup never fetching the file;
    • no console errors.

Budgets

Every signup tab's first load grows by 142 B: the idle load and the instant then, measured against main at 28373e1. No budget changes: this PR had raised Responses from 130 to 131, after #601 left it no room, and main's #649 has since made the same raise along with the other signup tabs', so budgets.json is main's.

At c0ec83d, with CI's build settings, which bake in their own instance name and contact details:

Page First-load JS Budget
/app/signups/[id]/build 159.315 kB 160
/app/signups/[id]/responses 130.675 kB 131
/app/signups/[id]/settings 130.210 kB 131
/app/signups/[id]/edit, /app/signups/[id] 129.252 kB 130

Docs

  • CHANGELOG: the share panel's entry (After publishing, help the organizer share the link #505) now says when its code loads, and that a failed load is tried again when the panel opens.
  • The comments in SharePanel.tsx and ShareQrCode.tsx no longer say the code loads only when the panel opens.
  • Help and legal: no change. Nothing a help page describes changes, and nothing new is stored, sent or set as a cookie.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HoJtwsyrp6YC4DU9JAnc7H

The share panel's code loaded only when the panel first opened (or as
Publish was pressed), so a first open showed its heading and a spinner,
then grew about 200 px when the code arrived. Share and Publish and share
now fetch it once the page is idle (200 ms after it's shown in Safari,
which has no requestIdleCallback).

Fetching it early isn't enough on its own: lazy waits a turn on a promise
even when the module is cached, and React keeps a fallback up for 300 ms
once shown. So once the code is in, the panel's lazy gets a then that
calls back at once, and resolves in the same render.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HoJtwsyrp6YC4DU9JAnc7H
From the review: SharePanel's lazy now lives in load-share-panel.ts, so the
object that only has `then` reaches nothing but `lazy`. The CHANGELOG says
the panel usually opens at its full size, and that a failed load is tried
again when the panel opens; SharePanel's and ShareQrCode's comments no
longer say the code loads only when the panel opens.

Tests: the same-render test now relies on the page's own idle load, a
failed load is shown not to be kept, and the panel is mocked afresh in each
test, since a mocked module stays loaded through resetModules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HoJtwsyrp6YC4DU9JAnc7H
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HoJtwsyrp6YC4DU9JAnc7H
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HoJtwsyrp6YC4DU9JAnc7H
main's #601 (the tabs' focus ring) and this PR's idle load and instant
`then` together take the Responses tab to 130.018 kB, 18 B over 130.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HoJtwsyrp6YC4DU9JAnc7H
The CHANGELOG's only conflict: main's two new entries for #604 and #605
go after this branch's line for the share panel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HoJtwsyrp6YC4DU9JAnc7H
budgets.json was the only conflict, and main's side is kept: #649 raised
Responses to 131 itself, the raise this branch made, along with the other
signup tabs' budgets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HoJtwsyrp6YC4DU9JAnc7H
@richshaw richshaw added pipeline:tophat pipeline:ux Changes what a person using OpenSignup sees or does pipeline:working A session is working on it right now labels Oct 25, 2026 — with Claude

Copy link
Copy Markdown
Owner Author

Tophat: passed

Ran c0ec83d as a production build (pnpm build && pnpm start), because dev-server compiles would skew load timing. Postgres 16, Chromium at 1280×900 and 390×844 (phone with touch on). I signed in under pnpm dev first and reused that session. The data was made up: an open signup, two drafts and a closed signup ("Snack duty — Spring season" and similar), each with one slot. For the "before" rows I built and ran the PR's base, main at 1d4ff3a.

I measured with a Playwright script that waits a set time after the page loads, then clicks. It samples the open dialog's height and whether the spinner is showing on every animation frame for 1.5 s. It also logs which JS files load after the page's load event. The share panel's file is the only one that does (chunk 9777).

Check Result What I saw
Before (main), Share 1 s after load, computer / phone ✅ bug reproduced Spinner for 16–19 frames, then the panel grew 238 → 434 px / 270 → 462 px. The second open was full size
After, Share 1 s after load, computer / phone ✅ 434 px / 462 px on the first frame and every frame after it. No spinner frames. Same on a second open
After, Publish and share on a draft 1 s after load, computer / phone ✅ Published, and the panel was 456 px / 462 px from the first frame, with no spinner
What loads after the page: open and draft signups ✅ The panel's file is fetched about 250–370 ms after load on the Build tab. The closed signup's Build tab fetched nothing after load
Click right away (at domcontentloaded, before idle) ✅ as described Spinner, then 238 → 434 (computer) and 270 → 462 (phone), the same as before the PR. The panel loads and works
The early load fails once (file aborted on its first request) ✅ Opening tried again: spinner, then the full panel (238 → 434). No fallback, and a second open was full size
The file always fails (phone) ✅ The fallback ("Couldn’t load the other ways to share…" with the link chip) showed and was still there on a second open, as on main
Escape, then a second open ✅ Escape closed the panel and focus went back to Share. The panel reopened at full size
Neighbour: Responses tab › Share › Copy link ✅ The panel opened with the message, Copy message, Email it and the QR Download
Browser console and server log ✅ No console errors apart from the ERR_FAILED I caused on purpose by blocking the file. The server log had no errors except the health check's pgboss.job probe, which fails because the worker wasn't running

For the owner (UX): the first time an organizer opens Share or presses Publish and share on a page, the panel now opens at its full size. Before, it showed a small box with a spinner for about a quarter of a second and then jumped about 200 px taller. Once the code is in, nothing else about the panel looks different. If someone clicks within a few hundred ms of the page loading, or the early fetch fails, they get the old spinner-then-grow behaviour, and the panel still works. The cost is that every draft or open signup's tabs now fetch the panel's file (about 7.5 kB gzip, cached per deploy) after the page loads, even if the organizer never shares. Screenshots: 646-after-share-desktop, 646-after-share-phone, 646-after-publish-desktop, 646-after-publish-phone, 646-after-all-loads-fail (the fallback), and 646-before-share-desktop. These are all the settled panel, 1.6 s after the click. The before/after difference is in the per-frame heights in the table above.

Screenshots are in https://claude.ai/code/session_01MTLHRSYbwK1vKjngmLNWUb.


Generated by Claude Code

@richshaw richshaw added pipeline:review pipeline:working A session is working on it right now and removed pipeline:tophat pipeline:working A session is working on it right now labels Oct 25, 2026 — with Claude
@richshaw
richshaw requested a balanced review from Copilot October 25, 2026 23:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@richshaw richshaw left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: passed (round 1)

This PR loads the share panel's code once a draft's or open signup's page is idle (usePrefetchSharePanel in ShareButton and PublishButton, requestIdleCallback with a 2 s timeout, or a 200 ms timer where there's none). It also moves the panel's lazy into load-share-panel.ts, where a load that has already come in is handed to lazy through a then that calls back at once. React's lazy calls then and then checks whether the payload resolved during that call, so the panel renders in the same pass and no fallback (with its 300 ms throttle) shows. Only a load that worked is stored in loaded, so a failed early load is tried again when the panel opens, and the fallback still shows if that fails too. The fake thenable is module-private and only lazy gets it. Several mounted buttons (desktop and phone) each prefetch, but import() dedupes them. The prefetch hook calls the module's own loadSharePanel, so the count assertions in ShareButton.test.tsx and PublishButton.test.tsx still measure Publish's own load and aren't padded by the prefetch. Each behaviour the description claims has a unit test: idle-only fetch, cancel on unmount, the Safari timer, same-render open once loaded, the fallback while loading, and a failed load not being kept.

Blocking (0): none
Optional (0): none
Earlier threads: none. Copilot couldn't review (quota used up).
Checks: CI green on c0ec83d (lint-type-test, e2e, CodeQL). The tophat passed on this same SHA, as a production build, at 1280 and 390, so runtime code hasn't changed since. I went through the checklist: no services, schema or public routes are touched. Budgets are unchanged and the PR reports its pages under them. The CHANGELOG entry is updated, and no help or legal page describes when the code loads. No local runs were needed, since there were no findings to prove. The branch is behind main (#600, #643) with no conflict, and the merge stage updates it.

Why the owner: UX. The first Share or Publish and share on a page now opens the panel at full size instead of as a spinner that then grows about 200 px. Every draft or open signup's tabs also now fetch about 7.5 kB gzip after load, even when the organizer never shares. The tophat's per-frame heights table and screenshots (646-after-share-desktop, 646-after-share-phone, 646-after-publish-*, 646-after-all-loads-fail) show it.

https://claude.ai/code/session_01DFKGuYh28iFmKJaws6mXzT


Generated by Claude Code

@richshaw richshaw added pipeline:owner Passed; waits for the owner (UX or high-risk) pipeline:merge pipeline:working A session is working on it right now and removed pipeline:review pipeline:working A session is working on it right now pipeline:owner Passed; waits for the owner (UX or high-risk) labels Oct 25, 2026 — with Claude

Copy link
Copy Markdown
Owner Author

Approved by the owner at c0ec83d.

The branch is behind main with no conflict, so I'm updating it. The next run merges it once CI passes on the new head.

https://claude.ai/code/session_014qBeQRGx7pCq7m7Xv8ZCpD


Generated by Claude Code

@richshaw richshaw added pipeline:working A session is working on it right now and removed pipeline:working A session is working on it right now labels Oct 26, 2026 — with Claude
@richshaw
richshaw merged commit 2481bff into main Oct 26, 2026
5 checks passed
@richshaw
richshaw deleted the claude/relaxed-dijkstra-cpx7zo branch October 26, 2026 03:24
@richshaw richshaw removed pipeline:merge pipeline:ux Changes what a person using OpenSignup sees or does pipeline:working A session is working on it right now labels Oct 26, 2026 — with Claude
richshaw pushed a commit that referenced this pull request Oct 26, 2026
Through the server, telemetry and screen branches. No conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants