Skip to content

feat: add maxInlineSize option for size-based asset inlining#1378

Open
bartekkrok wants to merge 2 commits intocallstack:mainfrom
bartekkrok:feat/size-limit-for-inline-assets
Open

feat: add maxInlineSize option for size-based asset inlining#1378
bartekkrok wants to merge 2 commits intocallstack:mainfrom
bartekkrok:feat/size-limit-for-inline-assets

Conversation

@bartekkrok
Copy link
Copy Markdown

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

  1. Add an asset smaller than the threshold and one larger than the threshold to a
    React Native screen.
  2. Configure the assets loader with maxInlineSize: .
  3. Build the app — verify the small asset is inlined as a base64 URI and the large
    asset is extracted as a separate file.
  4. Alternatively, use the tester app (apps/tester-app) which already has assets set
    up for manual validation.
  5. Verify the option works both when passed directly to assets-loader and via
    getAssetTransformRules({ maxInlineSize: ... }).

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.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 7, 2026

@bartekkrok is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 7, 2026

🦋 Changeset detected

Latest commit: 4521cff

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@callstack/repack Major
@callstack/repack-plugin-expo-modules Major
@callstack/repack-plugin-nativewind Major
@callstack/repack-plugin-reanimated Major
@callstack/repack-dev-server Major
@callstack/repack-init Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

@MikitasK MikitasK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Comment on lines +228 to +231
const shouldInlineAsset =
options.inline === true ||
(options.maxInlineSize !== undefined &&
largestVariantSize <= options.maxInlineSize);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
maybe boolean type conversion might make it a bit more readable

Suggested change
const shouldInlineAsset =
options.inline === true ||
(options.maxInlineSize !== undefined &&
largestVariantSize <= options.maxInlineSize);
const shouldInlineAsset =
!!options.inline ||
(!!options.maxInlineSize &&
largestVariantSize <= options.maxInlineSize);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing ! I refered to Your comments in new commit.

Copy link
Copy Markdown

@MikitasK MikitasK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants