fix: use public deployment URL for deep links and AD4M-connect appInfo (mobile bug)#611
fix: use public deployment URL for deep links and AD4M-connect appInfo (mobile bug)#611HexaField wants to merge 2 commits into
Conversation
…D4M-connect appInfo
In Capacitor (mobile) builds, `window.location.origin` is
`capacitor://localhost` — a scheme that only resolves inside the
running app. The two places that propagate this off-device were:
- `registerMobileNotifications.ts` — `appUrl` and `appIconPath` are
embedded in push-notification deep links. Tapping a notification on
any device produced a `capacitor://localhost#/communities/...`
link, broken everywhere except the device that originated it.
- `app.ts` — `appInfo.url` and `appInfo.iconPath` are sent to the
AD4M-connect popup and stored on the capability token. Same
problem, less visible (only surfaces in admin / debug views).
Add `utils/publicUrl.ts` with a pure resolver:
1. Use `VITE_PUBLIC_URL` (build-time env var) when set.
2. Otherwise use `window.location.origin` IF it points at a real
public host (not `capacitor:`, not `localhost`, not `*.local`).
3. Otherwise fall back to the canonical Coasys deployment —
fluxsocial-dev.netlify.app for non-prod, fluxsocial.netlify.app
for prod. The fallback exists so the bug surfaces as
"links go to the right-but-shared deployment" rather than
"links 404 silently."
Set `VITE_PUBLIC_URL` in `.env.development` and `.env.production` to
the canonical deployments. Mobile builds inherit these by virtue of
Vite baking them at build time.
The exported helpers `publicAppUrl()` and `publicIconUrl()` wrap the
runtime reads (`import.meta.env`, `window.location`); tests call
`resolvePublicAppUrl()` directly so every branch is covered without
monkey-patching globals.
Test covers:
- `isPublicOrigin` — accept/reject across https, http, capacitor,
ionic, localhost variants, 127.0.0.1, [::1], `.local`, malformed.
- `resolvePublicAppUrl` — env precedence, trailing-slash strip, blank
env fall-through, netlify-preview pass-through, capacitor fallback
(dev + prod), localhost fallback, null fallback.
- Regression — reconstructs the exact failing URL from the bug report
and asserts it now matches the expected
`https://fluxsocial-dev.netlify.app/#/communities/.../conversation`
form with no `capacitor` in it anywhere.
✅ Deploy Preview for fluxsocial-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Review limit reached
More reviews will be available in 51 minutes and 15 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIntroduces ChangesPublic URL Resolution for Deep Links
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
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 `@app/src/utils/publicUrl.ts`:
- Around line 71-74: The code at line 71-74 accepts any non-empty
`opts.envPublicUrl` value without validating that it is actually a valid public
HTTP(S) origin. Before returning the stripped env value, validate that it is a
proper HTTP or HTTPS URL. If the env value is not a valid public origin (does
not start with http:// or https://), reject it and allow the code to continue to
the next fallback logic rather than returning the invalid value, preventing
misconfigured env values from producing broken external deep links.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9c443724-b15d-4dad-a2fd-7d2de9701289
📒 Files selected for processing (6)
app/.env.developmentapp/.env.productionapp/src/app.tsapp/src/utils/__tests__/publicUrl.test.tsapp/src/utils/publicUrl.tsapp/src/utils/registerMobileNotifications.ts
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Summary
Mobile (Capacitor) builds were producing broken deep-link URLs because
window.location.originresolves tocapacitor://localhost— a scheme that only opens inside the running app on the originating device.Reported example:
Expected:
Two places propagate this off-device:
app/src/utils/registerMobileNotifications.ts—appUrl+appIconPathget embedded in push-notification deep links by the AD4M push service.app/src/app.ts—appInfo.url+appInfo.iconPathare sent to AD4M-connect and stored on the capability token.Fix
New
app/src/utils/publicUrl.tsresolves the public URL with this precedence:VITE_PUBLIC_URL(build-time env) — explicit, preferred. Mobile builds inherit it at build time.window.location.originwhen it points at a real public host (notcapacitor:, notlocalhost, not*.local).https://fluxsocial-dev.netlify.appfor non-prod,https://fluxsocial.netlify.appfor prod. The fallback exists so the bug surfaces as "wrong-but-public site" rather than "links 404 silently."Both
.env.developmentand.env.productionnow shipVITE_PUBLIC_URL, so the fallback is a safety net rather than the normal path.Test plan
publicUrl.test.ts) cover every branch — env precedence, trailing-slash strip, blank-env fallthrough, netlify preview pass-through, capacitor/localhost/null fallback, plus a regression test that rebuilds the exact failing URL from the report and asserts the fix.noderun (Flux's local jest setup is missingvue-jest+jest-environment-jsdom; tests are written to the jest convention used byupsertById.test.tsso they'll run in CI where the environment is intact).https://fluxsocial-dev.netlify.app/...rather thancapacitor://localhost/....🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Improvements