feat: add maxInlineSize option for size-based asset inlining#1378
feat: add maxInlineSize option for size-based asset inlining#1378bartekkrok wants to merge 1 commit intocallstack:mainfrom
Conversation
Assets whose largest scale variant is within the threshold are inlined as base64 URIs; larger assets are extracted as separate files. The option is supported in both the assets-loader directly and via getAssetTransformRules.
|
@bartekkrok is attempting to deploy a commit to the Callstack Team on Vercel. A member of the Team first needs to authorize it. |
|
MikitasK
left a comment
There was a problem hiding this comment.
overall, these changes looks good to me 👍
new maxInlineSize prop works like a charm 🚀 here's the recording:
Screen.Recording.2026-04-13.at.20.36.30.mp4
I'd just prefer to take into account a few things before merge:
| const shouldInlineAsset = | ||
| options.inline === true || | ||
| (options.maxInlineSize !== undefined && | ||
| largestVariantSize <= options.maxInlineSize); |
There was a problem hiding this comment.
nit:
maybe boolean type conversion might make it a bit more readable
| const shouldInlineAsset = | |
| options.inline === true || | |
| (options.maxInlineSize !== undefined && | |
| largestVariantSize <= options.maxInlineSize); | |
| const shouldInlineAsset = | |
| !!options.inline || | |
| (!!options.maxInlineSize && | |
| largestVariantSize <= options.maxInlineSize); |
There was a problem hiding this comment.
there's no automated coverage for new maxInlineSizeprop - nothing exercises new threshold behavior in either assets-loader.test.ts or getAssetTransformRules.test.ts. it'd be great cover this new logic with tests
Summary
Currently, the assets loader only supports two modes for asset delivery: always
extract as separate files or always inline as base64 URIs. There is no way to
automatically inline small assets (where the base64 overhead is negligible) while
still extracting large ones — developers had to choose one strategy for all assets
or manually split rules by path.
This PR adds a maxInlineSize option (in bytes) to both assets-loader and
getAssetTransformRules. Assets whose largest scale variant is within the threshold
are inlined as base64 URIs; larger assets are extracted as separate files. The
comparison uses the largest scale variant (e.g. @3x) intentionally — when an asset
is inlined, all variants are embedded in the bundle, so the largest one determines
the worst-case size impact.
Test plan
React Native screen.
asset is extracted as a separate file.
up for manual validation.
getAssetTransformRules({ maxInlineSize: ... }).