Compare commits

...

2 Commits

Author SHA1 Message Date
lebaudantoine 56c92a270f 🐛(frontend) subscribe useRoomData to the query cache
useRoomData read the room with getQueryData during render, without
subscribing. Consumers only updated because Conference observes the
same query and re-renders its subtree, so a consumer behind a memoized
component kept a stale value after a room settings or LiveKit metadata
update.

Subscribe to the query cache with useSyncExternalStore, filtered on
the room entry. The hook stays a passive reader: it adds no observer,
so it never fetches nor hands its own options to the query.
2026-11-17 00:01:35 +01:00
lebaudantoine 9ee68d9ddf ⚡️(frontend) animate floating reactions without rendering each frame
A floating reaction updated two states in requestAnimationFrame: the
component was rendered again on every frame, about 180 times during
the three seconds of its course, and moving it through its bottom
offset laid it out each time. A burst of reactions multiplies this by
the number of reactions on screen, during the call.

Describe the same course with the Web Animations API instead: a rise
at constant speed, with a fade out over the last 30 % of the course.
The browser runs it, the component is rendered once, and only the
transform and the opacity change.
2026-11-16 23:34:20 +01:00
3 changed files with 42 additions and 28 deletions
+2
View File
@@ -51,6 +51,8 @@ and this project adheres to
- ♿️(frontend) show the focus ring on connection test detail cards
- ♿️(frontend) use a heading for every connection test card title
- ♿️(frontend) put the ProConnect link label inside the link
- ⚡️(frontend) animate floating reactions without rendering each frame
- 🐛(frontend) subscribe useRoomData to the query cache
## [1.37.0] - 2026-11-01
@@ -1,5 +1,5 @@
import { createPortal } from 'react-dom'
import { useState, useEffect } from 'react'
import { useState, useEffect, useRef } from 'react'
import { Text } from '@/primitives'
import { css } from '@/styled-system/css'
import { useSnapshot } from 'valtio'
@@ -29,39 +29,35 @@ export function FloatingReaction({
speed = 1,
scale = 1,
}: FloatingReactionProps) {
const [deltaY, setDeltaY] = useState(0)
const [opacity, setOpacity] = useState(1)
const elementRef = useRef<HTMLDivElement>(null)
const [left] = useState(
() => Math.random() * window.innerWidth * REACTION_SPAWN_WIDTH_RATIO
)
useEffect(() => {
let start: number | null = null
function animate(timestamp: number) {
if (start === null) start = timestamp
const elapsed = timestamp - start
if (elapsed < 0) {
setOpacity(0)
} else {
const progress = Math.min(elapsed / ANIMATION_DURATION, 1)
const distance = ANIMATION_DISTANCE * speed
const newY = progress * distance
setDeltaY(newY)
if (progress > FADE_OUT_THRESHOLD) {
setOpacity(1 - (progress - FADE_OUT_THRESHOLD) / 0.3)
}
}
if (elapsed < ANIMATION_DURATION) {
requestAnimationFrame(animate)
}
}
const req = requestAnimationFrame(animate)
return () => cancelAnimationFrame(req)
const element = elementRef.current
if (!element) return
const distance = ANIMATION_DISTANCE * speed
const animation = element.animate(
[
{ transform: 'translateY(0)', opacity: 1 },
{
transform: `translateY(${-distance * FADE_OUT_THRESHOLD}px)`,
opacity: 1,
offset: FADE_OUT_THRESHOLD,
},
{ transform: `translateY(${-distance}px)`, opacity: 0 },
],
{ duration: ANIMATION_DURATION, easing: 'linear', fill: 'forwards' }
)
return () => animation.cancel()
}, [speed])
return (
<div
ref={elementRef}
className={css({
position: 'absolute',
display: 'flex',
@@ -70,8 +66,7 @@ export function FloatingReaction({
})}
style={{
left: left,
bottom: INITIAL_POSITION + deltaY,
opacity: opacity,
bottom: INITIAL_POSITION,
}}
>
<img
@@ -1,3 +1,5 @@
import { useCallback, useSyncExternalStore } from 'react'
import { hashKey } from '@tanstack/react-query'
import type { ApiRoom } from '@/features/rooms/api/ApiRoom'
import { useParams } from 'wouter'
import { keys } from '@/api/queryKeys'
@@ -5,6 +7,21 @@ import { queryClient } from '@/api/queryClient'
export const useRoomData = (): ApiRoom | undefined => {
const { roomId } = useParams()
const queryKey = [keys.room, roomId]
return queryClient.getQueryData<ApiRoom>(queryKey)
const subscribe = useCallback(
(onStoreChange: () => void) => {
const queryHash = hashKey([keys.room, roomId])
return queryClient.getQueryCache().subscribe((event) => {
if (event.query.queryHash === queryHash) onStoreChange()
})
},
[roomId]
)
const getSnapshot = useCallback(
() => queryClient.getQueryData<ApiRoom>([keys.room, roomId]),
[roomId]
)
return useSyncExternalStore(subscribe, getSnapshot)
}