Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Jun 27, 2025

Summary by CodeRabbit

  • New Features

    • Social media handle inputs for YouTube, Twitter, LinkedIn, Instagram, and TikTok are now automatically sanitized when pasted or submitted, ensuring consistency and cleanliness.
    • Added a script to clean up existing partner social media handles in the database.
  • Refactor

    • Improved the handling of pasted social media handles in the online presence form for better user experience and data quality.

@vercel
Copy link
Contributor

vercel bot commented Jun 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jun 27, 2025 5:58pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 27, 2025

Walkthrough

The changes introduce a new utility for sanitizing social media handles, apply this sanitization in the partner online presence update schema, refactor form paste handling to use the sanitizer, and add a script to retroactively clean existing database records. The sanitizer standardizes handle formats across five social platforms.

Changes

Files/Groups Change Summary
apps/web/lib/social-utils.ts New module providing sanitizeSocialHandle for cleaning social handles for YouTube, Twitter, LinkedIn, Instagram, and TikTok.
apps/web/lib/actions/partners/update-online-presence.ts Updated validation schema to sanitize social handles using the new utility during parsing.
apps/web/ui/partners/online-presence-form.tsx Refactored paste handler to use the sanitizer and update form state accordingly.
apps/web/scripts/sanitize-social-handles.ts New script to sanitize and update existing partner social handles in the database.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant OnlinePresenceForm
    participant sanitizeSocialHandle
    participant FormState

    User->>OnlinePresenceForm: Paste social handle
    OnlinePresenceForm->>sanitizeSocialHandle: Sanitize pasted input (with platform)
    sanitizeSocialHandle-->>OnlinePresenceForm: Return sanitized handle
    OnlinePresenceForm->>FormState: Update field value with sanitized handle
Loading
sequenceDiagram
    participant Script
    participant Database
    participant sanitizeSocialHandle

    Script->>Database: Query partners with social handles
    loop For each partner and handle
        Script->>sanitizeSocialHandle: Sanitize handle (with platform)
    end
    Script->>Database: Update partner records with sanitized handles
Loading

Suggested reviewers

  • steven-tey

Poem

In the warren of code, a bunny did hop,
Cleaning up handles with a sanitizer mop.
From TikTok to Twitter, each handle now neat,
No rogue URLs or stray @ signs to greet.
With a twitch of the nose and a hop in the night,
The partners' profiles are now just right! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c26aa5 and 1df8f5c.

📒 Files selected for processing (1)
  • apps/web/ui/partners/online-presence-form.tsx (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/ui/partners/online-presence-form.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
apps/web/scripts/sanitize-social-handles.ts (1)

49-58: Optimize sanitization trigger condition.

The current condition value.startsWith("http") || value.startsWith("@") may miss handles that need sanitization but don't start with these prefixes (e.g., handles with disallowed characters or incorrect casing).

Consider sanitizing all handles and comparing the result to the original:

-    for (const [platform, value] of Object.entries(socialHandles)) {
-      if (value && (value.startsWith("http") || value.startsWith("@"))) {
-        updatedSocialHandles[platform] = sanitizeSocialHandle(
-          value,
-          platform as SocialPlatform,
-        );
-
-        needsUpdate = true;
-      }
-    }
+    for (const [platform, value] of Object.entries(socialHandles)) {
+      if (value) {
+        const sanitized = sanitizeSocialHandle(
+          value,
+          platform as SocialPlatform,
+        );
+        
+        if (sanitized !== value) {
+          updatedSocialHandles[platform] = sanitized;
+          needsUpdate = true;
+        }
+      }
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f4c0ec and 4c26aa5.

📒 Files selected for processing (5)
  • apps/web/lib/actions/partners/update-online-presence.ts (2 hunks)
  • apps/web/lib/social-utils.ts (1 hunks)
  • apps/web/scripts/sanitize-social-handles.ts (1 hunks)
  • apps/web/ui/partners/online-presence-form.tsx (8 hunks)
  • apps/web/ui/partners/online-presence-summary.tsx (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
apps/web/ui/partners/online-presence-summary.tsx (1)
Learnt from: devkiran
PR: dubinc/dub#2448
File: packages/email/src/templates/partner-program-summary.tsx:0-0
Timestamp: 2025-05-29T04:45:18.504Z
Learning: In the PartnerProgramSummary email template (packages/email/src/templates/partner-program-summary.tsx), the stat titles are hardcoded constants ("Clicks", "Leads", "Sales", "Earnings") that will always match the ICONS object keys after toLowerCase() conversion, so icon lookup failures are not possible.
apps/web/scripts/sanitize-social-handles.ts (1)
Learnt from: devkiran
PR: dubinc/dub#2177
File: apps/web/lib/api/links/bulk-create-links.ts:66-84
Timestamp: 2025-06-06T07:59:03.120Z
Learning: In apps/web/lib/api/links/bulk-create-links.ts, the team accepts the risk of potential undefined results from links.find() operations when building invalidLinks arrays, because existing links are fetched from the database based on the input links, so matches are expected to always exist.
🧬 Code Graph Analysis (4)
apps/web/ui/partners/online-presence-summary.tsx (1)
apps/web/lib/social-utils.ts (2)
  • sanitizeSocialHandle (48-85)
  • SocialPlatform (1-6)
apps/web/scripts/sanitize-social-handles.ts (1)
apps/web/lib/social-utils.ts (2)
  • sanitizeSocialHandle (48-85)
  • SocialPlatform (1-6)
apps/web/lib/actions/partners/update-online-presence.ts (1)
apps/web/lib/social-utils.ts (1)
  • sanitizeSocialHandle (48-85)
apps/web/ui/partners/online-presence-form.tsx (1)
apps/web/lib/social-utils.ts (1)
  • SocialPlatform (1-6)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (12)
apps/web/lib/social-utils.ts (3)

1-6: LGTM: Well-defined type union.

The SocialPlatform type properly constrains the supported platforms and will provide good TypeScript support throughout the codebase.


48-85: Robust sanitization function with comprehensive validation.

The function handles edge cases well and follows a logical sanitization flow. The implementation correctly:

  • Validates input types and null/undefined values
  • Removes URL prefixes and extracts handles using platform-specific patterns
  • Applies character filtering and length constraints
  • Returns null for invalid inputs

The logic is sound and should handle most real-world social media URL and handle formats.


14-46: Review platform configurations for accuracy.

The platform configurations look comprehensive, but there are a few considerations:

  1. YouTube patterns: The regex /^@([^\/\?]+)/i may be too permissive for handles starting with @ - it doesn't validate YouTube's specific handle requirements.

  2. TikTok max length: The 24-character limit seems correct, but verify this aligns with TikTok's current username requirements.

  3. LinkedIn pattern: Consider if the pattern should also handle company pages (/company/) in addition to personal profiles (/in/).

What are the current username length limits and character requirements for YouTube, TikTok, and LinkedIn usernames?
apps/web/ui/partners/online-presence-summary.tsx (3)

1-1: LGTM: Proper import of sanitization utilities.

The import correctly brings in both the function and type from the new social-utils module.


55-55: LGTM: Updated label reflects current branding.

Changing from "X/Twitter" to "X" aligns with the platform's current branding.


131-136: ```shell
#!/bin/bash

Locate the sanitizeSocialHandle function in social-utils.ts

echo "Searching for sanitizeSocialHandle definition..."
rg -n "sanitizeSocialHandle" -A 10 apps/web/lib/social-utils.ts


</details>
<details>
<summary>apps/web/scripts/sanitize-social-handles.ts (2)</summary>

`6-27`: **LGTM: Efficient database query with safety limits.**

The query properly filters for partners with social handles and uses pagination with a conservative limit of 10 records. The field selection is optimal, only fetching necessary data.

---

`66-72`: **LGTM: Safe database update with proper error handling.**

The update operation is properly isolated per partner with clear logging. The script structure allows for easy monitoring of changes.

</details>
<details>
<summary>apps/web/lib/actions/partners/update-online-presence.ts (2)</summary>

`7-7`: **LGTM: Proper import of sanitization function.**

The import correctly brings in the sanitization utility for use in the schema transformations.

---

`19-38`: **LGTM: Consistent sanitization across all social platforms.**

The schema transformations properly apply sanitization to all social media handle inputs during validation. This ensures data consistency at the API boundary and complements the frontend sanitization.

</details>
<details>
<summary>apps/web/ui/partners/online-presence-form.tsx (2)</summary>

`77-77`: **LGTM: Added setValue for form field updates.**

Properly adds `setValue` to the form destructuring to support the new paste handling logic.

---

`210-210`: **LGTM: Consistent paste handling across all social inputs.**

The paste handlers are properly applied to all social media input fields with the correct platform identifiers.



Also applies to: 244-244, 278-278, 313-313, 351-351

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@devkiran
Copy link
Collaborator Author

@coderabbitai full review, any breaking changes?

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 27, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

I'll perform a comprehensive review and analyze potential breaking changes. Let me examine the codebase to understand the impact of these changes.


🏁 Script executed:

#!/bin/bash
# First, let's examine the schema file to understand the changes better
echo "=== Examining the schema changes ==="
cat apps/web/lib/actions/partners/update-online-presence.ts

echo -e "\n=== Looking for usages of updateOnlinePresenceSchema ==="
rg "updateOnlinePresenceSchema" -A 3 -B 3

echo -e "\n=== Checking for any existing social handle processing ==="
rg "sanitize.*social|social.*sanitize" -i

echo -e "\n=== Looking for imports of social-utils ==="
rg "social-utils" -A 2 -B 2

Length of output: 11218


🏁 Script executed:

#!/bin/bash
# Let's check for API endpoints or other consumers that might use this schema
echo "=== Looking for API endpoints using updateOnlinePresenceAction ==="
rg "updateOnlinePresenceAction" -A 5 -B 5

echo -e "\n=== Checking for any direct database queries on social handles ==="
rg "youtube|twitter|linkedin|instagram|tiktok" apps/web/lib/actions/partners/ -A 2 -B 2

echo -e "\n=== Looking for any tests that might be affected ==="
fd -e test.ts -e spec.ts | head -10
rg "updateOnlinePresence" --include="*.test.*" --include="*.spec.*"

echo -e "\n=== Checking if the schema is exported or used elsewhere ==="
rg "export.*updateOnlinePresenceSchema" 
rg "import.*updateOnlinePresenceSchema"

Length of output: 17741


🏁 Script executed:

#!/bin/bash
# Let's check for any tests related to social handles or online presence
echo "=== Searching for tests with correct ripgrep syntax ==="
rg "updateOnlinePresence" apps/web/tests/

echo -e "\n=== Looking for any API routes that might consume this data ==="
rg "updateOnlinePresence" apps/web/app/ apps/web/pages/

echo -e "\n=== Checking if there are any existing social handle validations ==="
rg "social.*handle|handle.*social" -i apps/web/lib/

echo -e "\n=== Looking at the social-utils to understand the transformation ==="
cat apps/web/lib/social-utils.ts

Length of output: 3433


@devkiran After conducting a comprehensive review of the PR changes, I can provide you with a detailed analysis of potential breaking changes:

🔍 Full Review Summary

✅ Non-Breaking Changes:

  1. New utility module (social-utils.ts) - Pure addition, no breaking changes
  2. Form paste handler refactor - Improves UX, doesn't break existing functionality
  3. Migration script - Data cleanup tool, doesn't affect code contracts
  4. Internal schema usage - Schema is not exported and only used within the action

⚠️ Potential Breaking Changes:

1. Data Transformation in Schema (Medium Risk)

// BEFORE: Raw input stored directly
youtube: z.string().nullish()

// AFTER: Input sanitized before storage  
youtube: z.string().nullish().transform(input => sanitizeSocialHandle(input, "youtube"))

Impact:

  • URLs like https://twitter.com/usernameusername
  • Handles like @usernameusername
  • Invalid characters stripped and handles truncated to platform limits

2. Database Data Format Change (Low Risk)

The sanitization will change how social handles are stored:

// Input: "https://youtube.com/@myhandle" 
// Stored: "myhandle"

3. Verification Logic Dependencies (Low Risk)

The verification code expects clean handle formats and should work correctly:

// This comparison should still work with sanitized handles
partner.twitter.toLowerCase() === username.toLowerCase()

🛡️ Risk Mitigation Factors:

  1. Contained scope - Schema only used in updateOnlinePresenceAction
  2. No external consumers - Schema not exported or used by external APIs
  3. Planned migration - Script exists to clean existing data retroactively
  4. Verification compatibility - Verification logic already expects clean handle formats

📋 Recommendations:

  1. Test verification flows with existing partner data before deployment
  2. Run the migration script on staging to ensure data cleanup works correctly
  3. Monitor verification success rates after deployment to catch any edge cases

Final Assessment: ✅ Minimal Breaking Change Risk

The changes are well-contained and appear to be a planned improvement to data quality. The main risk is around data consistency during the transition period, but the migration script and verification logic compatibility suggest this has been properly planned.

Would you like me to examine any specific aspect more deeply?

@steven-tey steven-tey merged commit 27d3c91 into main Jun 27, 2025
5 of 7 checks passed
@steven-tey steven-tey deleted the fix-social-urls branch June 27, 2025 17:56
@coderabbitai coderabbitai bot mentioned this pull request Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants