Skip to content
Source
Sign inSign up
TanStack/router

Shadcn-ui elements do not animate when using @tanstack/router v1 #939

Send to my agent
Closedguysolan(GitHub profile, opens in a new tab) opened this issue 4 comments

Describe the bug

When using the popular shadcn-ui library, animations stop working when using @tanstack/router.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-yvpcnc?file=src%2Fmain.tsx

Steps to Reproduce the Bug or Issue

  1. Clone the @tanstack/router basic example. I did this by opening the example with Stackblitz and downloading the code.

  2. As written in the README.md run:

npm install npm start

  1. Add an empty index.css file.

  2. Follow steps 1 to 6 of the shadcn-ui vite installation guide. The settings I used were:

Would you like to use TypeScript (recommended)? yes
Which style would you like to use? › Default
Which color would you like to use as base color? › Slate
Where is your global CSS file? › › src/index.css
Do you want to use CSS variables for colors? › no
Where is your tailwind.config.js located? › tailwind.config.js
Configure the import alias for components: › @/components
Configure the import alias for utils: › @/lib/utils
Are you using React Server Components? › no
  1. Add the sheet component with

npx shadcn-ui@latest add sheet

  1. Edit the main.tsx file to import and use the sheet component
import {
  Sheet,
  SheetContent,
  SheetDescription,
  SheetHeader,
  SheetTitle,
  SheetTrigger,
} from "@/components/ui/sheet"


function RootComponent() {
  return (
    <div className="bg-gradient-to-r from-green-700 to-lime-600 text-white">
      <Sheet>
        <SheetTrigger>Open</SheetTrigger>
        <SheetContent>
          <SheetHeader>
            <SheetTitle>Are you sure absolutely sure?</SheetTitle>
            <SheetDescription>
              This action cannot be undone. This will permanently delete your account
              and remove your data from our servers.
            </SheetDescription>
          </SheetHeader>
        </SheetContent>
      </Sheet>
      <div className="p-2 flex gap-2 text-lg bg-black/40 shadow-xl">
        <Link
          to="/"
          activeProps={{
            className: 'font-bold',
          }}
          activeOptions={{ exact: true }}
        >
          Home
        </Link>{' '}
        <Link
          to={'/posts'}
          activeProps={{
            className: 'font-bold',
          }}
        >
          Posts
        </Link>
      </div>
      <Outlet />
      <TanStackRouterDevtools position="bottom-right" />
    </div>
  )
}

Expected behavior

Typically the sheet element animates in as it does on the demo.

When reverting to react-router all issues were resolved.

TailwindCss animations still work for example if you add animate-pulse to the parent div of rootComponent the elements pulse as expected.

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Chrome,
  • Version: 120.0.6099.199 (Official Build) (64-bit)

Additional context

Otherwise, loving the router.

  1. I looked around that stackblitz, really weird. I have a private repo where I use shadcn and vite tanstack router, and the animations work there for me (tested with the sheet), tried searching for reasons why it wouldnt work there but work on my repo, couldnt find anything.

  2. SeanCassierecommented

    I played around with the reproduction above and found that it wasn't properly set up to work with tailwindcss.

    When using any of the react examples from Tanstack Router, they are set up to use the Tailwindcss Play CDN for styling. This is meant for quick iteration with tailwindcss without having to perform the full set-up.

    As such, the migration steps for moving one of the examples to work with your local tailwindcss setup would require the following:

    1. You need to remove the tailwindcss script import in the index.html file, so there isn't any mismatch been the tailwind npm package and the script being loaded from the cdn on page load.
    2. You need import the index.css located in the /src directory into your main.tsx file, so your local tailwindcss styles will be applied in to the final generated file.

    See the working example here: https://stackblitz.com/edit/tanstack-router-a8ywr5?file=src%2Fmain.tsx

    Please confirm and close the issue.

  3. tannerlinsley closed this

  4. @SeanCassiere many thanks, brilliant response all resolved.

  5. Yes I imported index.css from /src where my import @tailwindcss lies into main.tsx and that did the trick.

Sign in to join this conversation.