@@ -1834,3 +1834,99 @@ test("older-history prepend keeps the reading row fixed (no jump to oldest)", as
18341834 "Jump to latest" ,
18351835 ) ;
18361836} ) ;
1837+
1838+ // Regression: thread-summary badges must not flash during a scrollback prepend.
1839+ // When an older page lands, the urgent render pass still paints the OLD
1840+ // deferred message snapshot, so MessageTimeline passes `mainEntries=undefined`
1841+ // and TimelineMessageList rebuilds entries itself. That fallback used to drop
1842+ // the relay summary map — and since thread replies are usually not local
1843+ // timeline rows, every relay-driven badge unmounted for the whole deferred
1844+ // window and remounted when the heavy render committed (the visible flash).
1845+ // A MutationObserver is commit-granular, so it catches even a single-frame
1846+ // unmount that a polling assertion would race past.
1847+ test ( "thread summary badge survives an older-history prepend without unmounting" , async ( {
1848+ page,
1849+ } , testInfo ) => {
1850+ testInfo . setTimeout ( 60_000 ) ;
1851+ await installMockBridge ( page ) ;
1852+ await page . goto ( "/" ) ;
1853+ await page . waitForFunction (
1854+ ( ) => typeof window . __BUZZ_E2E_EMIT_MOCK_MESSAGE__ === "function" ,
1855+ ) ;
1856+
1857+ // Seed a reply to the NEWEST deep-history row before the channel is opened:
1858+ // no live subscription exists yet, so the reply lands only in the mock store.
1859+ // It is not a top-level timeline row, so the badge rendered for #599 is
1860+ // driven purely by the relay-shaped 39005 page summary — exactly the state
1861+ // the deferred-pass entry fallback used to drop.
1862+ await page . evaluate ( ( ) => {
1863+ window . __BUZZ_E2E_EMIT_MOCK_MESSAGE__ ?.( {
1864+ channelName : "deep-history" ,
1865+ content : "summary-only reply" ,
1866+ parentEventId : "mock-deep-history-599" ,
1867+ } ) ;
1868+ } ) ;
1869+
1870+ await page . getByTestId ( "channel-deep-history" ) . click ( ) ;
1871+ await expect ( page . getByTestId ( "chat-title" ) ) . toHaveText ( "deep-history" ) ;
1872+ const timeline = page . getByTestId ( "message-timeline" ) ;
1873+ const badgeSelector =
1874+ '[data-testid="message-thread-summary"][data-thread-head-id="mock-deep-history-599"]' ;
1875+ await expect ( timeline . locator ( badgeSelector ) ) . toBeVisible ( ) ;
1876+
1877+ const oldestRenderedIndex = ( ) =>
1878+ timeline . evaluate ( ( element ) => {
1879+ let min = Number . POSITIVE_INFINITY ;
1880+ for ( const row of (
1881+ element as HTMLDivElement
1882+ ) . querySelectorAll < HTMLElement > ( "[data-message-id]" ) ) {
1883+ const match = row . textContent ?. match ( / # ( \d + ) / ) ;
1884+ if ( match ) min = Math . min ( min , Number ( match [ 1 ] ) ) ;
1885+ }
1886+ return Number . isFinite ( min ) ? min : null ;
1887+ } ) ;
1888+ const oldestBefore = await oldestRenderedIndex ( ) ;
1889+ expect ( oldestBefore ) . not . toBeNull ( ) ;
1890+
1891+ // Arm the observer AFTER the initial window has settled, so the only
1892+ // mutations it sees are the prepend landing and any (buggy) badge unmount.
1893+ await timeline . evaluate ( ( element , selector ) => {
1894+ const scroller = element as HTMLDivElement ;
1895+ const win = window as typeof window & {
1896+ __SUMMARY_FLASH_PROBE__ ?: { missingCommits : number } ;
1897+ } ;
1898+ const probe = { missingCommits : 0 } ;
1899+ win . __SUMMARY_FLASH_PROBE__ = probe ;
1900+ new MutationObserver ( ( ) => {
1901+ if ( ! scroller . querySelector ( selector ) ) {
1902+ probe . missingCommits += 1 ;
1903+ }
1904+ } ) . observe ( scroller , { childList : true , subtree : true } ) ;
1905+ } , badgeSelector ) ;
1906+
1907+ // Scroll back until a genuinely older page has landed.
1908+ await timeline . hover ( ) ;
1909+ await expect
1910+ . poll (
1911+ async ( ) => {
1912+ await page . mouse . wheel ( 0 , - 4000 ) ;
1913+ await page . waitForTimeout ( 50 ) ;
1914+ return oldestRenderedIndex ( ) ;
1915+ } ,
1916+ { timeout : 20_000 } ,
1917+ )
1918+ . toBeLessThan ( oldestBefore ?? Number . POSITIVE_INFINITY ) ;
1919+
1920+ // The badge row must have stayed mounted through every DOM commit of the
1921+ // prepend — zero commits observed it missing — and still be attached now.
1922+ const missingCommits = await page . evaluate (
1923+ ( ) =>
1924+ (
1925+ window as typeof window & {
1926+ __SUMMARY_FLASH_PROBE__ ?: { missingCommits : number } ;
1927+ }
1928+ ) . __SUMMARY_FLASH_PROBE__ ?. missingCommits ,
1929+ ) ;
1930+ expect ( missingCommits ) . toBe ( 0 ) ;
1931+ await expect ( timeline . locator ( badgeSelector ) ) . toHaveCount ( 1 ) ;
1932+ } ) ;
0 commit comments