nextui icon indicating copy to clipboard operation
nextui copied to clipboard

Fix lazy load error in Plasmo

Open Xheldon opened this issue 9 months ago • 4 comments

Closes #

📝 Description

When using the HeroUI Toast component in Plasmo, there's a bug that makes the page not render. After debugging, we found it's because ToastProvider lazy loads framer-motion's domMax. Check out the related error:

https://github.com/PlasmoHQ/plasmo/issues/1180 https://github.com/PlasmoHQ/plasmo/issues/1241

⛳️ Current behavior (updates)

You can check the image descriptions in the two issues mentioned above. This problem causes the page to not render at all, with an error saying "xxx is not a function."

Maybe it's an issue with Parcel used by Plasmo, making it unable to dynamically import some modules. But if HeroUI could provide a usable update ASAP, developers would really appreciate it.

🚀 New behavior

Toast will work as expect.

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

No

📝 Additional Information

NO

Summary by CodeRabbit

  • Refactor
    • Enhanced the efficiency of animation feature loading for toast notifications, resulting in a more seamless and responsive experience.

Xheldon avatar Apr 14 '25 10:04 Xheldon

⚠️ No Changeset found

Latest commit: a596e9faf788536c138409314b8d710aa291e03c

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

changeset-bot[bot] avatar Apr 14 '25 10:04 changeset-bot[bot]

@Xheldon is attempting to deploy a commit to the HeroUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Apr 14 '25 10:04 vercel[bot]

Walkthrough

The change in this pull request modifies how the ToastProvider component loads animation features. The file now statically imports domMax from framer-motion instead of using dynamic imports. Additionally, the loadFeatures function has been updated so that it immediately returns a static promise with domMax, simplifying the control flow for loading these features.

Changes

File Change Summary
packages/components/toast/src/toast-provider.tsx Updated the import statement to statically import domMax from framer-motion. Modified the loadFeatures function to immediately resolve with domMax, replacing the previous dynamic import mechanism.

Sequence Diagram(s)

sequenceDiagram
    participant TP as ToastProvider
    participant LF as loadFeatures
    participant DM as domMax

    TP->>LF: Call loadFeatures()
    LF->>DM: Return static reference
    DM-->>LF: Immediately resolve with domMax
    LF-->>TP: Return resolved promise with domMax

[!TIP]

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 b865356b6c0b5cc1b10c588c846abf0b21800e1f and a596e9faf788536c138409314b8d710aa291e03c.

📒 Files selected for processing (1)
  • packages/components/toast/src/toast-provider.tsx (1 hunks)
🔇 Additional comments (2)
packages/components/toast/src/toast-provider.tsx (2)

3-3: Good change: Static import of domMax resolves the lazy loading issue.

This change directly imports domMax from 'framer-motion' instead of dynamically importing it. This should fix the issue where Plasmo's Parcel bundler was failing with the error "xxx is not a function" when handling dynamic imports.


8-8: Good solution: Simplified the feature loading mechanism.

The updated loadFeatures function now returns a static Promise that immediately resolves with the already imported domMax. This eliminates the dynamic import that was causing problems with Parcel bundler in the Plasmo framework, while still maintaining compatibility with the LazyMotion component which expects a Promise.

✨ 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.
    • 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

coderabbitai[bot] avatar Apr 14 '25 10:04 coderabbitai[bot]

Open in StackBlitz

@heroui/accordion

npm i https://pkg.pr.new/@heroui/accordion@5191
@heroui/autocomplete

npm i https://pkg.pr.new/@heroui/autocomplete@5191
@heroui/alert

npm i https://pkg.pr.new/@heroui/alert@5191
@heroui/avatar

npm i https://pkg.pr.new/@heroui/avatar@5191
@heroui/badge

npm i https://pkg.pr.new/@heroui/badge@5191
@heroui/breadcrumbs

npm i https://pkg.pr.new/@heroui/breadcrumbs@5191
@heroui/button

npm i https://pkg.pr.new/@heroui/button@5191
@heroui/calendar

npm i https://pkg.pr.new/@heroui/calendar@5191
@heroui/card

npm i https://pkg.pr.new/@heroui/card@5191
@heroui/checkbox

npm i https://pkg.pr.new/@heroui/checkbox@5191
@heroui/chip

npm i https://pkg.pr.new/@heroui/chip@5191
@heroui/code

npm i https://pkg.pr.new/@heroui/code@5191
@heroui/date-input

npm i https://pkg.pr.new/@heroui/date-input@5191
@heroui/date-picker

npm i https://pkg.pr.new/@heroui/date-picker@5191
@heroui/divider

npm i https://pkg.pr.new/@heroui/divider@5191
@heroui/drawer

npm i https://pkg.pr.new/@heroui/drawer@5191
@heroui/dropdown

npm i https://pkg.pr.new/@heroui/dropdown@5191
@heroui/form

npm i https://pkg.pr.new/@heroui/form@5191
@heroui/image

npm i https://pkg.pr.new/@heroui/image@5191
@heroui/input

npm i https://pkg.pr.new/@heroui/input@5191
@heroui/input-otp

npm i https://pkg.pr.new/@heroui/input-otp@5191
@heroui/kbd

npm i https://pkg.pr.new/@heroui/kbd@5191
@heroui/link

npm i https://pkg.pr.new/@heroui/link@5191
@heroui/listbox

npm i https://pkg.pr.new/@heroui/listbox@5191
@heroui/menu

npm i https://pkg.pr.new/@heroui/menu@5191
@heroui/modal

npm i https://pkg.pr.new/@heroui/modal@5191
@heroui/navbar

npm i https://pkg.pr.new/@heroui/navbar@5191
@heroui/number-input

npm i https://pkg.pr.new/@heroui/number-input@5191
@heroui/pagination

npm i https://pkg.pr.new/@heroui/pagination@5191
@heroui/popover

npm i https://pkg.pr.new/@heroui/popover@5191
@heroui/progress

npm i https://pkg.pr.new/@heroui/progress@5191
@heroui/radio

npm i https://pkg.pr.new/@heroui/radio@5191
@heroui/ripple

npm i https://pkg.pr.new/@heroui/ripple@5191
@heroui/scroll-shadow

npm i https://pkg.pr.new/@heroui/scroll-shadow@5191
@heroui/select

npm i https://pkg.pr.new/@heroui/select@5191
@heroui/slider

npm i https://pkg.pr.new/@heroui/slider@5191
@heroui/skeleton

npm i https://pkg.pr.new/@heroui/skeleton@5191
@heroui/snippet

npm i https://pkg.pr.new/@heroui/snippet@5191
@heroui/spacer

npm i https://pkg.pr.new/@heroui/spacer@5191
@heroui/spinner

npm i https://pkg.pr.new/@heroui/spinner@5191
@heroui/switch

npm i https://pkg.pr.new/@heroui/switch@5191
@heroui/table

npm i https://pkg.pr.new/@heroui/table@5191
@heroui/tabs

npm i https://pkg.pr.new/@heroui/tabs@5191
@heroui/toast

npm i https://pkg.pr.new/@heroui/toast@5191
@heroui/tooltip

npm i https://pkg.pr.new/@heroui/tooltip@5191
@heroui/user

npm i https://pkg.pr.new/@heroui/user@5191
@heroui/react

npm i https://pkg.pr.new/@heroui/react@5191
@heroui/system

npm i https://pkg.pr.new/@heroui/system@5191
@heroui/system-rsc

npm i https://pkg.pr.new/@heroui/system-rsc@5191
@heroui/theme

npm i https://pkg.pr.new/@heroui/theme@5191
@heroui/use-aria-accordion

npm i https://pkg.pr.new/@heroui/use-aria-accordion@5191
@heroui/use-aria-accordion-item

npm i https://pkg.pr.new/@heroui/use-aria-accordion-item@5191
@heroui/use-aria-button

npm i https://pkg.pr.new/@heroui/use-aria-button@5191
@heroui/use-aria-link

npm i https://pkg.pr.new/@heroui/use-aria-link@5191
@heroui/use-aria-modal-overlay

npm i https://pkg.pr.new/@heroui/use-aria-modal-overlay@5191
@heroui/use-aria-multiselect

npm i https://pkg.pr.new/@heroui/use-aria-multiselect@5191
@heroui/use-callback-ref

npm i https://pkg.pr.new/@heroui/use-callback-ref@5191
@heroui/use-clipboard

npm i https://pkg.pr.new/@heroui/use-clipboard@5191
@heroui/use-data-scroll-overflow

npm i https://pkg.pr.new/@heroui/use-data-scroll-overflow@5191
@heroui/use-disclosure

npm i https://pkg.pr.new/@heroui/use-disclosure@5191
@heroui/use-draggable

npm i https://pkg.pr.new/@heroui/use-draggable@5191
@heroui/use-image

npm i https://pkg.pr.new/@heroui/use-image@5191
@heroui/use-infinite-scroll

npm i https://pkg.pr.new/@heroui/use-infinite-scroll@5191
@heroui/use-intersection-observer

npm i https://pkg.pr.new/@heroui/use-intersection-observer@5191
@heroui/use-is-mobile

npm i https://pkg.pr.new/@heroui/use-is-mobile@5191
@heroui/use-is-mounted

npm i https://pkg.pr.new/@heroui/use-is-mounted@5191
@heroui/use-measure

npm i https://pkg.pr.new/@heroui/use-measure@5191
@heroui/use-pagination

npm i https://pkg.pr.new/@heroui/use-pagination@5191
@heroui/use-real-shape

npm i https://pkg.pr.new/@heroui/use-real-shape@5191
@heroui/use-ref-state

npm i https://pkg.pr.new/@heroui/use-ref-state@5191
@heroui/use-resize

npm i https://pkg.pr.new/@heroui/use-resize@5191
@heroui/use-safe-layout-effect

npm i https://pkg.pr.new/@heroui/use-safe-layout-effect@5191
@heroui/use-scroll-position

npm i https://pkg.pr.new/@heroui/use-scroll-position@5191
@heroui/use-ssr

npm i https://pkg.pr.new/@heroui/use-ssr@5191
@heroui/use-theme

npm i https://pkg.pr.new/@heroui/use-theme@5191
@heroui/use-update-effect

npm i https://pkg.pr.new/@heroui/use-update-effect@5191
@heroui/aria-utils

npm i https://pkg.pr.new/@heroui/aria-utils@5191
@heroui/dom-animation

npm i https://pkg.pr.new/@heroui/dom-animation@5191
@heroui/react-rsc-utils

npm i https://pkg.pr.new/@heroui/react-rsc-utils@5191
@heroui/framer-utils

npm i https://pkg.pr.new/@heroui/framer-utils@5191
@heroui/react-utils

npm i https://pkg.pr.new/@heroui/react-utils@5191
@heroui/shared-icons

npm i https://pkg.pr.new/@heroui/shared-icons@5191
@heroui/shared-utils

npm i https://pkg.pr.new/@heroui/shared-utils@5191
@heroui/stories-utils

npm i https://pkg.pr.new/@heroui/stories-utils@5191
@heroui/test-utils

npm i https://pkg.pr.new/@heroui/test-utils@5191

commit: a596e9f

pkg-pr-new[bot] avatar May 03 '25 06:05 pkg-pr-new[bot]