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

Link component is not checking if href is undefined #1834

Open
deansimcox opened this issue Jul 1, 2024 · 0 comments
Open

Link component is not checking if href is undefined #1834

deansimcox opened this issue Jul 1, 2024 · 0 comments
Labels

Comments

@deansimcox
Copy link

deansimcox commented Jul 1, 2024

Describe the Bug

If the field passed to the Link component has an undefined href, it will render undefined as a string in the dom.

To Reproduce

import {Link} from '@sitecore-jss/sitecore-jss-nextjs';

const field = {value: {href: undefined, text: 'This is a link with a href that is undefined'}};

<Link field={field} />

This will render a link like this:

<a href="undefined">This is a link with a href that is undefined</a>

Expected Behavior

I would expect the undefined href to be filtered out, leaving behind an anchor that with no href attribute.

E.g.

<a>This is a link with a href that is undefined</a>

Possible Fix

On line 104, we should be checking for undefined
https://github.com/Sitecore/jss/blob/dev/packages/sitecore-jss-react/src/components/Link.tsx#L104

Provide environment information

  • Sitecore Version: XP 10.3 (at least I think from memory)
  • JSS Version: "@sitecore-jss/sitecore-jss-nextjs": "^20.3.3",
  • Browser Name and version: Arc 1.49.0
  • Operating System and version (desktop or mobile): macOS 14.5
  • Link to your project (if available):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant