Skip to content

Feat/add canonical url support#16

Merged
umsungjun merged 2 commits intomainfrom
feat/add-canonical-url-support
Mar 2, 2026
Merged

Feat/add canonical url support#16
umsungjun merged 2 commits intomainfrom
feat/add-canonical-url-support

Conversation

@umsungjun
Copy link
Owner

@umsungjun umsungjun commented Mar 2, 2026

Summary by CodeRabbit

  • New Features

    • Added canonical URL support via new canonicalUrl prop for improved SEO management.
    • Component now automatically manages <link rel="canonical"> tags in the document head.
  • Documentation

    • Updated README with canonical URL usage examples and API reference.
  • Tests

    • Added comprehensive test coverage for canonical URL functionality.

umsungjun and others added 2 commits March 2, 2026 15:24
Add `canonicalUrl` prop that renders `<link rel="canonical">` in the
document head. This helps search engines identify the preferred URL for
a page, preventing duplicate content penalties in CSR SPAs.

- Add `canonicalUrl` optional prop to `ReactHeadSafeProps`
- Implement `updateLinkTag` helper for `<link>` element management
- Add tests for creation, update, and duplicate prevention
- Update README.md and README.ko.md with new prop documentation
- Add `canonicalUrl` usage to all example pages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Mar 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-head-safe Ready Ready Preview, Comment Mar 2, 2026 7:21am

@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5227a37 and 720a15f.

📒 Files selected for processing (9)
  • README.ko.md
  • README.md
  • examples/basic/src/pages/About.tsx
  • examples/basic/src/pages/Contact.tsx
  • examples/basic/src/pages/Home.tsx
  • package.json
  • src/ReactHeadSafe.tsx
  • src/test/ReactHeadSafe.test.tsx
  • src/types.ts

📝 Walkthrough

Walkthrough

This pull request adds support for a new canonicalUrl prop to the ReactHeadSafe component, allowing users to specify canonical URLs for SEO purposes. The implementation includes a helper function to manage canonical link tags in the document head and prevents duplicate tags through tag removal before creation.

Changes

Cohort / File(s) Summary
Type Definitions & Core Logic
src/types.ts, src/ReactHeadSafe.tsx
Added canonicalUrl?: string prop to ReactHeadSafeProps interface and implemented updateLinkTag helper to create/update canonical <link rel="canonical"> tags with duplicate prevention.
Test Coverage
src/test/ReactHeadSafe.test.tsx
Added tests covering canonical link tag creation, prop updates, and preventing duplicate tags across re-renders in multi-prop scenarios.
Documentation
README.md, README.ko.md
Updated API documentation and usage examples to reflect the new canonicalUrl prop and its role in rendering canonical link tags.
Example Usage
examples/basic/src/pages/*
Added canonicalUrl prop to ReactHeadSafe component invocations across Home.tsx, Contact.tsx, and About.tsx example pages.
Metadata
package.json
Version bumped from 1.3.0 to 1.4.0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A canonical hop through SEO's domain,
Link tags now managed without a strain,
From Home to About, the URLs align,
Version 1.4 marks the design so fine!
Our pages know their place, divine! ✨

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/add-canonical-url-support

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@umsungjun umsungjun merged commit 4bac90a into main Mar 2, 2026
4 of 5 checks passed
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.

2 participants