Escape store links from in-app browsers #4274
[vc]: #sqa9eKJgh5IXu5UBgB9p3hZJ0LZ2jftHlAbhPoxmuPQ=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJkdWIiLCJwcm9qZWN0SWQiOiJwcmpfYkx6SmdUUFdoQXlMSjZLS0dhWWVtQ3gxdlpWVSIsInYwIjpmYWxzZSwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL2R1YmluYy9kdWIvR0VWaWpEZ0trRnhMZ3V3ektlbVo2bmlhR1BEbSIsInByZXZpZXdVcmwiOiJkdWItZ2l0LWVzY2FwZS1zdG9yZS1saW5rcy1pbi1hcHAtYnJvd3NlcnMtZHViaW5jLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQiLCJyb290RGlyZWN0b3J5IjoiYXBwcy93ZWIifV0sInJlcXVlc3RSZXZpZXdVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vdmVyY2VsLWFnZW50L3JlcXVlc3QtcmV2aWV3P293bmVyPWR1YmluYyZyZXBvPWR1YiZwcj00Mjc0In0=
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Actions | Updated (UTC) |
| :--- | :----- | :------ | :------ |
| <a href="https://vercel.com/dubinc/dub"><sup><img src="https://vercel.com/api/www/avatar?projectId=prj_bLzJgTPWhAyLJ6KKGaYemCx1vZVU&teamId=team_y0zuoaL8RHti4hQoucTdqRSG&s=32" width="16" height="16" align="middle" alt="" /></sup></a> dub | !Ready Ready | Preview | Aug 4, 2026 8:05pm |
<a href="https://vercel.com/vercel-agent/request-review?owner=dubinc&repo=dub&pr=4274" rel="noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://agents-vade-review.vercel.sh/request-review-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://agents-vade-review.vercel.sh/request-review-light.svg"><img src="https://agents-vade-review.vercel.sh/request-review-light.svg" alt="Request Review"></picture></a>
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- review_stack_entry_start -->

<!-- review_stack_entry_end -->
<!-- This is an auto-generated comment: review paused by coderabbit.ai -->
[!NOTE]
## Reviews paused
> It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.> Use the following commands to manage reviews:
- @coderabbitai resume to resume automatic reviews.- @coderabbitai review to trigger a single review.> Use the checkboxes below for quick actions:
- [ ] <!-- {"checkboxId": "7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> ▶️ Resume reviews
- [ ] <!-- {"checkboxId": "e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review
<!-- end of auto-generated comment: review paused by coderabbit.ai -->
<!-- walkthrough_start -->
<details>
<summary>📝 Walkthrough</summary>
Walkthrough
Adds an in-app browser escape flow for Instagram, Facebook, and TikTok browser contexts. The middleware creates encoded escape URLs, and the escape page renders localized messaging, branding, destination details, and browser or copy actions.
Changes
In-app browser escape
|Layer / File(s)|Summary|
|---|---|
|Detect and route in-app browsers <br> apps/web/lib/middleware/utils/detect-in-app-browser.ts, apps/web/lib/middleware/link.ts|The middleware detects supported in-app browsers for store destinations. It resolves the destination, records the click, and rewrites the request to an encoded escape URL.|
|Render localized escape page <br> apps/web/app/in-app-browser/[url]/page.tsx, apps/web/app/in-app-browser/[url]/translations.ts|The escape page decodes and validates request data, resolves optional link configuration, selects localized content, and renders branding and store messaging.|
|Provide browser and copy actions <br> apps/web/app/in-app-browser/[url]/action-button.tsx|The client component opens external-browser schemes, handles intent:// fallbacks, copies the destination URL, and displays a selectable URL fallback when copying fails.|
Estimated code review effort: 4 (Complex) | ~45 minutes
Sequence Diagram(s)
sequenceDiagram
participant Request
participant LinkMiddleware
participant EscapePage
participant Prisma
participant ActionButton
Request->>LinkMiddleware: request store destination
LinkMiddleware->>LinkMiddleware: detect supported in-app browser
LinkMiddleware-->>Request: rewrite to encoded escape URL
Request->>EscapePage: load escape URL
EscapePage->>Prisma: resolve optional link configuration
Prisma-->>EscapePage: return configuration or destination fallback
EscapePage->>ActionButton: provide destination and copy URLs
ActionButton-->>Request: open external browser or copy URL
Possibly related PRs
intent:// fallback behavior with visibility detection.Suggested reviewers: devkiran, steven-tey
</details>
<!-- walkthrough_end -->
<!-- pre_merge_checks_walkthrough_start -->
<details>
<summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary>
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
| :----------------: | :--------- | :----------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
<details>
<summary>✅ Passed checks (4 passed)</summary>
| Check name | Status | Explanation |
| :------------------------: | :------- | :---------------------------------------------------------------------------------------------------- |
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly and concisely describes the main change: escaping store links from in-app browsers. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
</details>
</details>
<!-- pre_merge_checks_walkthrough_end -->
<!-- finishing_touch_checkbox_start -->
<details>
<summary>✨ Finishing Touches 💡 1</summary>
<!-- finishing_touch_suggestion:docstrings -->
<details>
<summary>📝 Generate docstrings 💡</summary>
</details>
<details>
<summary>🧪 Generate unit tests (beta)</summary>
escape-store-links-in-app-browsers</details>
</details>
<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->
---
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
<details>
<summary>❤️ Share</summary>
</details>
<sub>Comment @coderabbitai help to get the list of available commands.</sub>
<!-- tips_end -->
_📐 Maintainability & Code Quality_ | _🟡 Minor_ | _⚡ Quick win_
A custom backgroundColor can make the label unreadable.
Line 38 hardcodes text-white. Lines 40-46 let buttonStyle.backgroundColor override the background. A workspace that configures a light background gets white text on a light surface, and the label fails contrast.
Derive the text color from the configured background, or let buttonStyle supply a color value as well.
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/web/app/in-app-browser/`[url]/action-button.tsx around lines 38 - 46,
Update the button styling in the action-button component so its text color
remains readable when buttonStyle.backgroundColor is customized. Derive the
label color from the configured background or apply a buttonStyle.color
override, while preserving the existing white-text fallback when no custom
styling is provided.
</details>
<!-- fingerprinting:phantom:medusa:komodo -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:f62ed603d2f21a38ee0eda1b -->
<!-- This is an auto-generated reply by CodeRabbit -->
✅ Addressed in commit 2aaf29b
<!-- This is an auto-generated comment by CodeRabbit -->
_🩺 Stability & Availability_ | _🟡 Minor_ | _⚡ Quick win_
The copy action fails silently when the Clipboard API is unavailable.
useCopyToClipboard catches the failure, logs it with console.error, and leaves copied as false (see packages/ui/src/hooks/use-copy-to-clipboard.tsx). The label then never changes, and the user gets no signal.
Some in-app webviews block navigator.clipboard or run outside a secure context. For a TikTok source this button is the only working path, because getExtBrowserScheme returns null for "tiktok".
Pass throwOnError and show an error state, or render the URL as selectable text so the user can copy it manually.
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/web/app/in-app-browser/`[url]/action-button.tsx around lines 48 - 53,
The copy button in the action-button component fails silently when the Clipboard
API is unavailable, leaving the user with no feedback. Update the onClick
handler for the Button to pass throwOnError to copyToClipboard (or configure
useCopyToClipboard with throwOnError), then add error state tracking alongside
the existing copied state to capture and display failures. When an error occurs,
show an error message or visual indicator to the user so they know the clipboard
action failed, or alternatively render the copyUrl as selectable text below the
button so users can manually select and copy the URL when the Clipboard API is
unavailable.
</details>
<!-- fingerprinting:phantom:medusa:komodo -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:3971a6583560e930ea4cb7b9 -->
<!-- This is an auto-generated comment by CodeRabbit -->
✅ Addressed in commits cbc78e2 to cde30e5
_🎯 Functional Correctness_ | _🟡 Minor_ | _⚡ Quick win_
TikTok gets no escape path.
getExtBrowserScheme returns null for "tiktok". InAppBrowserActionButton then assigns window.location.href = destinationUrl in action-button.tsx Line 31. That navigation stays inside the TikTok webview, which is the condition this page exists to escape.
The button label still reads "Open in App Store", so the primary action does not do what it states. The copy-link button remains as a fallback.
Either hide the primary button when extBrowserScheme is null, or change the label and instructions for that case to direct the user to the webview menu.
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/web/app/in-app-browser/`[url]/page.tsx around lines 54 - 66, The TikTok
path in getExtBrowserScheme currently returns null, causing
InAppBrowserActionButton to navigate within the embedded webview while still
displaying the “Open in App Store” action. Update the related action-button
behavior so the primary action is hidden when extBrowserScheme is null, while
preserving the copy-link fallback.
</details>
<!-- fingerprinting:phantom:medusa:komodo -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:5f9ffb9620bc9323cd2f789c -->
<!-- This is an auto-generated comment by CodeRabbit -->
✅ Addressed in commits cbc78e2 to cde30e5
_🩺 Stability & Availability_ | _🟠 Major_ | _⚡ Quick win_
Remove the second decode of key; it can throw and crash the page.
The middleware sets key with escapeUrl.searchParams.set("key", key). Next.js decodes searchParams values before it passes them to the page. decodeURIComponent at Line 94 therefore decodes a second time.
Two consequences follow. A key that contains a literal % makes decodeURIComponent throw URIError, and the unhandled error turns the escape page into a 500. A key that contains %25 silently resolves to %, so the findUnique lookup at Line 107 misses.
<details>
<summary>🐛 Proposed fix to use the already-decoded value</summary>
const domain = searchParams.domain;
- const key = searchParams.key
- ? decodeURIComponent(searchParams.key)
- : undefined;
+ const key = searchParams.key;
</details>
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/web/app/in-app-browser/`[url]/page.tsx around lines 93 - 95, Remove the
decodeURIComponent call from the key assignment in the page component, using
searchParams.key directly when present and preserving undefined when absent.
Keep the existing key lookup flow unchanged so literal percent characters are
handled safely and the original decoded value reaches findUnique.
</details>
<!-- fingerprinting:phantom:medusa:komodo -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:855e0b5e972232bf41dfeb52 -->
<!-- This is an auto-generated comment by CodeRabbit -->
✅ Addressed in commits cbc78e2 to cde30e5
_📐 Maintainability & Code Quality_ | _🟡 Minor_ | _⚡ Quick win_
Interpolated store names produce ungrammatical strings in some locales.
storeName resolves to "Google Play" or "App Store" in page.tsx Line 136. The surrounding articles are fixed per locale, so they only fit one of the two values.
fr Line 25 and Line 26: "le App Store" is incorrect; French elides to "l'App Store". "le Google Play" is also wrong.pt Line 39 and Line 40: "na Google Play" uses a feminine article that does not fit "App Store".de Line 46 and Line 47: "zum Google Play" adds an article that German does not use for that name.Remove the articles from the templates, or store per-locale phrasing for each store name.
Also applies to: 39-40, 46-47
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/web/app/in-app-browser/`[url]/translations.ts around lines 25 - 26,
Update the localized description and openInStore templates in the French,
Portuguese, and German translation entries to avoid fixed articles that conflict
with either storeName value. Remove or replace the surrounding article phrasing
while preserving the {storeName} interpolation and the intended meaning for both
Google Play and App Store.
</details>
<!-- fingerprinting:phantom:medusa:komodo -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:d11032ed639c1f0c7702ea4d -->
<!-- This is an auto-generated comment by CodeRabbit -->
✅ Addressed in commits cbc78e2 to cde30e5
_📐 Maintainability & Code Quality_ | _🟠 Major_ | _🏗️ Heavy lift_
Reuse one destination resolution instead of duplicating the precedence rules.
Lines 420-427 repeat the iOS, Android, and geo precedence that the branches at Line 472, Line 536, and Line 599 already implement. Two copies of the same rules can drift.
Line 429 also calls getFinalUrl on every request that reaches this point. The selected branch then calls getFinalUrl again with the same inputs, so the work is done twice on the redirect hot path.
Resolve the destination once, compute finalUrl once, and reuse both values in the branches below.
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/web/lib/middleware/link.ts` around lines 420 - 433, Consolidate
destination selection and final URL computation in the surrounding link
middleware: reuse the existing precedence logic from the branches at Lines 472,
536, and 599 instead of maintaining the duplicate destinationForEscape chain.
Compute getFinalUrl once for the resolved destination, then pass the shared
destination and final URL through those branches so each request avoids repeated
resolution and URL generation.
</details>
<!-- fingerprinting:phantom:medusa:komodo -->
<!-- cr-indicator-types:refactor_suggestion -->
<!-- cr-comment:v1:9ad1078e07d43f45de9af0df -->
<!-- This is an auto-generated comment by CodeRabbit -->
✅ Addressed in commit 2aaf29b
_🗄️ Data Integrity & Integration_ | _🟠 Major_ | _⚡ Quick win_
<details>
<summary>🧩 Analysis chain</summary>
🏁 Script executed:
#!/bin/bash
# Description: Trace cacheDeepLinkClickData producers and consumers.
set -euo pipefail
fd -t f 'cache-deep-link-click-data*' || true
rg -n -C6 'cacheDeepLinkClickData|deepLinkClickCache|deferred deep link' --type=ts --type=tsx
Repository: dubinc/dub
Length of output: 180
---
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Tracked files matching cache-deep-link-click-data:\n'
git ls-files | grep -i 'cache-deep-link-click-data' || true
printf '\nCache/write and consumer references:\n'
rg -n -C6 'cacheDeepLinkClickData|deepLinkClickCache|deferred deep link' -e '\.(ts|tsx)$' | head -n 240
printf '\nCandidate middleware outline:\n'
ast-grep outline apps/web/lib/middleware/link.ts 2>/dev/null || true
printf '\nRelevant middleware sections:\n'
sed -n '360,580p' apps/web/lib/middleware/link.ts
Repository: dubinc/dub
Length of output: 430
---
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Trackable TypeScript files (non-error filtered):\n'
git ls-files | grep -P '\.(ts|tsx)$' | head -n 50
printf '\nLocate cacheDeepLinkClickData references:\n'
git ls-files -z | xargs -0 rg -n -C6 'cacheDeepLinkClickData|deepLinkClickCache|deferred deep link' || true
printf '\nRelevant middleware sections:\n'
sed -n '360,580p' apps/web/lib/middleware/link
printf '\nFind deep link interstitial references:\n'
git ls-files -z | xargs -0 rg -n -C4 '/deeplink|deeplink|deferred|skip_deeplink_preview' || true
Repository: dubinc/dub
Length of output: 3623
---
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Find cacheDeepLinkClickData references:\n'
git ls-files -z | xargs -0 rg -n -C8 'cacheDeepLinkClickData|deepLinkClickCache|deferred deep link' || true
printf '\nInspect middleware link around escape/iOS/Android branches:\n'
sed -n '360,580p' apps/web/lib/middleware/link.ts
printf '\nFind deeplink interstitial references (focused):\n'
rg -n -C5 '/deeplink|deeplink|skip_deeplink_preview|cacheDeepLinkClickData|deepLinkClickCache' .
Repository: dubinc/dub
Length of output: 38108
---
</details>
Preserve store-link deep-link click caching in the escape branch.
The iOS and Android branches cache deep link click data when the destination is an App Store or Play Store URL and skip_deeplink_preview is absent. The in-app browser escape branch runs first and returns early, then bypasses those branches, so store clicks in supported in-app browsers never populate deepLinkClickCache and cannot support deferred deep linking.
Call cacheDeepLinkClickData in the escape path before returning; use the main destination URL so later tracking can read the original application URL.
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/web/lib/middleware/link.ts` around lines 435 - 469, Update the
inAppBrowserSource escape branch before its early return to call
cacheDeepLinkClickData for eligible App Store or Play Store destinations when
skip_deeplink_preview is absent. Pass the main destination URL rather than
escapeFinalUrl so deferred deep-link tracking can recover the original
application URL.
</details>
<!-- fingerprinting:phantom:medusa:komodo -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:a4dfd2f30e014ed28df95922 -->
<!-- This is an auto-generated comment by CodeRabbit -->
✅ Addressed in commits cbc78e2 to cde30e5
Actionable comments posted: 7
<details>
<summary>🧹 Nitpick comments (2)</summary><blockquote>
<details>
<summary>apps/web/app/in-app-browser/[url]/page.tsx (2)</summary><blockquote>
36-40: _🎯 Functional Correctness_ | _🔵 Trivial_ | _⚡ Quick win_
Falling back to "instagram" for an unknown source is misleading.
Line 81 coerces any unrecognized source value to "instagram". The page then emits an instagram://extbrowser/ scheme and auto-navigates to it at Line 151. On a device without Instagram installed, that navigation fails and the user sees nothing happen.
Treat an unknown source as "no scheme available" instead, so the page renders the copy-link fallback.
<details>
<summary>♻️ Proposed change to the source fallback</summary>
- const source: InAppBrowserSource = VALID_SOURCES.has(
- rawSource as InAppBrowserSource,
- )
- ? (rawSource as InAppBrowserSource)
- : "instagram";
+ const source: InAppBrowserSource | null = VALID_SOURCES.has(
+ rawSource as InAppBrowserSource,
+ )
+ ? (rawSource as InAppBrowserSource)
+ : null;
getExtBrowserScheme then needs to accept null and return null for it.
</details>
Also applies to: 77-81
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/web/app/in-app-browser/`[url]/page.tsx around lines 36 - 40, The source
fallback logic (around the VALID_SOURCES reference) currently coerces
unrecognized source values to "instagram", which triggers a misleading
instagram:// scheme navigation that fails if the app isn't installed. Instead of
defaulting unknown sources to a valid scheme, treat them as null to represent
"no scheme available". Update the getExtBrowserScheme function to accept null as
input and return null for it, so the page falls back to rendering the copy-link
UI for unrecognized sources rather than attempting a failed navigation.
</details>
<!-- cr-comment:v1:289ce65153e6c5a31be328ec -->
---
105-130: _🚀 Performance & Scalability_ | _🔵 Trivial_ | _⚡ Quick win_
Remove the duplicate Prisma lookup from the escape page.
The in-app browser rewrite only passes domain and key through search params, so apps/web/app/in-app-browser/[url]/page.tsx resolves shortLink and shortDomain.deepviewData again. Move those fields into the rewrite state, or avoid re-fetching when they are already available.
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/web/app/in-app-browser/`[url]/page.tsx around lines 105 - 130, The
Prisma findUnique query around the domain_key lookup is redundantly fetching
shortLink and shortDomain.deepviewData even though the rewrite already passes
domain and key through search params. Either include shortLink and deepviewData
in the rewrite state to make them available without re-fetching, or
conditionally skip the findUnique query if those fields are already present.
Preserve the decodeLinkIfCaseSensitive logic for decoding the resolved link
data.
</details>
<!-- cr-comment:v1:82d4afc616019539bd68a738 -->
</blockquote></details>
</blockquote></details>
<details>
<summary>🤖 Prompt for all review comments with AI agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/web/app/in-app-browser/`[url]/action-button.tsx:
- Around line 38-46: Update the button styling in the action-button component so
its text color remains readable when buttonStyle.backgroundColor is customized.
Derive the label color from the configured background or apply a
buttonStyle.color override, while preserving the existing white-text fallback
when no custom styling is provided.
- Around line 48-53: The copy button in the action-button component fails
silently when the Clipboard API is unavailable, leaving the user with no
feedback. Update the onClick handler for the Button to pass throwOnError to
copyToClipboard (or configure useCopyToClipboard with throwOnError), then add
error state tracking alongside the existing copied state to capture and display
failures. When an error occurs, show an error message or visual indicator to the
user so they know the clipboard action failed, or alternatively render the
copyUrl as selectable text below the button so users can manually select and
copy the URL when the Clipboard API is unavailable.
In `@apps/web/app/in-app-browser/`[url]/page.tsx:
- Around line 54-66: The TikTok path in getExtBrowserScheme currently returns
null, causing InAppBrowserActionButton to navigate within the embedded webview
while still displaying the “Open in App Store” action. Update the related
action-button behavior so the primary action is hidden when extBrowserScheme is
null, while preserving the copy-link fallback.
- Around line 93-95: Remove the decodeURIComponent call from the key assignment
in the page component, using searchParams.key directly when present and
preserving undefined when absent. Keep the existing key lookup flow unchanged so
literal percent characters are handled safely and the original decoded value
reaches findUnique.
In `@apps/web/app/in-app-browser/`[url]/translations.ts:
- Around line 25-26: Update the localized description and openInStore templates
in the French, Portuguese, and German translation entries to avoid fixed
articles that conflict with either storeName value. Remove or replace the
surrounding article phrasing while preserving the {storeName} interpolation and
the intended meaning for both Google Play and App Store.
In `@apps/web/lib/middleware/link.ts`:
- Around line 420-433: Consolidate destination selection and final URL
computation in the surrounding link middleware: reuse the existing precedence
logic from the branches at Lines 472, 536, and 599 instead of maintaining the
duplicate destinationForEscape chain. Compute getFinalUrl once for the resolved
destination, then pass the shared destination and final URL through those
branches so each request avoids repeated resolution and URL generation.
- Around line 435-469: Update the inAppBrowserSource escape branch before its
early return to call cacheDeepLinkClickData for eligible App Store or Play Store
destinations when skip_deeplink_preview is absent. Pass the main destination URL
rather than escapeFinalUrl so deferred deep-link tracking can recover the
original application URL.
---
Nitpick comments:
In `@apps/web/app/in-app-browser/`[url]/page.tsx:
- Around line 36-40: The source fallback logic (around the VALID_SOURCES
reference) currently coerces unrecognized source values to "instagram", which
triggers a misleading instagram:// scheme navigation that fails if the app isn't
installed. Instead of defaulting unknown sources to a valid scheme, treat them
as null to represent "no scheme available". Update the getExtBrowserScheme
function to accept null as input and return null for it, so the page falls back
to rendering the copy-link UI for unrecognized sources rather than attempting a
failed navigation.
- Around line 105-130: The Prisma findUnique query around the domain_key lookup
is redundantly fetching shortLink and shortDomain.deepviewData even though the
rewrite already passes domain and key through search params. Either include
shortLink and deepviewData in the rewrite state to make them available without
re-fetching, or conditionally skip the findUnique query if those fields are
already present. Preserve the decodeLinkIfCaseSensitive logic for decoding the
resolved link data.
</details>
<details>
<summary>🪄 Autofix</summary>
Fix all unresolved CodeRabbit comments on this PR:
</details>
---
<details>
<summary>ℹ️ Review info</summary>
<details>
<summary>⚙️ Run configuration</summary>
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 9bcbdeeb-5283-41aa-82c4-475fee916995
</details>
<details>
<summary>📥 Commits</summary>
Reviewing files that changed from the base of the PR and between 73c58094a6dd326e4ae7db7ecd3830f7a9d6584a and 5d7026684a4581a3c309e9b6a86507838c2b83db.
</details>
<details>
<summary>📒 Files selected for processing (5)</summary>
apps/web/app/in-app-browser/[url]/action-button.tsx
apps/web/app/in-app-browser/[url]/page.tsx
apps/web/app/in-app-browser/[url]/translations.ts
apps/web/lib/middleware/link.ts
apps/web/lib/middleware/utils/detect-in-app-browser.ts</details>
</details>
<!-- This is an auto-generated comment by CodeRabbit for review status -->
Pre-existing Deep View pattern; out of scope for this change
@pepeladeira, acknowledged. This PR follows the existing Deep View styling pattern, so this change is out of scope.
Would you like me to create a GitHub follow-up issue for configurable button text contrast?
<sub>You are interacting with an AI system.</sub>
<!-- This is an auto-generated reply by CodeRabbit -->
<details>
<summary>🧹 Nitpick comments (1)</summary><blockquote>
<details>
<summary>apps/web/app/in-app-browser/[url]/page.tsx (1)</summary><blockquote>
26-30: _📐 Maintainability & Code Quality_ | _🔵 Trivial_ | _💤 Low value_
Remove the unused static rendering config, or document why it stays.
InAppBrowserEscapePage reads request data with headers() before getLanguage() and userAgent(). That makes the route dynamic, so revalidate = false and generateStaticParams() do not affect rendering. Keep the config if a specific reason applies; otherwise remove it to avoid a future headers() removal accidentally enabling stale static cache.
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/web/app/in-app-browser/`[url]/page.tsx around lines 26 - 30, Remove the
unused revalidate export and generateStaticParams function near
InAppBrowserEscapePage, since headers() makes this route dynamic; only retain
them if you add documentation explaining a specific intentional purpose.
</details>
<!-- cr-comment:v1:c49ef14d4a4f634ff068188f -->
</blockquote></details>
</blockquote></details>
<details>
<summary>🤖 Prompt for all review comments with AI agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@apps/web/app/in-app-browser/`[url]/page.tsx:
- Around line 26-30: Remove the unused revalidate export and
generateStaticParams function near InAppBrowserEscapePage, since headers() makes
this route dynamic; only retain them if you add documentation explaining a
specific intentional purpose.
</details>
---
<details>
<summary>ℹ️ Review info</summary>
<details>
<summary>⚙️ Run configuration</summary>
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4cf66a69-b8c2-4ab2-ba63-e40ed7c77596
</details>
<details>
<summary>📥 Commits</summary>
Reviewing files that changed from the base of the PR and between cde30e5c35ed10ff8a84b33274f6b385aae162bb and 2aaf29bca29198b2aaa6ace3d602887dba02d299.
</details>
<details>
<summary>📒 Files selected for processing (3)</summary>
apps/web/app/in-app-browser/[url]/action-button.tsx
apps/web/app/in-app-browser/[url]/page.tsx
apps/web/lib/middleware/link.ts
</details>
<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>
apps/web/app/in-app-browser/[url]/action-button.tsx
</details>
</details>
<!-- This is an auto-generated comment by CodeRabbit for review status -->
@coderabbitai full review. any breaking changes?
<!-- This is an auto-generated reply by CodeRabbit -->
<!-- CodeRabbit review command invocation: 832f7515-563b-43bb-b18b-8992d6d470f9 -->
<details>
<summary>🧩 Analysis chain</summary>
🏁 Script executed:
#!/bin/bash
set -euo pipefail
git diff --stat HEAD^ HEAD
git diff --find-renames -- \
'apps/web/lib/middleware/link.ts' \
'apps/web/lib/middleware/utils/detect-in-app-browser.ts' \
'apps/web/app/in-app-browser/[url]/action-button.tsx' \
'apps/web/app/in-app-browser/[url]/page.tsx' \
'apps/web/app/in-app-browser/[url]/translations.ts'
printf '\n--- Relevant symbols and references ---\n'
ast-grep outline apps/web/lib/middleware/link.ts --items all
ast-grep outline apps/web/lib/middleware/utils/detect-in-app-browser.ts --items all
ast-grep outline 'apps/web/app/in-app-browser/[url]/page.tsx' --items all
rg -n -C 3 '\b(shouldEscapeInAppBrowser|getInAppBrowserEscapeUrl|InAppBrowserEscapePage|InAppBrowserActionButton)\b' apps/web
printf '\n--- Related test files ---\n'
fd -t f . apps/web | rg -i '(in-app-browser|detect-in-app-browser|middleware.*link|link.*middleware).*(test|spec)|\.(test|spec)\.[^.]+$' || true
Length of output: 14052
---
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- PR commits and changed paths ---'
git log --oneline HEAD^..HEAD
git diff --name-status HEAD^ HEAD
printf '%s\n' '--- Current LinkMiddleware redirect section ---'
sed -n '300,510p' apps/web/lib/middleware/link.ts
printf '%s\n' '--- Parent LinkMiddleware redirect section ---'
git show HEAD^:apps/web/lib/middleware/link.ts | sed -n '300,510p'
printf '%s\n' '--- In-app browser helpers ---'
cat -n apps/web/lib/middleware/utils/detect-in-app-browser.ts
printf '%s\n' '--- URL/store helpers ---'
cat -n apps/web/lib/middleware/utils/is-ios-app-store-url.ts
cat -n apps/web/lib/middleware/utils/is-google-play-store-url.ts
cat -n apps/web/lib/middleware/utils/get-final-url.ts
printf '%s\n' '--- Escape page and action component ---'
sed -n '1,340p' 'apps/web/app/in-app-browser/[url]/page.tsx'
sed -n '1,220p' 'apps/web/app/in-app-browser/[url]/action-button.tsx'
printf '%s\n' '--- Effective diff with context ---'
git diff --find-renames -U80 HEAD^ HEAD -- \
'apps/web/lib/middleware/link.ts' \
'apps/web/app/in-app-browser/[url]/page.tsx' \
'apps/web/app/in-app-browser/[url]/action-button.tsx'
Length of output: 57039
---
🏁 Script executed:
#!/bin/bash
set -euo pipefail
base="$(git merge-base HEAD main)"
printf 'Merge base: %s\n' "$base"
printf '%s\n' '--- Complete PR changed paths ---'
git diff --name-status "$base" HEAD
printf '%s\n' '--- Complete PR diff summary ---'
git diff --stat "$base" HEAD
printf '%s\n' '--- Complete PR diff: in-app-browser and middleware ---'
git diff -U50 "$base" HEAD -- \
'apps/web/lib/middleware/link.ts' \
'apps/web/lib/middleware/utils/detect-in-app-browser.ts' \
'apps/web/app/in-app-browser/[url]/page.tsx' \
'apps/web/app/in-app-browser/[url]/action-button.tsx' \
'apps/web/app/in-app-browser/[url]/translations.ts'
printf '%s\n' '--- Middleware and route configuration references ---'
rg -n -C 4 'LinkMiddleware|matcher|in-app-browser|/deeplink/' \
apps/web/middleware.ts apps/web/next.config.* apps/web 2>/dev/null || true
printf '%s\n' '--- Target branch versions, when files exist ---'
for f in \
'apps/web/lib/middleware/utils/detect-in-app-browser.ts' \
'apps/web/app/in-app-browser/[url]/page.tsx' \
'apps/web/app/in-app-browser/[url]/action-button.tsx' \
'apps/web/app/in-app-browser/[url]/translations.ts'
do
if git cat-file -e "$base:$f" 2>/dev/null; then
printf '\n--- %s at merge base ---\n' "$f"
git show "$base:$f" | sed -n '1,360p'
fi
done
printf '%s\n' '--- URL construction edge cases ---'
python3 - <<'PY'
from urllib.parse import quote
for u in [
"https://play.google.com/store/apps/details?id=com.example#reviews",
"https://apps.apple.com/us/app/example/id123?pt=1#privacy",
"https://play.google.com:8443/store/apps/details?id=com.example",
]:
print(u)
print("encoded path:", quote(u, safe=""))
PY
Length of output: 45658
---
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- Middleware dispatch and application-route exclusions ---'
sed -n '1,115p' apps/web/middleware.ts
sed -n '1,95p' apps/web/lib/middleware/app.ts
printf '%s\n' '--- Domain and request parsing behavior ---'
rg -n -C 3 '\bAPP_DOMAIN\b|function isDubDomain|const isDubDomain|export.*isDubDomain' \
packages apps/web 2>/dev/null || true
cat -n apps/web/lib/middleware/utils/parse.ts
printf '%s\n' '--- Existing test conventions for middleware utilities ---'
fd -t f -e ts -e tsx apps/web | rg '(test|spec)\.(ts|tsx)$' | head -80
rg -n -C 2 'NextRequest|NextFetchEvent|LinkMiddleware|userAgent\(' \
apps/web/tests apps/web/lib --glob '*.{test,spec}.ts' 2>/dev/null || true
printf '%s\n' '--- Package scripts and test tooling declarations ---'
for f in package.json apps/web/package.json; do
if [ -f "$f" ]; then
printf '\n--- %s ---\n' "$f"
sed -n '1,220p' "$f"
fi
done
Length of output: 64519
---
</details>
@pepeladeira I completed the full review.
I found no breaking public API or redirect-contract change.
The PR intentionally changes behavior for Instagram, Facebook, and TikTok in-app browsers when the selected destination is an App Store or Google Play URL. These requests now render the escape page instead of continuing through the normal store-link flow.
For all other requests, the existing destination priority remains unchanged:
1. iOS destination on iOS.
2. Android destination on Android.
3. Geo-targeted destination.
4. Default destination.
The implementation preserves click recording, cookies, tracking parameters, and deferred deep-link caching before it enters the escape flow.
I did not identify a blocking code defect. The main release risk is device-specific behavior for the Instagram, Facebook, and Android intent:// external-browser schemes. Validate those paths on physical iOS and Android devices before release. Focused automated coverage for user-agent detection and escape URL construction would also reduce regression risk.
<details>
<summary>✅ Action performed</summary>
Full review finished.
</details>
_🩺 Stability & Availability_ | _🟡 Minor_ | _⚡ Quick win_
Replace the in check with an own-property check.
in also matches inherited Object.prototype keys. A request with Accept-Language: constructor makes getLanguage return "constructor", and getTranslations then returns Object. On the escape page, t.description is undefined, so .replace("{storeName}", storeName) at page.tsx Line 183 throws and the page returns a 500.
Use Object.prototype.hasOwnProperty.call or a Set of valid codes.
<details>
<summary>🐛 Proposed fix</summary>
for (const lang of languages) {
- if (lang in translations) {
+ if (Object.prototype.hasOwnProperty.call(translations, lang)) {
return lang as Language;
}
}
</details>
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export function getLanguage(acceptLanguage?: string | null): Language {
if (!acceptLanguage) return "en";
const languages = acceptLanguage
.toLowerCase()
.split(",")
.map((lang) => {
const [code] = lang.trim().split(";");
return code.split("-")[0];
});
for (const lang of languages) {
if (Object.prototype.hasOwnProperty.call(translations, lang)) {
return lang as Language;
}
}
return "en";
}
</details>
<!-- suggestion_end -->
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/web/app/in-app-browser/`[url]/translations.ts around lines 86 - 104,
Update the language validation in getLanguage to accept only translation codes
that are own properties of translations, using
Object.prototype.hasOwnProperty.call or an equivalent valid-code Set. Preserve
the existing fallback to "en" and return behavior for supported language codes.
</details>
<!-- fingerprinting:phantom:medusa:komodo -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:ccb5c97ad980fed463770a60 -->
<!-- This is an auto-generated comment by CodeRabbit -->
✅ Addressed in commit 5c3701b
Actionable comments posted: 1
<details>
<summary>🤖 Prompt for all review comments with AI agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/web/app/in-app-browser/`[url]/translations.ts:
- Around line 86-104: Update the language validation in getLanguage to accept
only translation codes that are own properties of translations, using
Object.prototype.hasOwnProperty.call or an equivalent valid-code Set. Preserve
the existing fallback to "en" and return behavior for supported language codes.
</details>
<details>
<summary>🪄 Autofix</summary>
Fix all unresolved CodeRabbit comments on this PR:
</details>
---
<details>
<summary>ℹ️ Review info</summary>
<details>
<summary>⚙️ Run configuration</summary>
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 512a4df5-220b-4b9f-be5a-91057bbbdaac
</details>
<details>
<summary>📥 Commits</summary>
Reviewing files that changed from the base of the PR and between cbc78e2c93d4e6ec3218d3b9b919807839570646 and 2aaf29bca29198b2aaa6ace3d602887dba02d299.
</details>
<details>
<summary>📒 Files selected for processing (5)</summary>
apps/web/app/in-app-browser/[url]/action-button.tsx
apps/web/app/in-app-browser/[url]/page.tsx
apps/web/app/in-app-browser/[url]/translations.ts
apps/web/lib/middleware/link.ts
apps/web/lib/middleware/utils/detect-in-app-browser.ts</details>
</details>
<!-- This is an auto-generated comment by CodeRabbit for review status -->
pepeladeira
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
New Features
Added an in-app browser escape experience for Instagram, Facebook, and TikTok.
Users can open links in an external browser or copy destination URLs.
Added localized messaging in eight languages, app store guidance, branded styling, badges, and deep-link support.
Bug Fixes
Improved redirect handling across iOS, Android, and location-based destinations.
Added clear success messaging and a selectable fallback URL when copying fails.
Invalid or unsupported links now continue safely without unnecessary external-browser redirects.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->