Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pickChildren breaks when components are wrapped in HOC #2815

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

sapkra
Copy link
Contributor

@sapkra sapkra commented Apr 20, 2024

  • updated react types, fixed alphabetical sorting in package.json

📝 Description

In my project I'm wrapping every component with an HOC, which leads to the problem that pickChildren won't detect the right component type. This change will use the displayName instead which can be passed down by the HOC.

⛳️ Current behavior (updates)

  • compares an entire component object

🚀 New behavior

  • compares just the component name

💣 Is this a breaking change (Yes/No):

No, I don't think so. Already tested a few cases.

Summary by CodeRabbit

  • Updates
    • Updated React and React DOM type definitions to improve compatibility and developer experience.
  • Refactor
    • Enhanced child component selection in utilities to allow filtering by display name, improving component interaction flexibility.

updated react types, fixed alphabetical sorting in package.json
Copy link

changeset-bot bot commented Apr 20, 2024

⚠️ No Changeset found

Latest commit: 3dc3d3f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

vercel bot commented Apr 20, 2024

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

Name Status Preview Comments Updated (UTC)
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 20, 2024 4:50am

Copy link

vercel bot commented Apr 20, 2024

@sapkra is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Apr 20, 2024

Walkthrough

The recent updates primarily focus on refining dependencies and enhancing functionality. Key changes include the removal and updates of several packages in package.json to improve project compatibility and maintenance. Additionally, the children.ts file within the utilities has been modified to incorporate a more precise child component selection mechanism based on the displayName property, enhancing the robustness of component interactions.

Changes

File Summary
package.json - Removed tsx package
- Updated @types/react and @types/react-dom
- Added @storybook/react and intl-messageformat
- Updated concurrently and npm-check-updates
.../react-rsc-utils/src/children.ts Updated pickChildren function to filter child components more accurately using displayName property.

Recent Review Details

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 4cad622 and 3dc3d3f.
Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !pnpm-lock.yaml
Files selected for processing (2)
  • package.json (5 hunks)
  • packages/utilities/react-rsc-utils/src/children.ts (1 hunks)
Additional comments not posted (5)
packages/utilities/react-rsc-utils/src/children.ts (1)

15-15: Ensure the targetChild parameter is documented to explain the new displayName property usage.

Adding a parameter description in the JSDoc comments would improve code maintainability and clarity for future developers.

package.json (4)

70-70: Validate the compatibility of the new Storybook version with existing project configurations.

Ensure that the newly added Storybook version is compatible with the project's existing configurations and addons.


81-82: Confirm the updated React types are compatible with the project's current React version.

It's crucial to ensure that the updated type definitions for React do not introduce type mismatches or require changes in the component definitions.


114-114: Review the necessity and usage of intl-messageformat in the project.

Given that intl-messageformat has been added, it's important to verify its usage and integration within the project to justify its inclusion.


132-132: The removal of the TypeScript version specified by "tsx" should be verified for any potential impacts.

Ensure that the removal of the "tsx" version does not affect any scripts or configurations that depend on this specific version.

Verification successful

The script results indicate that the term "tsx" appears in filenames and a variable within the project. These references seem to be related to TypeScript files (e.g., _app.tsx, custom-button.tsx) rather than a specific version of TypeScript or a script named "tsx". Therefore, it appears that the removal of the "tsx" version from package.json does not directly affect these parts of the codebase.

  • _app.tsx and custom-button.tsx are likely just TypeScript files and do not imply a dependency on the specific version mentioned in package.json.
  • The variable fileName constructing a .tsx filename does not suggest a dependency on the specific TypeScript version either.

Based on this analysis, the removal of the TypeScript version specified by "tsx" in package.json should not impact the identified files or configurations.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check if the tsx script is used elsewhere in the project.
fd 'tsx' --exec rg 'tsx' {}

Length of output: 143


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 1

Comment on lines +21 to +25
if (
targetChild.displayName &&
typeof item.type === "object" &&
(item.type as ComponentType).displayName === targetChild.displayName
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Refine the component type checking logic.

-    if (
-      targetChild.displayName &&
-      typeof item.type === "object" &&
-      (item.type as ComponentType).displayName === targetChild.displayName
-    ) {
+    if (targetChild.displayName && item.type?.displayName === targetChild.displayName) {

This change simplifies the condition by using optional chaining and removes the redundant type check, making the code cleaner and potentially more performant.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (
targetChild.displayName &&
typeof item.type === "object" &&
(item.type as ComponentType).displayName === targetChild.displayName
) {
if (targetChild.displayName && item.type?.displayName === targetChild.displayName) {

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

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

can you please share a failing example for us to test?

@wingkwong wingkwong changed the base branch from main to canary April 28, 2024 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants