fix(training): load TeSS listings in the browser - #336
Merged
Merged
Conversation
The past events query sends include_expired=true, which adds ended events to the upcoming ones rather than returning ended events only. Combined with sort=new, which orders by creation date, anything recently added to TeSS lands at the top of "Past training events", so the two events created today would have been listed as past on the next build. I sort by start date now and drop whatever has not ended yet, fetching twice the page size so ten remain once those are gone.
The listings were fetched during the build, so the page only ever showed what TeSS had on the day of the last deploy. That was Aug 24, and both events added to TeSS today were missing from elixir.no while a local build showed them, which is what #335 reports. Each section is now a React island that asks TeSS when the page loads. It shows a skeleton while waiting and, if TeSS never answers, a link to browse the listing there instead. The request sends Accept: application/json and nothing else, which keeps it a simple CORS request; TeSS rejects the preflight with a 403, so any extra header would break it. With someone waiting on the page, the retry budget goes from 5 x 20s to 3 x 15s, and the build no longer depends on TeSS being up at all. Fixes #335
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new React hook does not guard against state updates after unmount, which can produce runtime warnings and should be fixed before merging.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Moves TeSS listings on /training from build-time fetching to client-side fetching via small React “islands”, so production always reflects current TeSS data and deploys/CI aren’t impacted by TeSS availability.
Changes:
- Replace build-time TeSS fetch/rendering in
src/pages/training/index.astrowith React islands (TessEvents,TessMaterials) hydrated in the browser. - Update TeSS helper logic to use shorter retries/timeouts for interactive page loads and fix “past events” ordering/filtering.
- Remove the now-unused
tess-unavailable.astrocomponent and centralize TeSS “browse” URLs.
| File | Description |
|---|---|
| src/pages/training/index.astro | Switches TeSS sections to client-side React islands and uses centralized TeSS browse links. |
| src/lib/tess.ts | Adjusts retry/backoff for browser usage, fixes past-events sorting/filtering, and adds browseLinks. |
| src/components/tess-unavailable.astro | Removes build-time unavailable component no longer used by /training. |
| src/components/tess-listings.tsx | Adds React islands for events/materials with loading/empty/unavailable states and a client-side materials filter. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #335.
The training page fetched TeSS at build time, so it only ever showed the listings as they were on the day of the last deploy. That deploy ran on Aug 24, and both upcoming events were created on TeSS this morning, which is why elixir.no says nothing is coming up while a local build, fetching fresh, shows them.
I moved the fetch into the browser. Each section is a small React island (
src/components/tess-listings.tsx) that calls TeSS on load, shows a skeleton while it waits, and falls back to a link to TeSS if three tries don't get an answer. The request sendsAccept: application/jsonand nothing else. That keeps it a simple CORS request, which matters because TeSS answers a preflight with a 403; the JSON responses themselves carryaccess-control-allow-origin: *, so the browser takes them without complaint.While checking this I found a second bug, fixed in its own commit. The past events query uses
include_expired=true, which adds ended events to the upcoming ones instead of returning only ended events, andsort=neworders by creation date, so a redeploy today would have put both new events at the top of "Past training events". It now sorts by start date and drops anything that hasn't ended.Side effects worth knowing:
test-pages.mjscan't see these hrefs now, sosafeUrlinsrc/lib/tess.tsis the only thing keeping a non-http(s) URL from the feed out of the pageTesting:
astro check0 errors, 303 pages built,test:slugsandtest:pagespass