fix: extract badge URL to shared constant and improve markdown export handling#8272
fix: extract badge URL to shared constant and improve markdown export handling#8272ionfwsrijan wants to merge 2 commits into
Conversation
The handleCopyMarkdown function previously used String.replace to construct the badge URL, which could match the domain name instead of the path segment for certain usernames (e.g., 'vercel'). This was already fixed by refactoring to use URL API, but the fix now also extracts BADGE_BASE_URL to a shared constants file for reuse across the app. Fixes JhaSourav07#8268
|
@ionfwsrijan is attempting to deploy a commit to the jhasourav07's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
This PR addresses the issue of broken badge URLs by extracting the badge URL to a shared constant, which is a great improvement for maintainability and correctness. It aligns with previous decisions made to ensure that badge URLs are constructed correctly without relying on potentially faulty string replacements. Thank you for your contribution, and looking forward to your updates! |
|
@Aamod007 Please review this |
📦 Next.js Bundle Size Report (Gzipped Sizes)
📊 Summary of Totals
|
Aamod007
left a comment
There was a problem hiding this comment.
Thanks for starting on this bug fix! Extracting the base URL to a constant is a great way to avoid the substring matching issue.
However, it looks like you missed committing the actual changes to \handleCopyMarkdown\ (where the replacement logic happens) and any other files where this new constant should be used. The PR currently only contains the new \lib/constants.ts\ file.
To fix this, please commit the rest of your changes (e.g., using \git add\ on the modified files and \git commit) and push them to this branch so we can review the full fix.
Looking forward to seeing the complete implementation!
Label Justification:
- \level:beginner: Refactoring a string replacement into a constant usage is a standard beginner task.
- \ ype:bug: Fixes broken badge URLs during markdown export.
- \mentor:Aamod007: Assigned as required.
…and ShareSheet Import BADGE_BASE_URL from lib/constants in useShareActions and use it in buildStreakSvgUrl instead of constructing the URL with getOrigin(). Import SITE_URL from lib/constants in ShareSheet.tsx and use it for the hardcoded profile URL. Removes unused getOrigin import. Fixes JhaSourav07#8268
|
@Aamod007 Please review now |
Description
The
handleCopyMarkdownfunction previously usedString.replace(username, ...)to construct the badge URL, which could match the domain name instead of the path segment for usernames that are substrings of the domain (e.g., "vercel", "commit", "app"). This produced broken badge URLs that silently failed to render.Fix
Extracted
BADGE_BASE_URLto a shared constants file (lib/constants.ts) for reuse across the app. The existingbuildStreakSvgUrlfunction inuseShareActions.tsalready uses the correctURLAPI withsearchParams.set(), which avoids the substring matching issue entirely.Changes
lib/constants.ts: Created withSITE_URLandBADGE_BASE_URLconstantsChecklist
CONTRIBUTING.mdfileFixes #8268