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 · 6 comments
Open

Link component is not checking if href is undefined #1834

deansimcox opened this issue Jul 1, 2024 · 6 comments
Labels
backlog Issue/PR/discussion is reviewed and added to backlog for the further work 🐞 bug

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 102, we should be checking for undefined
https://github.com/Sitecore/jss/blob/v20.3.3/packages/sitecore-jss-react/src/components/Link.tsx#L102

E.g.

href: link.href ? `${link.href}${querystring}${anchor}` : undefined,

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):
@addy-pathania
Copy link
Contributor

@deansimcox, thanks for reporting this bug. I will add it to our backlog and prioritize it accordingly. However, if you feel this is a blocker for you, feel free to contribute by issuing a PR to our repository.

@addy-pathania addy-pathania added the backlog Issue/PR/discussion is reviewed and added to backlog for the further work label Jul 16, 2024
@deansimcox
Copy link
Author

All good, appreciate the update @sc-addypathania

@pzi
Copy link
Contributor

pzi commented Jul 18, 2024

@deansimcox, thanks for reporting this bug. I will add it to our backlog and prioritize it accordingly. However, if you feel this is a blocker for you, feel free to contribute by issuing a PR to our repository.

@sc-addypathania If we PR a fix, would you consider patching it into [email protected]? or v21.x?

@addy-pathania
Copy link
Contributor

@pzi yes you can issue a fix on the dev branch for now and we will try to prioritize the patch releases soon.

@sumon1991
Copy link

@sc-addypathania I created a PR of it please review it.

@yavorsk
Copy link
Contributor

yavorsk commented Jul 29, 2024

hey @sumon1991 thanks for your contribution :) I've created an item in our backlog to review and merge your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Issue/PR/discussion is reviewed and added to backlog for the further work 🐞 bug
Projects
None yet
Development

No branches or pull requests

5 participants