Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

router.push event is throwing TypeError: Cannot destructure property 'auth' of 'urlObj' as it is undefined. #65357

Closed
vizsumit opened this issue May 4, 2024 · 2 comments
Labels
bug Issue was opened via the bug report template. Pages Router Related to Pages Router.

Comments

@vizsumit
Copy link

vizsumit commented May 4, 2024

Link to the code that reproduces this issue

https://github.com/vizsumit/next-js-bug

To Reproduce

  1. install npm packages
  2. start the app
  3. visit hello link from header
  4. it will throw "TypeError: Cannot destructure property 'auth' of 'urlObj' as it is undefined."

Current vs. Expected behavior

after clicking link relevant page should open

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 16305
  Available CPU cores: 8
Binaries:
  Node: 20.11.1
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.2.3
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Pages Router

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

I am using chip component from nextui lib, which takes router.push as obj to navigate.
screenshot-localhost_3000-2024 05 04-22_43_28

@vizsumit vizsumit added the bug Issue was opened via the bug report template. label May 4, 2024
@github-actions github-actions bot added the Pages Router Related to Pages Router. label May 4, 2024
@YuzuZensai
Copy link

YuzuZensai commented May 5, 2024

I encountered a similar problem in my project as well. After some messing around, it appears that the issue might be related to NextUI, Because I do have another component library in the project too and that worked fine.

I found a workaround for the issue by patching all instances of router.open in the NextUI. Sending additional href in the parameter to the function call, since I noticed the router interface contains

interface Router {
    isNative: boolean;
    open: (target: Element, modifiers: Modifiers, href: Href, routerOptions: RouterOptions | undefined) => void;
    useHref: (href: Href) => string;
}

It seems to resolve the issue for me

I use pnpm to patch all of these occurrence
@nextui-org/use-aria-link

- router.open(e.currentTarget, e);
+ router.open(e.currentTarget, e, e.currentTarget.href);

@nextui-org/use-aria-menu

-      router.open(e.target, e);
+      router.open(e.target, e, e.target.href);

@nextui-org/pagination

-          router.open(e.currentTarget, e);
+          router.open(e.currentTarget, e, e.currentTarget.href);

Then, finally, don't forget to clear your webpack cache or delete your .next folder

This workaround may not be the optimal solution and there's a possibility it could introduce other issues, I haven't looked deep into it, because I need to get my project working in time 😅

EDIT: Seem like there is a PR to fix this now on NextUI repo: nextui-org/nextui#2943

@vizsumit vizsumit closed this as completed May 6, 2024
@vizsumit
Copy link
Author

vizsumit commented May 6, 2024

@YuzuZensai Thanks for helping me out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Pages Router Related to Pages Router.
Projects
None yet
Development

No branches or pull requests

2 participants