Skip to content

Commit faaccd8

Browse files
committed
fix(links): simplify deep link redirect to direct 302
Replace HTML interstitial with a straight 302 redirect to the URI scheme. No browser tab flash — the app opens immediately.
1 parent d93feb8 commit faaccd8

File tree

1 file changed

+2
-35
lines changed

1 file changed

+2
-35
lines changed

apps/links/src/routes/redirect.ts

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -130,33 +130,6 @@ function isMobile(ua: string | null): boolean {
130130
);
131131
}
132132

133-
function buildInterstitialHtml(deepUri: string, fallbackUrl: string): string {
134-
const escaped = (s: string) =>
135-
s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
136-
137-
return `<!DOCTYPE html>
138-
<html>
139-
<head>
140-
<meta charset="utf-8">
141-
<meta name="viewport" content="width=device-width,initial-scale=1">
142-
<meta http-equiv="refresh" content="2;url=${escaped(fallbackUrl)}">
143-
<title>Redirecting…</title>
144-
<style>body{display:flex;align-items:center;justify-content:center;height:100dvh;margin:0;font-family:system-ui,sans-serif;color:#666}p{text-align:center;font-size:14px}</style>
145-
</head>
146-
<body>
147-
<p>Opening app…</p>
148-
<script>
149-
(function(){
150-
var d="${escaped(deepUri)}",f="${escaped(fallbackUrl)}",t;
151-
try{window.location=d}catch(e){}
152-
t=setTimeout(function(){window.location=f},800);
153-
document.addEventListener("visibilitychange",function(){if(document.hidden)clearTimeout(t)});
154-
})();
155-
</script>
156-
</body>
157-
</html>`;
158-
}
159-
160133
function appendRef(url: string, linkId: string): string {
161134
return `${url}${url.includes("?") ? "&" : "?"}ref=${encodeURIComponent(linkId)}`;
162135
}
@@ -410,14 +383,8 @@ export const redirectRoute = new Elysia().get(
410383
captureError(err, { error_step: "record_click", link_id: link.id })
411384
);
412385
emit("deep_link");
413-
const fallback = appendRef(targetUrl, link.id);
414-
return new Response(buildInterstitialHtml(deepUri, fallback), {
415-
headers: {
416-
...headers,
417-
"Content-Type": "text/html; charset=utf-8",
418-
"Cache-Control": "private, no-store",
419-
},
420-
});
386+
set.headers = { ...headers, "Cache-Control": "private, no-store" };
387+
return redirect(deepUri, 302);
421388
}
422389
}
423390

0 commit comments

Comments
 (0)