Skip to content

fix(calendar): invalid prop ref supplied to React.Fragment#4428

Merged
jrgarciadev merged 2 commits into
canaryfrom
fix/eng-1727
Dec 22, 2024
Merged

fix(calendar): invalid prop ref supplied to React.Fragment#4428
jrgarciadev merged 2 commits into
canaryfrom
fix/eng-1727

Conversation

@wingkwong
Copy link
Copy Markdown
Member

@wingkwong wingkwong commented Dec 22, 2024

📝 Description

In 2.3.0, PopLayoutWrapper was used to forward the ref.

const PopLayoutWrapper = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
  (props, ref) => {
    return <div ref={ref} {...props} />;
  },
);

At some point (couldn't trace when probably due to force push), it was changed to use React.Fragment, i.e. <></>. This is where the error is thrown.

In Ripple component, there is the same pattern (i.e. replace PopLayoutWrapper by <></>) and the fragment got removed in this commit. Hence, applying the same change to calendar-base.tsx.

⛳️ Current behavior (updates)

Sandbox provided by the user: https://codesandbox.io/p/devbox/friendly-diffie-55mxp5

image

🚀 New behavior

I cloned the above sandbox and link to my local package for testing.

pr4428-demo.webm

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

📝 Additional Information

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Dec 22, 2024

🦋 Changeset detected

Latest commit: 0e9cfd3

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

This PR includes changesets to release 3 packages
Name Type
@nextui-org/calendar Patch
@nextui-org/date-picker Patch
@nextui-org/react Patch

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

@linear
Copy link
Copy Markdown

linear Bot commented Dec 22, 2024

@vercel
Copy link
Copy Markdown

vercel Bot commented Dec 22, 2024

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

Name Status Preview Comments Updated (UTC)
nextui-docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 22, 2024 9:39am
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 22, 2024 9:39am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 22, 2024

Walkthrough

The pull request addresses a bug in the @nextui-org/calendar package by removing an unnecessary fragment in the CalendarBase component. The change specifically targets an issue with invalid prop references to React.Fragment, which was causing errors when using the DateRangePicker and Datepicker components in Next.js 15 and React 19. The modification simplifies the component's structure without altering its core functionality.

Changes

File Change Summary
packages/components/calendar/src/calendar-base.tsx Removed unnecessary fragment from AnimatePresence component, directly placing MotionConfig as a child
.changeset/chilled-files-serve.md Patch file for the @nextui-org/calendar package

Assessment against linked issues

Objective Addressed Explanation
Resolve invalid prop error in React.Fragment [#4358, #4068]
Fix DateRangePicker and Datepicker component issues

Possibly related issues

Possibly related PRs

Suggested labels

👀 Status: In Review

Suggested reviewers

  • jrgarciadev

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5494fa2 and 0e9cfd3.

📒 Files selected for processing (2)
  • .changeset/chilled-files-serve.md (1 hunks)
  • packages/components/calendar/src/calendar-base.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/chilled-files-serve.md
🔇 Additional comments (1)
packages/components/calendar/src/calendar-base.tsx (1)

155-157: LGTM! Fragment removal fixes the invalid prop reference issue.

The removal of the unnecessary Fragment wrapper around MotionConfig is the correct approach, as Fragments are only needed when grouping multiple children. This change resolves the invalid prop reference issues with React.Fragment while maintaining the component's functionality.

Let's verify the React 19 compatibility:

✅ Verification successful

LGTM! The Fragment removal is safe and improves React 19 compatibility.

The codebase scan confirms that the Fragment removal in calendar-base.tsx is appropriate. The remaining Fragment usages in the codebase are either:

  1. Necessary for grouping multiple children
  2. Used with explicit key props for list rendering
  3. Used as named imports for TypeScript type safety

The change aligns with React best practices by removing unnecessary Fragment wrapper when there's only one child element (MotionConfig).

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining Fragment usage that might cause issues
# with prop references in React 19

# Search for Fragment usage in calendar components
rg -A 2 "Fragment|<>|</>" --type typescript --type typescriptreact

# Look for potential prop passing to Fragments
ast-grep --pattern 'Fragment $props {$$$}'

Length of output: 148


Script:

#!/bin/bash
# Search for Fragment usage in calendar components with correct file extensions
rg -A 2 "Fragment|<>|</>" -g "*.tsx" -g "*.ts"

# Look for potential prop passing to Fragments in tsx files
rg -A 2 "Fragment.*props" -g "*.tsx" -g "*.ts"

# Check for any remaining Fragment imports
rg "import.*Fragment" -g "*.tsx" -g "*.ts"

Length of output: 29376


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>, please review it.
    • 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 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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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. (Beta)
  • @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.

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.

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

Labels

None yet

Projects

None yet

2 participants