diff --git a/packages/core/core.ts b/packages/core/core.ts index 12e69dc..761f94b 100644 --- a/packages/core/core.ts +++ b/packages/core/core.ts @@ -207,10 +207,10 @@ class Marquee { this.resizeObserver?.disconnect() this.resizeObserver = undefined - // // Remove the cloned child if it exists - // if (this.clonedChild && this.clonedChild.parentNode === this.root) { - // this.root.removeChild(this.clonedChild) - // } + // Remove the cloned child if it exists + if (this.clonedChild && this.clonedChild.parentNode === this.root) { + this.root.removeChild(this.clonedChild) + } this.clonedChild = undefined this.originalChild = undefined } diff --git a/packages/react/index.tsx b/packages/react/index.tsx index 32f1b73..2bf5ed3 100644 --- a/packages/react/index.tsx +++ b/packages/react/index.tsx @@ -33,17 +33,15 @@ const useMarquee = ({ } marquee.initialize(children[0] as HTMLElement) + + return () => marquee.destroy() }, []) useEffect(() => { if (!marquee) return if (play) marquee.play() else marquee.pause() - }, [play]) - - useEffect(() => { - return () => marquee?.destroy() - }, []) + }, [play, marquee]) return [rootRef, marquee] as const } diff --git a/templates/basic/app/components/header.tsx b/templates/basic/app/components/header.tsx index e95fc93..04eef08 100644 --- a/templates/basic/app/components/header.tsx +++ b/templates/basic/app/components/header.tsx @@ -1,5 +1,6 @@ import { Link } from 'react-router' import Logo from './logo' +import { isDevelopment } from '@/lib/constants' export const links = [ { @@ -14,25 +15,41 @@ export const links = [ label: 'discord', to: 'https://discord.gg/UJtQFJ3X3z', }, + isDevelopment + ? { + label: 'Test Page', + to: '/test', + } + : undefined, ] +const checkIsAbsoluteUrl = (url: string) => { + return url.startsWith('http') +} + export default function Header() { return (
- + + +
- {links.map((link) => ( - - {link.label} - - ))} + {links.map((link) => { + if (!link) return null + const isAbsoluteUrl = checkIsAbsoluteUrl(link.to) + return ( + + {link.label} + + ) + })}
) diff --git a/templates/basic/app/lib/constants.ts b/templates/basic/app/lib/constants.ts index b6032c7..7614dbf 100644 --- a/templates/basic/app/lib/constants.ts +++ b/templates/basic/app/lib/constants.ts @@ -4,7 +4,7 @@ export const isServer = typeof window === 'undefined' export const isClient = typeof window !== 'undefined' -export const isDevelopment = import.meta.env.NODE_ENV === 'development' +export const isDevelopment = import.meta.env.MODE === 'development' const base_url = import.meta.env.VITE_VERCEL_PROJECT_PRODUCTION_URL || import.meta.env.VITE_VERCEL_URL || import.meta.env.VITE_SITE_URL diff --git a/templates/basic/app/routes.ts b/templates/basic/app/routes.ts index 13ed509..340dfc5 100644 --- a/templates/basic/app/routes.ts +++ b/templates/basic/app/routes.ts @@ -1,3 +1,3 @@ -import { type RouteConfig, index } from '@react-router/dev/routes' +import { type RouteConfig, index, route } from '@react-router/dev/routes' -export default [index('routes/home/index.tsx')] satisfies RouteConfig +export default [index('routes/home/index.tsx'), route('/test', 'routes/test/index.tsx')] satisfies RouteConfig diff --git a/templates/basic/app/routes/test/index.tsx b/templates/basic/app/routes/test/index.tsx new file mode 100644 index 0000000..c5fd7d1 --- /dev/null +++ b/templates/basic/app/routes/test/index.tsx @@ -0,0 +1,13 @@ +import { Marquee } from '@joycostudio/marquee/react' + +export default function Test() { + return ( +
+ +

+ This page is to test how the marquee behaves when the component is unmounted. +

+
+
+ ) +}