nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - Button Not Working With Next.js Link Component on Andorid(brave browser)

Open jstbyte opened this issue 2 years ago • 4 comments

Describe the bug

TypeError: Cannot read property 'nodeName' of undefined.

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

<Link href='/test'>
      <Button
        as='a'
        auto
        size='sm'
        shadow
        css={{ marginTop: '$12' }}
        onClick={() => ''}
      >
        Test Page
      </Button>
    </Link>

Expected behavior

Expected behavior is navigate to spacified page but i'm getting error: TypeError: Cannot read property 'nodeName' of undefined.

Screenshots or Videos

No response

Operating System Version

windows 10

Browser

Chrome

jstbyte avatar May 26 '22 04:05 jstbyte

Hey @jstbyte could you please share a Codesandbox or something similar?, I couldn't replicate it

https://stackblitz.com/edit/nextjs-hln4yw?file=pages/index.js

jrgarciadev avatar Jun 06 '22 14:06 jrgarciadev

Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention? > This issue will be closed in 10 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 05 '22 16:08 stale[bot]

@jrgarciadev I also have the same problem with. If I wrap Button with Link from Next I get the same error. Link and Button works on their own.

smartercow avatar Aug 29 '22 18:08 smartercow

Hey @smartercow, @jstbyte could you try this way?:

import { Button } from "@nextui-org/react";
import Link from "next/link";

///....
<Button
  auto
  shadow
  as={Link}
  size='sm'
  href="/test"
  css={{ marginTop: '$12' }}
  onPress={() => console.log('pressed')}
>
 <a>
     Test Page
  </a>
</Button>

jrgarciadev avatar Sep 18 '22 18:09 jrgarciadev

The above example results in Error: Multiple children were passed to <Link> with `href` of `/register` but only one child is supported. Facing the same issue for all links I want to display as buttons.

creazy231 avatar Sep 23 '22 19:09 creazy231

Hi @jrgarciadev,

I too am getting the same issues as @jstbyte and @creazy231.

I've tried the following:

import Link from 'next/link';
import { Button } from '@nextui-org/react';

<Link href='/test'>
<Button as='a'>
    Test Page
</Button>
</Link>

See the following error: TypeError: Cannot read properties of undefined (reading 'nodeName')

and

import Link from 'next/link';
import { Button } from '@nextui-org/react';

<Button
  as={Link}
  href="/test"
>
 <a>
     Test Page
  </a>
</Button>

See the following error: Error: Multiple children were passed to <Link> with href of some-url but only one child is supported

Lastly I tried:

import Link from 'next/link';
import { Button } from '@nextui-org/react';

<Link href='/test' passHref>
<Button as='a'>
    Test Page
</Button>
</Link>

Getting the same results as the first example.

My package.json contains the following: "@nextui-org/react": "*", "next": "12.3.1", "react": "18.2.0", "react-dom": "18.2.0"

BenSwitzerHavas avatar Sep 25 '22 18:09 BenSwitzerHavas

import { Button, Link } from "@nextui-org/react";
import { default as NextLink } from "next/link";

<NextLink href={href} passHref>
      <Button
        as={Link}
      >
        Sign in
      </Button>
    </NextLink>

results in: TypeError: Cannot read properties of undefined (reading 'nodeName') briefly flashing before navigating. I think the flash only occurs on first navigation from a new page.

"@nextui-org/react": "*", ("1.0.0-beta.10",)
"next": "12.2.5",
"react": "18.2.0",
"react-dom": "18.2.0",

leogilmour avatar Oct 01 '22 16:10 leogilmour

The above isn't just on Android, it's on Windows Chrome too.

This is a common usecase (button that opens a link).

rolznz avatar Oct 19 '22 07:10 rolznz

It looks like as a temporary fix you can do: (note e?. required for clicking the button again after navigating back, it seems like the event is not always available)

import { Button, Link } from "@nextui-org/react";
import { default as NextLink } from "next/link";
<NextLink href={Routes.withdraw} passHref>
  <Button as="a" onClick={(e) => { e?.preventDefault();}}>
    Test
  </Button>
</NextLink>

rolznz avatar Oct 19 '22 08:10 rolznz

Issue is stale but for anyone that couldn't apply the workaround of @rolznz, here is mine.

If the Link is internal we can just attach a callback function on the onPress event with the router from next/router like this

import { useRouter } from 'next/router'

const router = useRouter()

<Button onPress={() => router.push('/some-route')}>
          Dummy button
</Button>

Hope this helps !

gBoole01 avatar Jan 31 '23 16:01 gBoole01

Hey guys sorry for the delay please upgrade to V2.

jrgarciadev avatar Aug 02 '23 13:08 jrgarciadev