-
Notifications
You must be signed in to change notification settings - Fork 17
Fix the url localization for the share links #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
|
@m7moud is attempting to deploy a commit to the DigitalSeem's projects Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughAdjusted locale handling in useBookShareUrl.getUrl: locale segment is now appended to the base URL with a trailing slash instead of being prefixed before the origin. Other URL components (reader path, optional versionId query, selection fragment) remain unchanged. No exported/public signatures were modified. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/lib/share.ts (3)
26-28: Bug fixed; normalize path joining to avoid//and locale/path edge casesThe change resolves the
arhttps://...bug. To make joins robust regardless of trailing/leading slashes and whetherpageReaderreturns/t/...ort/..., normalize both sides.Apply this diff:
- if (locale !== routing.defaultLocale) url = `${url}${pathLocale}/`; - url += navigation.books.pageReader(slug, pageIndex + 1); + if (locale !== routing.defaultLocale) + url = `${url.replace(/\/+$/, "")}${pathLocale.replace(/^\/?/, "/").replace(/\/+$/, "")}`; + url = `${url.replace(/\/+$/, "")}/${navigation.books.pageReader(slug, pageIndex + 1).replace(/^\/+/, "")}`;
29-29: Encode query param valueSafer in case
versionIdcontains special characters.Apply this diff:
- if (versionId) url += `?versionId=${versionId}`; + if (versionId) url += `?versionId=${encodeURIComponent(versionId)}`;
50-54: Handle clipboard write failuresAvoid showing success when
navigator.clipboardis unavailable or denied.Apply this diff:
- const url = getUrl({ slug, pageIndex, versionId, selection }); - await navigator.clipboard.writeText(url); - - toast.success(t("reader.chat.copied")); + const url = getUrl({ slug, pageIndex, versionId, selection }); + try { + await navigator.clipboard.writeText(url); + toast.success(t("reader.chat.copied")); + } catch { + toast.error("Failed to copy URL"); + }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/lib/share.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/lib/share.ts (1)
src/i18n/config.ts (1)
routing(4-42)
🔇 Additional comments (1)
src/lib/share.ts (1)
24-24: Ensure client-only usage or guardwindowaccessHook accesses window.location.origin and navigator.clipboard — ensure it's only invoked from client components (add "use client" to callers) or add a runtime guard (e.g., check typeof window !== "undefined" and navigator?.clipboard before use).
Location: src/lib/share.ts —
let url = window.location.origin;Repo scan did not return call sites; verify callers are client components or add guards.
Please test this case:
The links for citations and sources in the Arabic locale are something like:
arhttps://usul.ai/t/nadhra-al-naeem-fi-makarem-akhlaq-al-rasool-al-kareem/5186It should be:
https://usul.ai/ar/t/nadhra-al-naeem-fi-makarem-akhlaq-al-rasool-al-kareem/5186Summary by CodeRabbit