Commit 23361b8
authored
feature(docs): improve logic for asset origin fix (tldraw#8768)
### Problem
Docs and marketing are two separate Next apps on Vercel. When marketing
rewrites a path (e.g. `tldraw.dev/quick-start`) and returns docs HTML,
the browser’s address bar is still the marketing origin, but the HTML
referenced `/_next/static/...` as root-relative paths. Those requests
went to marketing’s `/_next` (wrong app / wrong hashes) instead of docs’
`/_next`.
Setting `ASSET_PREFIX` only in some environments (or only on Production)
was easy to get wrong: Preview builds often had no prefix, and
Production could pin the wrong hostname (e.g. a `*.vercel.app` alias)
while the live site was `tldraw.dev`, which caused 404s, cache skew (old
HTML vs new static files), and confusion.
### What we changed
`assetPrefix` (and the same base for `assetUrl()` on `public/` paths)
now resolves to:
1. `ASSET_PREFIX` when set (explicit override), else
2. `https://${VERCEL_URL}` on Vercel (the current deployment URL), else
3. unset locally → root-relative assets as before.
### Why it helps
- Every Vercel build automatically points JS/CSS (and prefixed `public/`
URLs) at that deployment’s static host, without maintaining
Preview-specific `ASSET_PREFIX` for every branch.
- `ASSET_PREFIX` remains an escape hatch when you need a fixed canonical
origin (e.g. force the apex in prod).
- Docs HTML served through rewrites still loads `/_next` from the docs
deployment that produced the page, which removes the “wrong `/_next`
host” class of bugs.
### Change type
- [ ] `bugfix`
- [x] `improvement`
- [ ] `feature`
- [ ] `api`
- [ ] `other`1 parent 32d04ed commit 23361b8
3 files changed
Lines changed: 77 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
6 | 16 | | |
7 | 17 | | |
8 | | - | |
| 18 | + | |
9 | 19 | | |
10 | 20 | | |
11 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | | - | |
| 13 | + | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
16 | | - | |
| 19 | + | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
| 23 | + | |
19 | 24 | | |
20 | 25 | | |
21 | | - | |
| 26 | + | |
| 27 | + | |
22 | 28 | | |
23 | 29 | | |
24 | 30 | | |
25 | 31 | | |
26 | | - | |
| 32 | + | |
| 33 | + | |
27 | 34 | | |
28 | 35 | | |
| 36 | + | |
29 | 37 | | |
30 | 38 | | |
31 | | - | |
| 39 | + | |
| 40 | + | |
32 | 41 | | |
33 | 42 | | |
34 | 43 | | |
35 | 44 | | |
36 | | - | |
| 45 | + | |
| 46 | + | |
37 | 47 | | |
38 | 48 | | |
| 49 | + | |
39 | 50 | | |
40 | 51 | | |
41 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
42 | 82 | | |
43 | 83 | | |
44 | 84 | | |
45 | 85 | | |
46 | | - | |
| 86 | + | |
| 87 | + | |
47 | 88 | | |
48 | 89 | | |
| 90 | + | |
49 | 91 | | |
50 | 92 | | |
51 | 93 | | |
52 | | - | |
| 94 | + | |
| 95 | + | |
53 | 96 | | |
54 | 97 | | |
55 | 98 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
1 | 11 | | |
2 | 12 | | |
3 | | - | |
4 | | - | |
5 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
6 | 16 | | |
0 commit comments