fix(i18n): keep production sourcemaps usable when the i18n plugin rewrites a chunk - #25691
Open
totally-not-ai[bot] wants to merge 2 commits into
Open
fix(i18n): keep production sourcemaps usable when the i18n plugin rewrites a chunk#25691totally-not-ai[bot] wants to merge 2 commits into
totally-not-ai[bot] wants to merge 2 commits into
Conversation
The i18n Vite plugin rewrote every chunk in generateBundle and replaced the chunk sourcemap with a MagicString map that has no sources, so all .map files of an application built with build.sourcemap enabled came out empty. The rewriting now happens in renderChunk, where the bundler composes the returned map with the one it already has for the chunk, and chunks the plugin does not touch keep their sourcemap as is. The registerChunk calls are now matched with a pattern that tolerates renamed bindings and rewritten string quotes, so the duplicate calls are removed and every chunk name marker is replaced also when the bundler has reformatted the rendered chunk. Related to #16679
The production test application now uses Hilla translations in two frontend modules, so that the i18n build plugin rewrites the chunk they end up in. Without them the plugin left every chunk untouched and the sourcemap test only covered the chunks the plugin does not rewrite. The sourcemap test also follows the imports of the entry bundle transitively and checks that the sources of a map are the original files, with their contents, instead of only counting them.
|
Contributor
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.



Summary
The Vaadin i18n build plugin replaced the sourcemap of every chunk with an empty one, so all
.mapfiles of an app built withbuild.sourcemapenabled were useless. The plugin now rewrites chunks at a point where the bundler keeps the original sourcemap, and leaves untouched chunks alone.Related to #16679
What changed
Behavior change: only apps that build with
build.sourcemapenabled are affected, and only for the better — their.mapfiles now contain the real sources instead of being empty. Chunk output itself is unchanged, so no API or runtime behavior changes for anyone else.rollup-plugin-vaadin-i18n.jsmoves the chunk rewriting fromgenerateBundletorenderChunk. The bundler then composes the map returned by the plugin with the map it already has for that chunk. Chunks the plugin does not touch returnnulland keep their sourcemap as is.generateBundlestill collects the translation keys.registerChunkcalls are now found with a regular expression instead of an exact string match. It tolerates a renamedi18nbinding and rewritten string quotes, so duplicate calls are removed and the chunk name marker is replaced also when the bundler has reformatted the rendered chunk.vite-productiontest app now uses Hilla translations in two frontend modules (via a small stub of@vaadin/hilla-react-i18n) and builds with sourcemaps on, so the tests actually run through the rewriting path.Test summary
.mapfile reachable from the entry bundle has non-emptysources, non-emptymappings, and the contents of each sourcereturn nullmust not drop maps the bundler producedregisterChunkwith its own served file name, and the marker is goneregisterChunkcalli18nbinding or rewrites the string quotesTests added on this branch:
SourceMapsIT.bundleSourceMapsPointToOriginalSources— rows 1, 2I18nChunkIT.chunkRegistersItselfUnderItsOwnName— rows 3, 4Left untested on purpose:
BundleAccessis a test helper that only downloads bundle files, so it is covered indirectly by both ITs.