rusackas opened a new pull request, #41780:
URL: https://github.com/apache/superset/pull/41780
### SUMMARY
**Stacked on #39357 — do not merge before it.** The first two commits here
are that PR's branch (its diff will disappear from this one once it merges and
this is rebased). Marked draft until then.
#39357 fixes the code-split translation race (#35330) by inlining the Jed
language pack into the bootstrap HTML. That's correct but ships ~237KB raw /
~67KB gzipped of pack in every non-English full-page response, since HTML isn't
cacheable. This follow-up keeps the synchronous-configuration guarantee while
making the pack a first-class cacheable asset:
- `spa.html` emits `<script
src="/language_pack/<lang>/<version>/script.js">` **before the entry bundle**,
where `<version>` is a short content hash of the pack file (cached in-process
alongside the pack itself).
- The new endpoint serves `window.__SUPERSET_LANGUAGE_PACK__ = {…};` with
`Cache-Control: public, max-age=31536000, immutable` — browsers fetch the pack
**once per translation change** instead of once per page load, and cache-bust
automatically on upgrade. (The pre-existing unversioned
`/language_pack/<lang>/` fetch could serve packs up to a year stale after an
upgrade, thanks to `SEND_FILE_MAX_AGE_DEFAULT`.)
- A stale version in a cached HTML page still gets current content, served
`no-cache` so it can't pin under the wrong address.
- English emits no tag and pays nothing (unchanged).
- Packs supplied via `COMMON_BOOTSTRAP_OVERRIDES_FUNC` still ride the
bootstrap payload and suppress the script tag; `spa.html` stashes them on
`window` instead, so the historical #35330 workaround keeps working and takes
precedence.
- `preamble.ts`'s fallback chain is unchanged (bootstrap pack → window
global → async fetch), so a failed script load degrades gracefully.
- The endpoint is deliberately unauthenticated: translation catalogs are
static public content shipped in this repo, contain no user or tenant data, and
must load for anonymous principals (login page, embedded dashboards — note the
sibling `/language_pack/<lang>/` fetch endpoint's `@has_access` would 302 for
embedded anonymous users, which the script tag avoids).
- Embedded gets the same treatment: `EmbeddedView` passes the same template
context.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — no visual changes. Behavior change is in caching headers and HTML size.
### TESTING INSTRUCTIONS
```bash
pytest tests/unit_tests/translations/utils_test.py \
tests/unit_tests/views/test_language_pack_script.py \
tests/unit_tests/views/test_bootstrap_auth.py \
tests/unit_tests/views/test_base.py
cd superset-frontend && npx jest src/preamble.test.ts
```
Manual: set a non-English locale, load any page, and confirm (1) the
`<script src="/language_pack/…/script.js">` tag precedes the entry bundle, (2)
the response carries `immutable`, (3) a hard reload serves it from browser
cache, (4) translations render in code-split chunks on first paint.
### ADDITIONAL INFORMATION
- [x] Has associated issue: #35330 (follow-up to #39357)
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration
- [x] Introduces new feature or API (new unauthenticated
`/language_pack/<lang>/<version>/script.js` route)
- [ ] Removes existing feature or API
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]