Skip to content

Commit a59e668

Browse files
authored
fix(dotcom): serve source maps instead of stripping them from the deploy (tldraw#9327)
In order to make deployed tldraw.com builds debuggable in browser devtools and stop the source-map 404s, this PR stops stripping `.js.map` files from the client deploy and serves them publicly. Closes tldraw#9322. The client build generated source maps, uploaded them to Sentry, then deleted the `.js.map` files from the deployed assets — while leaving the `//# sourceMappingURL` comments in the shipped JS. That produced a 404 for every map and left browser devtools unable to symbolicate deployed builds. The usual reason to hide source maps is to keep source private, which does not apply here since the client source is public in this repo. Sentry upload is unaffected: it reads from `dist/assets` before the strip step. ### Change type - [x] `bugfix` ### Test plan 1. From the preview deploy, open devtools → Network, reload, and confirm `*.js.map` requests return 200 rather than 404. 2. Open a minified stack frame in devtools and confirm it symbolicates to real names and lines. ### Code changes | Section | LOC change | | -------------- | ---------- | | Config/tooling | +7 / -3 |
1 parent 88bcbe5 commit a59e668

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

apps/dotcom/client/scripts/build.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { mkdirSync, readFileSync, readdirSync, writeFileSync } from 'fs'
22
import { T } from '@tldraw/validate'
33
import { config } from 'dotenv'
4-
import { glob } from 'fast-glob'
54
import json5 from 'json5'
65
import regexgen from 'regexgen'
76
import { exec } from '../../../../internal/scripts/lib/exec'
@@ -53,7 +52,10 @@ async function build() {
5352
await exec('rm', ['-rf', '.vercel/output'])
5453
mkdirSync('.vercel/output', { recursive: true })
5554
await exec('cp', ['-r', 'dist', '.vercel/output/static'])
56-
await exec('rm', ['-rf', ...glob.sync('.vercel/output/static/**/*.js.map')])
55+
// We serve the .js.map files publicly. The client source is open at tldraw/tldraw, so
56+
// there's nothing to hide, and serving the maps lets anyone debugging a deployed build get
57+
// real names and lines in devtools without going through Sentry. Sentry still gets its own
58+
// copy via the upload step, which reads from dist/assets before this point.
5759

5860
// Add fonts to preload into index.html
5961
const assetsList = readdirSync('dist/assets')
@@ -92,7 +94,9 @@ async function build() {
9294

9395
const multiplayerServerUrl = getMultiplayerServerURL() ?? 'http://localhost:8787'
9496

95-
const assetsToCache = assetsList.filter((f) => !f.endsWith('.js.map')).map((f) => `/assets/${f}`)
97+
// Includes the .js.map files: they're content-hashed like the chunks they describe, so they're
98+
// safe to cache immutably, and we now serve them rather than stripping them from the deploy.
99+
const assetsToCache = assetsList.map((f) => `/assets/${f}`)
96100
// need to batch these because Vercel's route limit is 4096 characters
97101
const assetsBatches: string[][] = []
98102
for (let i = 0; i < assetsToCache.length; i += 50) {

0 commit comments

Comments
 (0)