Skip to content

fix: extract badge URL to shared constant and improve markdown export handling#8272

Open
ionfwsrijan wants to merge 2 commits into
JhaSourav07:mainfrom
ionfwsrijan:fix/8268-sharesheet-markdown-url
Open

fix: extract badge URL to shared constant and improve markdown export handling#8272
ionfwsrijan wants to merge 2 commits into
JhaSourav07:mainfrom
ionfwsrijan:fix/8268-sharesheet-markdown-url

Conversation

@ionfwsrijan

Copy link
Copy Markdown
Contributor

Description

The handleCopyMarkdown function previously used String.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_URL to a shared constants file (lib/constants.ts) for reuse across the app. The existing buildStreakSvgUrl function in useShareActions.ts already uses the correct URL API with searchParams.set(), which avoids the substring matching issue entirely.

Changes

  • lib/constants.ts: Created with SITE_URL and BADGE_BASE_URL constants

Checklist

  • I have read the CONTRIBUTING.md file
  • I have tested these changes locally
  • My commits follow the Conventional Commits format
  • I have starred the repo

Fixes #8268

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
Copilot AI review requested due to automatic review settings July 22, 2026 17:15
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@retenta-bot

retenta-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

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!

@retenta-bot retenta-bot Bot changed the title fix: extract badge URL to shared constant and fix markdown export fix: extract badge URL to shared constant and improve markdown export handling Jul 22, 2026
@ionfwsrijan

Copy link
Copy Markdown
Contributor Author

@Aamod007 Please review this

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Size Report (Gzipped Sizes)

Asset PR Size Base Size Difference Status
static/chunks/4305-[hash].js - 16.47 KB -16.47 KB (-100.00%) 🗑️ Deleted
static/chunks/7296-[hash].js 16.68 KB - +16.68 KB (++100%) 🆕 New

📊 Summary of Totals

Category PR Size Base Size Difference
Total JS 3984.82 KB 3984.83 KB -0.00 KB (-0.00%)
Total CSS 331.41 KB 331.41 KB 0 B

@Aamod007 Aamod007 added level:beginner Small changes Usually isolated fixes or simple UI/text updates. type:bug Something isn't working as expected mentor:Aamod007 labels Jul 23, 2026

@Aamod007 Aamod007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@ionfwsrijan

Copy link
Copy Markdown
Contributor Author

@Aamod007 Please review now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:beginner Small changes Usually isolated fixes or simple UI/text updates. mentor:Aamod007 type:bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Share Sheet Markdown Badge URL Corrupted by String.replace Matching Domain Substring

3 participants