Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit 00da6b5

Browse files
authored
fix(mobile): stop shared content errors in Personal Team builds (pingdotgg#4943)
1 parent 6ab2f16 commit 00da6b5

3 files changed

Lines changed: 90 additions & 1 deletion

File tree

‎apps/mobile/src/features/sharing/IncomingShareProvider.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
type IncomingShareDestination,
1616
type IncomingShareDraft,
1717
} from "./incoming-share-model";
18+
import { createIncomingSharePayloadReader } from "./incoming-share-native";
1819
import { IncomingShareInbox } from "./incoming-share-inbox";
1920
import {
2021
loadIncomingShareDrafts,
@@ -48,6 +49,11 @@ function receiveSharingEnabled(): boolean {
4849
return Constants.expoConfig?.extra?.iosPersonalTeamBuild !== true;
4950
}
5051

52+
const getIncomingSharePayloads = createIncomingSharePayloadReader({
53+
platform: Platform.OS,
54+
readPayloads: getSharedPayloads,
55+
});
56+
5157
async function resolvedPayloadsForImages(): Promise<ReadonlyArray<ResolvedSharePayload>> {
5258
try {
5359
return await getResolvedSharedPayloadsAsync();
@@ -121,7 +127,7 @@ const incomingShareInbox = new IncomingShareInbox({
121127
loadDrafts: loadIncomingShareDrafts,
122128
writeDraft: writeIncomingShareDraft,
123129
removeDraft: removeIncomingShareDraft,
124-
getPayloads: getSharedPayloads,
130+
getPayloads: getIncomingSharePayloads,
125131
clearPayloads: clearSharedPayloads,
126132
buildDraft: async ({ payloads, id, createdAt }) => {
127133
const cleanupUris = new Set<string>();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { describe, expect, it, vi } from "@effect/vitest";
2+
import type { SharePayload } from "expo-sharing";
3+
4+
import { createIncomingSharePayloadReader } from "./incoming-share-native";
5+
6+
const PAYLOAD: SharePayload = {
7+
shareType: "text",
8+
mimeType: "text/plain",
9+
value: "Fix this",
10+
};
11+
12+
describe("createIncomingSharePayloadReader", () => {
13+
it("treats a missing iOS App Group as an unavailable inbox", () => {
14+
const readPayloads = vi.fn((): ReadonlyArray<SharePayload> => {
15+
throw Object.assign(new Error("Expo-sharing has failed to fetch the app group id"), {
16+
code: "ERR_FAILED_TO_RESOLVE_APP_GROUP_ID",
17+
});
18+
});
19+
const read = createIncomingSharePayloadReader({ platform: "ios", readPayloads });
20+
21+
expect(read()).toEqual([]);
22+
expect(read()).toEqual([]);
23+
expect(readPayloads).toHaveBeenCalledTimes(1);
24+
});
25+
26+
it("returns native payloads when receiving is available", () => {
27+
const read = createIncomingSharePayloadReader({
28+
platform: "ios",
29+
readPayloads: () => [PAYLOAD],
30+
});
31+
32+
expect(read()).toEqual([PAYLOAD]);
33+
});
34+
35+
it("preserves other native errors", () => {
36+
const error = new Error("native failure");
37+
const read = createIncomingSharePayloadReader({
38+
platform: "ios",
39+
readPayloads: () => {
40+
throw error;
41+
},
42+
});
43+
44+
expect(read).toThrow(error);
45+
});
46+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { SharePayload } from "expo-sharing";
2+
3+
const IOS_APP_GROUP_UNAVAILABLE_ERROR_CODE = "ERR_FAILED_TO_RESOLVE_APP_GROUP_ID";
4+
5+
function errorCode(error: unknown): string | null {
6+
if (typeof error !== "object" || error === null || !("code" in error)) {
7+
return null;
8+
}
9+
return typeof error.code === "string" ? error.code : null;
10+
}
11+
12+
/**
13+
* Normalizes the native "share into" capability to an empty inbox. Personal
14+
* Team builds cannot include the App Group that expo-sharing reads from.
15+
*/
16+
export function createIncomingSharePayloadReader(input: {
17+
readonly platform: string;
18+
readonly readPayloads: () => ReadonlyArray<SharePayload>;
19+
}): () => ReadonlyArray<SharePayload> {
20+
let isUnavailable = false;
21+
22+
return () => {
23+
if (isUnavailable) {
24+
return [];
25+
}
26+
27+
try {
28+
return input.readPayloads();
29+
} catch (error) {
30+
if (input.platform === "ios" && errorCode(error) === IOS_APP_GROUP_UNAVAILABLE_ERROR_CODE) {
31+
isUnavailable = true;
32+
return [];
33+
}
34+
throw error;
35+
}
36+
};
37+
}

0 commit comments

Comments
 (0)