Skip to content

Conversation

@saseungmin
Copy link
Member

@saseungmin saseungmin commented Jun 19, 2025

  • Support string (videoId or URL) and object formats
  • Add useYouTubeVideoId hook for source parsing
  • Maintain backward compatibility with videoId extraction

Summary by CodeRabbit

  • New Features

    • Introduced a flexible source prop for the YouTube player, accepting a video ID string, YouTube URL, or an object with videoId or url.
    • Added support for multiple YouTube URL formats.
    • Added a new hook to internally extract and validate the video ID from the source.
  • Breaking Changes

    • Replaced the videoId prop with the new source prop in the YouTube player component.
  • Documentation

    • Updated all documentation and usage examples to use the new source prop.
  • Bug Fixes

    • Enhanced video ID extraction and validation logic for improved accuracy and reliability.
    • Removed console error logs on invalid video IDs for cleaner output.

- Support string (videoId or URL) and object formats
- Add useYouTubeVideoId hook for source parsing
- Maintain backward compatibility with videoId extraction
@changeset-bot
Copy link

changeset-bot bot commented Jun 19, 2025

🦋 Changeset detected

Latest commit: 60f0f4a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-native-youtube-bridge Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Jun 19, 2025

Walkthrough

This change replaces the videoId prop with a new, more flexible source prop for the YouTube player component, allowing input as a string or object with a video ID or URL. It introduces a hook for extracting the video ID, updates validation and extraction utilities, and revises documentation and examples accordingly.

Changes

File(s) Change Summary
.changeset/three-papayas-design.md Documents the breaking change: videoId prop replaced by flexible source prop; new hook for extracting video ID.
README.md, README-ko_kr.md Updates documentation and examples to use the new source prop instead of videoId.
example/src/App.tsx Changes prop in example usage from videoId to source.
src/YoutubePlayer.tsx, src/YoutubePlayer.web.tsx Replaces direct videoId prop usage with source and integrates new hook for video ID extraction.
src/hooks/useYoutubeVideoId.ts Adds new exported hook useYouTubeVideoId for extracting and validating video ID from the source prop.
src/hooks/useCreateLocalPlayerHtml.ts Removes console error log for invalid video ID; now fails silently with an HTML message.
src/modules/YouTubePlayerCore.ts Redefines local PlayerConfig type to require a videoId and exclude source from props.
src/types/youtube.ts Changes YoutubePlayerProps to replace videoId with source; introduces new YouTubeSource type.
src/utils/validate.ts Consolidates and improves YouTube URL regex; updates extraction and validation functions for video IDs, changes return type semantics.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant YoutubePlayer
    participant useYouTubeVideoId
    participant validate/extract Utils

    App->>YoutubePlayer: Passes source prop (string/object)
    YoutubePlayer->>useYouTubeVideoId: Calls with source
    useYouTubeVideoId->>validate/extract Utils: Validate or extract videoId
    validate/extract Utils-->>useYouTubeVideoId: Returns videoId or undefined
    useYouTubeVideoId-->>YoutubePlayer: Returns videoId (string or empty)
    YoutubePlayer-->>App: Renders player with derived videoId
Loading

Poem

A hop and a skip, a new prop in play,
No more just videoId, source leads the way!
URLs or IDs, it handles with flair,
A hook finds the magic, the video is there.
Docs now are clearer, examples anew—
The rabbit approves this flexible view! 🐇✨


📜 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 f0ef7c3 and 60f0f4a.

📒 Files selected for processing (1)
  • src/hooks/useYoutubeVideoId.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/hooks/useYoutubeVideoId.ts
✨ Finishing Touches
  • 📝 Generate Docstrings

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

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jun 19, 2025

Deploying react-native-youtube-bridge with  Cloudflare Pages  Cloudflare Pages

Latest commit: 60f0f4a
Status: ✅  Deploy successful!
Preview URL: https://ad51bffc.react-native-youtube-bridge.pages.dev
Branch Preview URL: https://feat-flexible-source-prop.react-native-youtube-bridge.pages.dev

View logs

@saseungmin saseungmin changed the title feat: replace videoId prop with flexible source prop feat: add flexible source prop to support videoId and URL Jun 19, 2025
Copy link

@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: 1

♻️ Duplicate comments (1)
src/YoutubePlayer.tsx (1)

44-44: Consistent source parsing implementation.

The useYouTubeVideoId hook usage matches the web implementation pattern, ensuring consistent behavior across platforms. The extracted videoId correctly integrates with the existing validation and player logic.

🧹 Nitpick comments (5)
example/src/App.tsx (1)

177-177: Correct API migration maintaining backward compatibility.

The change from videoId to source prop correctly demonstrates the API update. Since videoId is a string, it's fully compatible with the new YouTubeSource union type.

Consider enhancing the example to showcase the new flexible source formats:

// Could add examples like:
// source="https://www.youtube.com/watch?v=AbZH7XWDW_k"
// source={{ videoId: "AbZH7XWDW_k" }}
// source={{ url: "https://youtu.be/AbZH7XWDW_k" }}
README.md (1)

43-47: Consider showing concrete source values in the basic usage example.

The example uses source={source} without defining what the source variable contains. Consider showing concrete examples to make it clearer for developers:

-    <YoutubePlayer 
-      source={source} // youtube videoId or url
-      // OR source={{ videoId: 'AbZH7XWDW_k' }}
-      // OR source={{ url: 'https://youtube.com/watch?v=AbZH7XWDW_k' }}
-    />
+    <YoutubePlayer 
+      source="AbZH7XWDW_k" // youtube videoId
+      // OR source={{ videoId: 'AbZH7XWDW_k' }}
+      // OR source={{ url: 'https://youtube.com/watch?v=AbZH7XWDW_k' }}
+    />
src/hooks/useYoutubeVideoId.ts (2)

6-6: Provide explanation for the biome-ignore comment.

The ignore comment should include a proper explanation of why exhaustive dependencies checking is disabled.

- // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
+ // biome-ignore lint/correctness/useExhaustiveDependencies: Custom dependency array needed for source object comparison

21-23: Simplify the complex dependency array to improve maintainability.

The current dependency array is complex and error-prone. Consider extracting the logic or using a more straightforward approach:

- ], [
-   typeof source === 'string' ? source : 'videoId' in source ? source.videoId : 'url' in source ? source.url : null,
- ]);
+ ], [source]);

Since the source object reference would change when its properties change, using [source] should be sufficient and more readable.

README-ko_kr.md (1)

43-47: Consider showing concrete source values in the Korean documentation as well.

Similar to the English README, consider showing concrete examples instead of source={source}:

-    <YoutubePlayer 
-      source={source} // youtube videoId or url
-      // OR source={{ videoId: 'AbZH7XWDW_k' }}
-      // OR source={{ url: 'https://youtube.com/watch?v=AbZH7XWDW_k' }}
-    />
+    <YoutubePlayer 
+      source="AbZH7XWDW_k" // youtube videoId
+      // OR source={{ videoId: 'AbZH7XWDW_k' }}
+      // OR source={{ url: 'https://youtube.com/watch?v=AbZH7XWDW_k' }}
+    />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 07333dd and f0ef7c3.

📒 Files selected for processing (11)
  • .changeset/three-papayas-design.md (1 hunks)
  • README-ko_kr.md (5 hunks)
  • README.md (5 hunks)
  • example/src/App.tsx (1 hunks)
  • src/YoutubePlayer.tsx (3 hunks)
  • src/YoutubePlayer.web.tsx (1 hunks)
  • src/hooks/useCreateLocalPlayerHtml.ts (0 hunks)
  • src/hooks/useYoutubeVideoId.ts (1 hunks)
  • src/modules/YouTubePlayerCore.tsx (1 hunks)
  • src/types/youtube.ts (1 hunks)
  • src/utils/validate.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • src/hooks/useCreateLocalPlayerHtml.ts
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/modules/YouTubePlayerCore.tsx (1)
src/types/youtube.ts (1)
  • YoutubePlayerProps (56-78)
src/YoutubePlayer.web.tsx (1)
src/types/youtube.ts (1)
  • YoutubePlayerProps (56-78)
src/hooks/useYoutubeVideoId.ts (2)
src/types/youtube.ts (3)
  • YouTubeSource (54-54)
  • PlayerEvents (36-52)
  • ERROR_CODES (107-118)
src/utils/validate.ts (2)
  • validateVideoId (14-17)
  • extractVideoIdFromUrl (4-12)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (15)
src/types/youtube.ts (2)

54-54: Well-designed flexible type definition.

The YouTubeSource union type provides excellent flexibility by supporting string video IDs, objects with videoId, and objects with url. This enables multiple input formats while maintaining type safety.


57-57: Clean API improvement with backward compatibility.

Replacing videoId with source in YoutubePlayerProps provides a more intuitive and flexible API. Since strings are supported in the union type, this maintains backward compatibility for existing string video ID usage.

src/modules/YouTubePlayerCore.tsx (2)

2-2: Clean import simplification.

Removing the PlayerConfig alias import and defining it locally provides better separation of concerns.


5-7: Well-designed internal type that maintains clear boundaries.

The local PlayerConfig type correctly excludes the flexible source prop and requires a concrete videoId string. This maintains a clean separation where the core module works with validated video IDs while parent components handle source parsing and validation.

src/YoutubePlayer.web.tsx (2)

5-5: Correct import for source parsing hook.

Adding the useYouTubeVideoId import enables flexible source format handling.


9-10: ```shell
#!/bin/bash

Print YouTubeSource, YoutubePlayerProps, and PlayerEvents definitions

rg -n "export type YouTubeSource" -A5 src/types/youtube.ts
rg -n "export type YoutubePlayerProps" -A5 src/types/youtube.ts
rg -n "export type PlayerEvents" -A5 src/types/youtube.ts


</details>
<details>
<summary>src/YoutubePlayer.tsx (2)</summary>

`6-6`: **Consistent import across platforms.**

Adding the `useYouTubeVideoId` import maintains consistency with the web implementation.

---

`16-16`: **Correct prop destructuring update.**

Updating the destructuring from `videoId` to `source` aligns with the new API while maintaining all other props.

</details>
<details>
<summary>README.md (1)</summary>

`127-127`: **LGTM! Documentation consistently updated.**

All examples throughout the documentation have been properly updated to use the new `source` prop instead of `videoId`. The changes are consistent and maintain clarity.




Also applies to: 165-165, 185-185, 224-224

</details>
<details>
<summary>src/hooks/useYoutubeVideoId.ts (1)</summary>

`7-23`: **LGTM! Source normalization logic is well-structured.**

The source normalization logic correctly handles all three input formats (string, object with videoId, object with url) and provides appropriate fallback behavior.

</details>
<details>
<summary>README-ko_kr.md (1)</summary>

`127-127`: **LGTM! Korean documentation properly updated.**

All examples in the Korean documentation have been consistently updated to use the new `source` prop, maintaining consistency with the English version.




Also applies to: 165-165, 185-185, 224-224

</details>
<details>
<summary>.changeset/three-papayas-design.md (1)</summary>

`1-12`: **LGTM! Well-documented breaking change.**

The changeset properly documents this as a breaking change with clear information about:
- The replacement of `videoId` prop with `source` prop
- The flexible input formats supported
- The new internal hook
- Support for multiple YouTube URL formats

The minor version bump is appropriate for this breaking change.

</details>
<details>
<summary>src/utils/validate.ts (3)</summary>

`1-2`: **LGTM! Comprehensive YouTube URL regex consolidation.**

The consolidated regex pattern effectively matches multiple YouTube URL formats including:
- youtu.be short URLs
- Various youtube.com paths (embed, v, watch, shorts, live)
- YouTube variants (nocookie, education)

This is a good improvement over having multiple patterns.

---

`4-12`: **LGTM! Improved function signature with better type safety.**

The changes improve the function:
- Optional parameter allows for more flexible usage
- Returning `undefined` instead of `null` is more consistent with modern TypeScript practices
- Early return for empty input prevents unnecessary regex execution

---

`14-17`: **LGTM! Simplified regex maintains same validation logic.**

The simplified regex `/^[\w-]{11}$/` is equivalent to the previous pattern but more concise. The `\w` character class includes `[a-zA-Z0-9_]`, so adding the hyphen covers the same validation requirements.

</details>

</blockquote></details>

</details>

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

@saseungmin saseungmin merged commit 4925df0 into main Jun 19, 2025
6 checks passed
@saseungmin saseungmin deleted the feat/flexible-source-prop branch June 19, 2025 12:19
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