Fix truncation of compiled theme assets when content contains non-ASCII characters #6729
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.
WHY are these changes introduced?
Fixes #0000 (no issue filed yet)
When running shopify theme dev, the locally-generated compiled assets (for example /compiled_assets/styles.css and the compiled scripts) can be unexpectedly truncated when the aggregated content includes non-ASCII characters (for example Chinese/Japanese comments).
Root cause: the server response metadata sets size using JavaScript string.length (UTF-16 code units), but that value is used as a byte-based Content-Length. For multi-byte UTF-8 characters, string.length underestimates the true byte length, so clients stop reading early and the response appears cut off.
WHAT is this pull request doing?
Updates the compiled theme asset handlers to compute response sizes using UTF-8 byte length (Buffer.byteLength(...)) instead of string.length.
Prevents truncated responses for compiled CSS/JS when content contains multi-byte characters.
No functional change for pure ASCII content.
How to test your changes?
Create or use a theme that contains a {% stylesheet %}...{% endstylesheet %} block with non-ASCII characters (for example Chinese comments) in a snippets/ or sections/ .liquid file.
Run the theme dev server:
shopify theme dev --store
Fetch the compiled stylesheet and verify it is not truncated:
curl -s "http://127.0.0.1:9292/compiled_assets/styles.css" | tail -n 50 curl -sI "http://127.0.0.1:9292/compiled_assets/styles.css" | grep -i content-length curl -s "http://127.0.0.1:9292/compiled_assets/styles.css" | wc -c
Repeat for the compiled scripts endpoint (if applicable in your environment) and confirm the response is complete.
(Optional) Remove the non-ASCII characters and confirm behavior remains unchanged.
Expected result: the returned CSS/JS content includes the full output and the Content-Length matches the actual byte size of the response body.
Post-release steps
n/a
Measuring impact
[x] n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
[ ] Existing analytics will cater for this addition
[ ] PR includes analytics changes to measure impact
Checklist
[x] I've considered possible cross-platform impacts (Mac, Linux, Windows)
[ ] I've considered possible documentation changes