Skip to content

Keep the week calendar and Coming up bar from firing a ResizeObserver error when resized - #2087

Closed
svaka2000 wants to merge 1 commit into
Open-Coding-Society:mainfrom
svaka2000:fix/week-view-resize-frame
Closed

svaka2000 wants to merge 1 commit into
Open-Coding-Society:mainfrom
svaka2000:fix/week-view-resize-frame

Conversation

@svaka2000

Copy link
Copy Markdown
Contributor

Two parts of a course home watch their own width with a ResizeObserver, a browser API that calls a function when an element's size changes:

  • The week calendar (mountWeekView in _projects/systems/courses/js/announcement-calendar/calendar-feed.js) switches to a narrow table, with a row per day, when it's under 640px wide.
  • The Coming up bar (CalendarTicker in calendar-ticker.js, same folder) starts sliding when its announcements don't fit on one line, and stops when they do. It only shows for signed-in visitors, since it reads Spring's calendar.

What changed:

  • Both switched layouts inside the observer's function, which changed the size of the element being watched while the observer was still reporting. The browser can't report a second size for the same element in the same frame, so it fired the error "ResizeObserver loop completed with undelivered notifications" and reported the size in the next frame. Not every resize fired it: in my runs that depended on whether the visitor was signed in and whether the Coming up bar was showing.
  • WebKit (Safari's engine) reports it as an uncaught error, and Chrome fires it at the page too (a window error listener gets it). Apart from the error, both parts still ended up in the right layout.
  • Now WidthWatcher (new, in width-watcher.js) compares the width in the observer's function. When it changed, it asks requestAnimationFrame for one redraw on the next frame, which reads the latest width. Both parts use it, and stop(), which their unmount calls, cancels a redraw that hasn't run.
  • The cost: for one frame (about 16 ms on a 60 Hz screen) the old layout shows at the new width before the new one is drawn.

Other notes:

  • Playwright opened the live CSA course home (/navigation/courses/csa/) in WebKit and in Chrome, with the Spring backend faked, once with main's code and once with this branch's.
    • Week calendar, signed out: making the window narrow enough for a row per day and then wide again fired the error twice on main (once each way) and never in the same runs on this branch. The table still switched between 2 rows (wide) and 5 rows (narrow).
    • Week calendar hidden and shown again: once on main in all three runs (WebKit signed in and out, Chrome signed out), never here. I hid the element that holds it by hand to test this. The course home doesn't do that, but a page with tabs could.
    • Coming up bar, signed in with three short events: resizing the window so the bar started sliding and then stopped fired the error twice on main. With only the week calendar fixed it still fired twice, and with both fixed it never did.
  • The new tests in _projects/systems/courses/tests/width_watcher.test.mjs (tests/width_watcher.test.mjs runs it) check that a new width is redrawn on the next frame and not inside the observer's function, that an observer call with the same width does nothing, and that stop() drops a redraw that hasn't run. The ticker's resize test now checks for the next frame too.
  • I added a line about it to the week calendar part of AGENTS.md, AGENTS_MD_DOCUMENTATION.md and the Courses README.

How to try it:

  1. Check out fix/week-view-resize-frame from svaka2000/Pages-JJ.
  2. Run node --test tests/width_watcher.test.mjs tests/calendar_ticker.test.mjs tests/week_row_tools.test.mjs.

…em reports no error

The course home's week calendar redrew its table inside its ResizeObserver callback when its width
crossed 640px, and the Coming up ticker started or stopped moving inside its own callback. Both
changed the size of the element being watched while the observer was still reporting. When nothing
else the page watches changed size in that frame, the browser fired "ResizeObserver loop completed
with undelivered notifications": WebKit (Safari's engine) reports it as an uncaught error, and
Chrome fires it at the page without logging it. A page that hides the week view and shows it again
got the same error.

WidthWatcher (js/announcement-calendar/width-watcher.js) keeps the width check in the callback and
runs the redraw on the next animation frame, once. mountWeekView and CalendarTicker use it, and
both cancel a redraw that hasn't run when they're unmounted.
@svaka2000

Copy link
Copy Markdown
Contributor Author

Combined into #2089 with the same commits.

@svaka2000 svaka2000 closed this Nov 26, 2026
jm1021 pushed a commit that referenced this pull request Nov 26, 2026
…esizeObserver error

Branch fix/week-view-resize-frame, head 07d5610.
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.

1 participant