Skip to content

Commit e64bd07

Browse files
Cherrylilnasy
andauthored
fix: better assetsInlineLimit runtime type checking (#10154)
* fix: string assetsInlineLimit * fix: better handle NaN values for `assetsInlineLimit` * chore: prettier * chore: simplify for requested changes * chore: update changeset * chore: remove tests * chore: simplify function * Apply suggestions from code review --------- Co-authored-by: Arsh <[email protected]>
1 parent aa45eb9 commit e64bd07

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

.changeset/late-bears-collect.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"astro": patch
3+
---
4+
5+
Fixes an issue where `config.vite.build.assetsInlineLimit` could not be set as a function.

packages/astro/src/core/build/plugins/util.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,13 @@ export function shouldInlineAsset(
7575
assetPath: string,
7676
assetsInlineLimit: NonNullable<BuildOptions['assetsInlineLimit']>
7777
) {
78-
if (typeof assetsInlineLimit === 'number') {
79-
return Buffer.byteLength(assetContent) < assetsInlineLimit;
80-
}
81-
82-
const result = assetsInlineLimit(assetPath, Buffer.from(assetContent));
83-
if (result != null) {
84-
return result;
78+
if (typeof assetsInlineLimit === 'function') {
79+
const result = assetsInlineLimit(assetPath, Buffer.from(assetContent));
80+
if (result != null) {
81+
return result;
82+
} else {
83+
return Buffer.byteLength(assetContent) < 4096; // Fallback to 4096kb by default (same as Vite)
84+
}
8585
}
86-
87-
return Buffer.byteLength(assetContent) < 4096; // Fallback to 4096kb by default (same as Vite)
86+
return Buffer.byteLength(assetContent) < Number(assetsInlineLimit);
8887
}

0 commit comments

Comments
 (0)