Skip to content

Space in the beginning of classname crashes Nextjs app #456

Closed
@callmearta

Description

Describe the bug

cn(" text-white") causes nextjs page crash in browser giving out of memory error. cn("text-white") fixes the issue. that space took me 6 hours to find out about. Worked fine before new release. cn is also a function that uses clsx and tailwind-merge to combine classnames.

To Reproduce

  1. create a nextjs app
  2. create the cn function as below:
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
 
export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}
  1. use cn(" text-white") classname as an example.
  2. the page crashes in browser while it is on a not much powerful server. I still don't understand why it is related to the server cpu causing client browser to crash.

Expected behavior

No crash in browser.

Environment

nextjs v14.2.5
clsx v2.0.0

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcontext-v2Related to tailwind-merge v2

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions