Problem
Three patterns appear at every callsite in bench-review and have no framework support:
Loading boundaries
bench-review's pattern, repeated everywhere:
<ul :if="!commentsLoaded()">
<li :for="i in [1, 2]">skeleton...</li>
</ul>
<div :else-if="comments().length === 0">empty state</div>
<ul :else>
<li :for="c in comments()">{{ c.body }}</li>
</ul>That's three branches per data dependency. Multiply by ~15 fetched surfaces in bench-review = ~45 conditional branches.
The standard primitive is <Suspense>:
<Suspense fallback="<Skeleton count={2} />">
<CommentsList /> <!-- can throw a promise via useQuery suspense mode; Suspense catches and renders fallback -->
</Suspense>One boundary handles all descendant loading states.
Optimistic mutations
bench-review's "like a review" flow:
async function toggleLike() {
const prevLiked = liked()
liked.set(!liked()) // optimistic
likes.set(likes() + (liked() ? 1 : -1))
try {
await authStore.authFetch('/api/reviews/X/like', { method: 'POST' })
} catch {
liked.set(prevLiked) // rollback
likes.set(likes() - (liked() ? 1 : -1))
}
}That's a lot of manual snapshot/rollback. Vue + React both have first-class primitives:
const [optimisticLikes, addOptimistic] = useOptimistic(likes(), (current, delta) => current + delta)
async function toggleLike() {
addOptimistic(liked() ? -1 : 1)
try { await authStore.authFetch('/api/reviews/X/like', { method: 'POST' }) }
catch { /* useOptimistic auto-rolls back on the next render after the action settles */ }
}Enter/leave transitions
bench-review's dropdown reveal:
<div
x-class="bellOpen() ? 'opacity-100 translate-y-0' : 'opacity-0 -translate-y-2 pointer-events-none'"
class="transition-all duration-150"
>Pre-existing memory note (feedback_stx_xclass_static_in_array) flags how easy this is to get wrong. The standard primitive is <Transition>:
<Transition name="fade-slide" enter-from="opacity-0 -translate-y-2" enter-to="opacity-100 translate-y-0" leave-to="opacity-0 -translate-y-2">
<div :if="bellOpen()">...</div>
</Transition>For list transitions (adding/removing review cards), <TransitionGroup> with auto-FLIP positioning is the standard primitive.
Proposed: ship all three
<Suspense>:
- Catches any descendant component that's in a "suspended" state (via integration with P1.4's
useQuery) - Renders the
fallbackslot until all descendants resolve errorFallbackslot catches errors thrown during render- Nested
<Suspense>boundaries compose (inner fallback shows first, then outer when fully resolved)
useOptimistic(baseSignal, reducer):
- Returns
[optimisticValue, applyOptimistic] applyOptimistic(input)queues a pending update that's visible immediately- When the corresponding async action settles, the optimistic state is discarded and
baseSignalis the source of truth - Auto-rolls back on action error
<Transition> / <TransitionGroup>:
- Class-driven enter/leave transitions on
:iftoggle - FLIP positioning for list reorders
appearprop for first-mount transitions- JS hook props (
onEnter,onLeave) for advanced cases
Prior art
<Suspense>— React 18, Vue 3, SolidJS, Qwik. All have it.useOptimistic— React 19's official primitive, TanStack Query'sonMutatemechanic.<Transition>— Vue's built-in, SolidJS Transition, React's Framer Motion +<motion.div>.
Impact
<Suspense>reduces every fetched-data surface's conditional rendering by 50-70%.useOptimisticremoves the snapshot-rollback boilerplate from every mutation.<Transition>removes the hand-rolled x-class transition class strings (which have known footguns — seefeedback_stx_xclass_static_in_array).
Phasing
- Phase 1:
<Transition>(smallest, doesn't depend on other primitives) - Phase 2:
useOptimistic(depends on P1.4 if integrated withuseMutation, but works standalone too) - Phase 3:
<Suspense>(depends on P1.4'suseQueryto throw promises in suspended state)
Happy to PR Phase 1.