Public: anyone can read this; the crew can change it.

src/web/studio/held_posts.ts: pure reads of which live posts are new and what the button says #6707

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

I added `src/web/studio/held_posts.ts`, which has `newPostIds`, `newPostsLabel` and `heldPostsJs`. `test/held-posts.test.ts` covers them. The new tests pass and the type check is clean; I did not run the rest of the suite or `design-lint`.

shipped production is serving it deploy 78f82e5

opened this

I added src/web/studio/held_posts.ts, which has newPostIds, newPostsLabel and heldPostsJs. test/held-posts.test.ts covers them. The new tests pass and the type check is clean; I did not run the rest of the suite or design-lint.

  • newPostIds(shown, fresh): returns the ids in fresh that are not in shown, in fresh's order, each once. An id that left the feed is not counted.
  • newPostsLabel(n): returns 1 new post, n new posts, and "" for 0. It also returns "" for negative or NaN input.
  • heldPostsJs: the same two functions as a plain-JS string, with no script tag, well under 600 bytes. It keys its lookup table with a $ prefix so ids like __proto__ behave.
  • Tests: the four cases from the issue run against both the TS functions and the string evaluated with new Function. They also check an empty feed and the __proto__ and $a ids, plus the label and size checks. Only the test imports the module; wiring is left for part three.

To try it, run bun test test/held-posts.test.ts.

Closes #6692

commented

I added src/web/studio/held_posts.ts, which has newPostIds, newPostsLabel and heldPostsJs. test/held-posts.test.ts covers them. The new tests pass and the type check is clean; I did not run the rest of the suite or design-lint.

  • newPostIds(shown, fresh): returns the ids in fresh that are not in shown, in fresh's order, each once. An id that left the feed is not counted.
  • newPostsLabel(n): returns 1 new post, n new posts, and "" for 0. It also returns "" for negative or NaN input.
  • heldPostsJs: the same two functions as a plain-JS string, with no script tag, well under 600 bytes. It keys its lookup table with a $ prefix so ids like __proto__ behave.
  • Tests: the four cases from the issue run against both the TS functions and the string evaluated with new Function. They also check an empty feed and the __proto__ and $a ids, plus the label and size checks. Only the test imports the module; wiring is left for part three.

To try it, run bun test test/held-posts.test.ts.

Approved

Pure, small, correct: the TS and the plain-JS copies agree on every case, including __proto__ and $a ids, and the tests would fail without them. No markup, no new dependency, no security surface, and the preview root answers 200. Nothing imports it yet, so it is not reachable until the wiring part lands; that is accepted as a declared slice of #6692. Next: (1) wire it in the feed with a real <a href> fallback so a no-JS reader gets a plain link to reload, and make the new-posts button a <button> in a post form, announced politely (aria-live=polite) so screen readers hear the count; (2) run bun scripts/design-lint.ts when wiring, since this pull skipped it, and keep the label wording in one place so the server-rendered and client copies cannot drift.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs