From 159a2dc28ba3ff615ec95fa9c1f7c1bf2e2f047f Mon Sep 17 00:00:00 2001 From: D N <4661784+retyui@users.noreply.github.com> Date: Wed, 2 Dec 2026 14:28:28 +0100 Subject: [PATCH 1/3] fix(web): return a data URI from `result.uri` `uri` returned `base64`, i.e. the bare payload with the `data:image/jpeg;base64,` prefix stripped, so `` rendered nothing even though the README documents `uri` as the data URI on web and the example app feeds it straight back as an image source. `uri` is now the data URI and the stripped payload stays on `base64`. `toDataURL` is memoized so reading both getters costs one encode, not two. --- src/index.web.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/index.web.ts b/src/index.web.ts index aba5ad9..5a85820 100644 --- a/src/index.web.ts +++ b/src/index.web.ts @@ -99,7 +99,17 @@ class ImageEditor { throw new Error('Image cannot be created from canvas'); } - let _path: string, _uri: string; + let _path: string; + let _dataUri: string | undefined; + + // `canvas.toDataURL()` is expensive, so build the data URI only + // when `uri` or `base64` is actually read. + function getDataUri() { + if (_dataUri === undefined) { + _dataUri = canvas.toDataURL(type, quality); + } + return _dataUri; + } const result: CropResult = { width: canvas.width, @@ -114,15 +124,17 @@ class ImageEditor { } return _path; }, + // Unlike iOS/Android, the web has no file to point at, so `uri` + // is the data URI (see README) — usable directly as an `Image` + // `source`. `base64` stays the bare payload, as on the other + // platforms. get uri() { - return result.base64 as string; + return getDataUri(); }, get base64() { - if (!_uri) { - _uri = canvas.toDataURL(type, quality); - } - return _uri.split(',')[1]; - // ^^^ remove `data:image/xxx;base64,` prefix (to align with iOS/Android platform behavior) + // strip the `data:image/xxx;base64,` prefix (to align with + // iOS/Android platform behavior) + return getDataUri().split(',')[1] ?? ''; }, }; From bb42f1877107ea5dc82105efe23fce203f3991e9 Mon Sep 17 00:00:00 2001 From: D N <4661784+retyui@users.noreply.github.com> Date: Wed, 2 Dec 2026 14:29:40 +0100 Subject: [PATCH 2/3] fix(web): honor `includeBase64` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `includeBase64` was never read on web. `base64` was an always-present own getter, so `result.base64 !== undefined` even when the caller asked for nothing (iOS/Android omit the key), which makes feature-detection diverge per platform. Worse, anything that enumerates the result — `{...result}`, `JSON.stringify`, DevTools inspection — invoked the getter and paid for a full `canvas.toDataURL()` nobody requested. Define `base64` only when `includeBase64` is set, matching the native platforms. Note this is also the precondition for typing `cropImage`'s result conditionally: the web implementation now actually matches the `includeBase64`-keyed signature the native entry point declares. --- src/index.web.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/index.web.ts b/src/index.web.ts index 5a85820..4aa8086 100644 --- a/src/index.web.ts +++ b/src/index.web.ts @@ -131,13 +131,19 @@ class ImageEditor { get uri() { return getDataUri(); }, - get base64() { - // strip the `data:image/xxx;base64,` prefix (to align with - // iOS/Android platform behavior) - return getDataUri().split(',')[1] ?? ''; - }, }; + if (cropData.includeBase64) { + Object.defineProperty(result, 'base64', { + get() { + // strip the `data:image/xxx;base64,` prefix (to align with + // iOS/Android platform behavior) + return getDataUri().split(',')[1] ?? ''; + }, + enumerable: true, + }); + } + return result; }); } From e389fafcfe36b3a6d236c9d28a243edc6f03ac3a Mon Sep 17 00:00:00 2001 From: D N <4661784+retyui@users.noreply.github.com> Date: Wed, 2 Dec 2026 14:29:58 +0100 Subject: [PATCH 3/3] chore: add changeset for web uri/includeBase64 fixes --- .changeset/web-uri-include-base64.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .changeset/web-uri-include-base64.md diff --git a/.changeset/web-uri-include-base64.md b/.changeset/web-uri-include-base64.md new file mode 100644 index 0000000..e2d71ba --- /dev/null +++ b/.changeset/web-uri-include-base64.md @@ -0,0 +1,11 @@ +--- +'@react-native-community/image-editor': minor +--- + +fix(web): `result.uri` is now a data URI, and `includeBase64` is honored + +On web, `result.uri` returned the bare base64 payload, so `` rendered nothing — the documented behavior (and what iOS/Android return) is a URI. It is now a `data:` URI, and the bare payload stays on `result.base64`. + +`includeBase64` was never read on web: `result.base64` was always present, and reading it (or spreading the result, or `JSON.stringify`, or inspecting it in DevTools) triggered a full `canvas.toDataURL()` that was never asked for. `base64` is now defined only when `includeBase64` is true, matching native, and the data URI is computed once and shared between `uri` and `base64`. + +If you relied on the old web `result.uri` being the base64 payload, use `result.base64` (with `includeBase64: true`).