Set target es2024 in TS and Vite, drop browserslist - #3356
Merged
Conversation
- tsconfig target es2024: with noEmit, this only changes the default lib, allowing ES2024 APIs (Promise.withResolvers, Object.groupBy, etc.) - vite build.target es2024: Vite maps this to the oldest browsers with full ES2024 support. Pinned because the default (baseline-widely-available) is lower (safari16.4) and drifts across Vite versions. tsc only checks against lib types and nothing polyfills APIs, so this must stay in sync with the tsconfig target. - autoprefixer was an unused leftover from Tailwind v3 (no postcss config, nothing imports it), and the browserslist key was consumed only by it.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Spun off from #3354, where I wanted
Promise.withResolversin a test but tsc wouldn't let me. Then I found out our browserslist list setting is not being used by anything — autoprefixer went away with Tailwind v4.Changes
targetin tsconfig: es2023 → es2024, so tsc accepts ES2024 builtins likePromise.withResolversbuild.target: 'es2024'in the Vite config to match. Vite's default target is'baseline-widely-available', a browser list regenerated for each Vite major (currently Chrome 111 / Firefox 114 / Safari 16.4)Argument
targetin tsconfig can control two things: what syntax tsc emits and the defaultlibdeclarations for typechecking. We usenoEmitbecause we compile with Vite, so we only care aboutlib: it determines which builtin APIs the typechecker allows (Promise.withResolvers,Object.groupBy, etc.).Vite has its own target concept, and it only affects syntax: it rewrites newer syntax for older browsers, but if you call a too-new API, it doesn't polyfill or warn about it. 🤖 confirmed this by building
Promise.withResolvers()with targetsafari16.4: clean build, the call ships as-is, TypeError at runtime. That means tsc'slibis the only thing keeping unsupported APIs out of the code, so the tsconfig target has to line up with the browsers we actually support. This PR setsbuild.target: 'es2024', which Vite maps to the oldest browsers with full ES2024 support (Chrome 119, Safari 17.4, Firefox 145, per https://caniuse.com/sr-es15), and adds a safety test asserting the two targets are the same.The potential downside is that we are moving our target to browsers that might be too new. The worst one is Firefox, where full ES2024 support means 145 (Nov 2025). But that version requirement comes from a single feature that we're never going to call: per MDN,
Atomics.waitAsyncappeared in Firefox 145, while every other ES2024 feature was in by Firefox 128 (July 2024), and the ones we'd actually use (groupBy,withResolvers,isWellFormed) by 121 (Dec 2023).Alternatives
es2023for TS andbaseline-widely-availablefor Vite. Fine, butes2024has fun APIs we could use.es2024for TS but leave Vite on the default. Also most likely fine in practice, but feels bad.