Skip to content

[Bug]: SidebarMenuSkeleton causes hydration error in Nuxt 4 #1633

@rem-aster

Description

@rem-aster

Reproduction

not needed, i know the cause and have a potential fix

Describe the bug

SidebarMenuSkeleton uses Math.random() to make random size.

const width = computed(() => {
	return `${Math.floor(Math.random() * 40) + 50}%`
})

This causes hydration error in Nuxt 4 - different numbers are obtained on the client and server.

Here is a possible fix:

const uid = useId()
const width = useState(`skeleton-width-${uid}`, () => `${Math.floor(Math.random() * 40) + 50}%`)

System Info

Not needed

Contributes

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions