Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

fix(mobile): fixes #1807

daniel31x13bd2a09f99dba
diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsx
index bd84c192..bb739910 100644
--- a/apps/mobile/app/_layout.tsx
+++ b/apps/mobile/app/_layout.tsx
@@ -6,7 +6,7 @@ import {
} from "expo-router";
import { PersistQueryClientProvider } from "@tanstack/react-query-persist-client";
import { queryPersister } from "@/lib/queryPersister";
-import { useState, useEffect } from "react";
+import { useState, useEffect, useRef } from "react";
import "../styles/global.css";
import { SheetProvider } from "react-native-actions-sheet";
import "@/components/ActionSheets/Sheets";
@@ -44,6 +44,7 @@ export default Sentry.wrap(function RootLayout() {
const { setAuth } = useAuthStore();
const rootNavState = useRootNavigationState();
+ const redirectingToIncoming = useRef(false);
useEffect(() => {
setAuth();
@@ -54,13 +55,15 @@ export default Sentry.wrap(function RootLayout() {
useEffect(() => {
if (!rootNavState?.key || isLoading) return;
- if (hasShareIntent && shareIntent.webUrl) {
- updateData({
- shareIntent: {
- hasShareIntent: true,
- url: shareIntent.webUrl || "",
- },
- });
+ if (hasShareIntent) {
+ if (shareIntent.webUrl) {
+ updateData({
+ shareIntent: {
+ hasShareIntent: true,
+ url: shareIntent.webUrl,
+ },
+ });
+ }
resetShareIntent();
}
@@ -71,11 +74,12 @@ export default Sentry.wrap(function RootLayout() {
pathname !== "/incoming";
if (needsRewrite) {
- router.replace("/incoming");
- }
- if (hasShareIntent) {
- resetShareIntent();
- router.replace("/incoming");
+ if (!redirectingToIncoming.current) {
+ redirectingToIncoming.current = true;
+ router.replace("/incoming");
+ }
+ } else if (pathname === "/incoming") {
+ redirectingToIncoming.current = false;
}
}, [
rootNavState?.key,
diff --git a/apps/mobile/app/incoming.tsx b/apps/mobile/app/incoming.tsx
index 9c87f2ad..1f56681b 100644
--- a/apps/mobile/app/incoming.tsx
+++ b/apps/mobile/app/incoming.tsx
@@ -17,6 +17,8 @@ import { SheetManager } from "react-native-actions-sheet";
import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types/global";
import { SafeAreaView } from "react-native-safe-area-context";
+let pendingSubmission: { url: string; promise: Promise<any> } | null = null;
+
export default function IncomingScreen() {
const { auth } = useAuthStore();
const router = useRouter();
@@ -27,33 +29,58 @@ export default function IncomingScreen() {
const [link, setLink] = useState<LinkIncludingShortenedCollectionAndTags>();
useEffect(() => {
- if (auth.status === "authenticated" && data.shareIntent.url)
- addLink.mutate(
- {
- url: data.shareIntent.url,
+ const url = data.shareIntent.url;
+
+ if (!url) {
+ pendingSubmission = null;
+ return;
+ }
+
+ if (auth.status !== "authenticated") return;
+
+ if (pendingSubmission?.url !== url) {
+ pendingSubmission = {
+ url,
+ promise: addLink.mutateAsync({
+ url,
collection: { id: data.preferredCollection?.id },
- },
- {
- onSuccess: (e) => {
- setLink(e as unknown as LinkIncludingShortenedCollectionAndTags);
- setShowSuccess(true);
- setTimeout(() => {
- updateData({
- shareIntent: {
- hasShareIntent: false,
- url: "",
- },
- });
- router.replace("/dashboard");
- }, 1500);
- },
- onError: (error) => {
- Alert.alert("Error", "There was an error adding the link.");
- console.error("Error adding link:", error);
- },
- }
- );
- }, [auth, data.shareIntent.url]);
+ }),
+ };
+ }
+
+ let ignore = false;
+
+ pendingSubmission.promise.then(
+ (e) => {
+ if (ignore) return;
+
+ setLink(e as unknown as LinkIncludingShortenedCollectionAndTags);
+ setShowSuccess(true);
+ setTimeout(() => {
+ pendingSubmission = null;
+ updateData({
+ shareIntent: {
+ hasShareIntent: false,
+ url: "",
+ },
+ });
+ router.replace("/dashboard");
+ }, 1500);
+ },
+ (error) => {
+ pendingSubmission = null;
+
+ if (ignore) return;
+
+ Alert.alert("Error", "There was an error adding the link.");
+ console.error("Error adding link:", error);
+ }
+ );
+
+ return () => {
+ ignore = true;
+ };
+ }, [auth.status, data.shareIntent.url]);
if (auth.status === "unauthenticated") return <Redirect href="/" />;