question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Link with react-material-ui - warning Unknown key passed via urlObject into url.format:

See original GitHub issue

Bug report

This may be related to this issue.

I am getting the warning below on all my Link instances:

     Unknown key passed via urlObject into url.format: searchParams 

Describe the bug

I’ve tried 2 alternatives to using Link: 1 - using the recommended implementation from react-material-ui

2 - using the solution proposed in this article

To Reproduce

For alternative 1 I have /src/components/link like so:

 import PropTypes from 'prop-types';
 import clsx from 'clsx';
 import { useRouter } from 'next/router';
 import NextLink from 'next/link';
 import MuiLink from '@material-ui/core/Link';

const NextComposed = React.forwardRef(function NextComposed(props, ref) {
     const { as, href, ...other } = props;

return (
    <NextLink href={href} as={as}>
        <a ref={ref} {...other} />
    </NextLink>
 );
 });

NextComposed.propTypes = {
    as: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
    href: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
   prefetch: PropTypes.bool,
};

function Link(props) {
   const {
    href,
    activeClassName = 'active',
    className: classNameProps,
    innerRef,
    naked,
    ...other
} = props;

const router = useRouter();
const pathname = typeof href === 'string' ? href : href.pathname;
const className = clsx(classNameProps, {
    [activeClassName]: router.pathname === pathname && activeClassName,
});

if (naked) {
    return (
        <NextComposed className={className} ref={innerRef} href={href} {...other} />
    );
}

return (
    <MuiLink
        component={NextComposed}
        className={className}
        ref={innerRef}
        href={href}
        {...other}
    />
);
}

Link.propTypes = {
 ....
};

 export default React.forwardRef((props, ref) => <Link {...props} innerRef={ref} />);

Then on the component:

  import Link from './link';
 import { EditOutlined } from '@material-ui/icons';
 .....

 <Link
     href="/admin/categories/edit/[adId]"
     as={`/admin/categories/edit/${
              tableMeta.rowData[0].match(/\d+/)[0]
            }`}
      >
          <EditOutlined id={tableMeta.rowData[0]} />
  </Link>

For alternative 2

   import Link from 'next/link';
   import { EditOutlined } from '@material-ui/icons';
   .....
   <Link
       href="/admin/categories/edit/[adId]"
      as={`/admin/categories/edit/${
            tableMeta.rowData[0].match(/\d+/)[0]
            }`}
       passHref
   >
      <Button component="a">
           <EditOutlined id={tableMeta.rowData[0]} />
       </Button>
  </Link>

Expected behavior

Expecting to work without the warning. In fact it DOES work. Just trying to get rid of the warning

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: MacOS 10.15.6
  • Browser (if applies) Chrome, Firefox
  • Version of Next.js: 9.5.3
  • Version of Node.js: 12.16.0

Additional context

The code is available in this repo

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
BernardAcommented, Sep 24, 2020

Thanks @gabrielalmeida I will wait till 9.5.4 is released to upgrade and test. Leaving it open for now.

2reactions
gabrielalmeidacommented, Sep 24, 2020

Duplicate of https://github.com/vercel/next.js/issues/16794, it’s fixed on next@9.5.4-canary.2.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NextJs router push unknown key passed via urlObject
The function works, I properly add queries, but I would like to understand why all these warnings occur. javascript · next.js · next-router....
Read more >
How do I add a query param to Router.push in NextJS?-Reactjs
d.ts to see how push is defined). That's why you're getting the error Unknown key passed via urlObject into url.format: as ...
Read more >
How to Link in React and the Material UI Framework
Clicking the link will update your browser's URL and history. By themselves, these links won't cause anything to change in your application.
Read more >
interact-next - npm Package Health Analysis - Snyk
Snyk scans all the packages in your projects for vulnerabilities and ... an URL object and it will automatically format it to create...
Read more >
HTML5 for .NET Developers - doc-developpement-durable.org
presentation, HTML5 has something for everyone in the web design and ... WARNING <link> tags can reference stylesheets from other sites, but most....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found