Shadcn-ui elements do not animate when using @tanstack/router v1 #939
Send to my agentDescribe 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#
Clone the @tanstack/router basic example. I did this by opening the example with Stackblitz and downloading the code.
As written in the README.md run:
npm install npm start
Add an empty index.css file.
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
- Add the sheet component with
npx shadcn-ui@latest add sheet
- 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.
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:
- You need to remove the tailwindcss script import in the
index.htmlfile, so there isn't any mismatch been the tailwind npm package and the script being loaded from the cdn on page load. - You need import the
index.csslocated in the/srcdirectory into yourmain.tsxfile, 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.
- You need to remove the tailwindcss script import in the
tannerlinsley closed this
@SeanCassiere many thanks, brilliant response all resolved.
Yes I imported
index.cssfrom/srcwhere myimport @tailwindcsslies intomain.tsxand that did the trick.
Sign in to join this conversation.
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.