ai generated solutions to our ai generated problems

This commit is contained in:
2026-06-20 00:43:44 +01:00
parent fb773489f5
commit 22bff51147
7 changed files with 218 additions and 35 deletions
-1
View File
@@ -38,7 +38,6 @@
} catch {}
window.__TSS_BOOT_PREFERENCES__ = { analyticsPreferences, theme }
window.__TSS_BOOT_DATA__ = __TSS_BOOT_DATA__
document.documentElement.dataset.theme = theme
document.documentElement.style.colorScheme = theme
document.querySelector('meta[name="theme-color"]')?.setAttribute(
+4 -3
View File
@@ -1,8 +1,9 @@
# Static Public Data
The frontend tries these JSON snapshots before falling back to the live API by
default. The web server serves `/data/*` from the public data cache and fills
missing snapshots from the matching `/api/tss/*` route with a short timeout.
The web server serves `/data/*` from the same public data cache used by
`/api/tss/*`, and fills missing snapshots from the matching API route with a
short timeout. The frontend uses `/api/tss/*` by default; set
`VITE_STATIC_DATA=true` only for static-first experiments.
- `/data/leaderboard-teams.json`
- `/data/leaderboard-players.json`
+1 -1
View File
@@ -52,7 +52,7 @@ const siteVersion = '1.0.1'
const turnstileSiteKey = import.meta.env.VITE_TURNSTILE_SITE_KEY || ''
const siteGateEnabled = String(import.meta.env.VITE_SITE_GATE || 'false').toLowerCase() === 'true'
const staticDataBase = (import.meta.env.VITE_STATIC_DATA_BASE || '/data').replace(/\/+$/, '')
const staticDataEnabled = String(import.meta.env.VITE_STATIC_DATA || 'true').toLowerCase() !== 'false'
const staticDataEnabled = String(import.meta.env.VITE_STATIC_DATA || 'false').toLowerCase() === 'true'
const missingStaticDataPaths = new Set()
const defaultAnalyticsPreferences = {
+50 -1
View File
@@ -2,4 +2,53 @@ import { createRoot } from 'react-dom/client'
import './styles.css'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(<App />)
const root = document.getElementById('root')
async function fetchBootJson(path) {
const response = await fetch(path, { headers: { Accept: 'application/json' } })
if (!response.ok) throw new Error(`Boot request failed with ${response.status}`)
return response.json()
}
async function preloadBootData() {
if (!root?.dataset.tssFallback) return
const pathname = window.location.pathname
const timeout = new Promise((_, reject) => {
window.setTimeout(() => reject(new Error('Boot preload timed out')), 1500)
})
const load = async () => {
if (pathname === '/') {
const [homeTeams, live] = await Promise.all([
fetchBootJson('/data/home-teams.json'),
fetchBootJson('/data/recent-games.json'),
])
return { homeTeams, live }
}
if (pathname === '/teams') {
return { leaderboard: await fetchBootJson('/data/leaderboard-teams.json') }
}
if (pathname === '/players') {
return { playerLeaderboard: await fetchBootJson('/data/leaderboard-players.json') }
}
if (pathname === '/battle-logs' || pathname === '/live') {
const [live, leaderboard] = await Promise.all([
fetchBootJson('/data/recent-games.json'),
fetchBootJson('/data/leaderboard-teams.json'),
])
return { live, leaderboard }
}
return null
}
window.__TSS_BOOT_DATA__ = await Promise.race([load(), timeout]).catch(() => null)
}
preloadBootData().finally(() => {
createRoot(root).render(<App />)
})