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

Adding hyperlink to page causes "Failed to construct 'CustomElement': The result must not have attributes. #235

Open
joe-alaska opened this issue Nov 7, 2024 · 1 comment · May be fixed by #238
Assignees
Labels

Comments

@joe-alaska
Copy link

Please verify the version of auro-hyperlink you have installed

4.1.1

Please describe the bug

  1. Create a hyperlink element in React that imports auro-hyperlink.
  2. Place that anywhere in the app.

image

Reproducing the error

None

Expected behavior

Hyperlink should appear on page with no runtime errors.

What browsers are you seeing the problem on?

No response

Additional context

Code for my Hyperlink element:

import` '@aurodesignsystem/auro-hyperlink';
import React, { useEffect, useRef } from 'react';

const Hyperlink = ({ onClick, href, isButton, children }) => {
  const ref = useRef(null);
  useEffect(() => {
    const hyperlinkCurrentRef = ref.current;

    hyperlinkCurrentRef.addEventListener('click', (event) => {
      onClick(event);
    });

    return () => {
      hyperlinkCurrentRef.removeEventListener('click', (event) => {
        onClick(event);
      });
    };
  }, [ref, onClick]);

  return (
    // <auro-hyperlink ref={ref} href={href} role={isButton ? "button" : null}>
    <auro-hyperlink>
      {children}
    </auro-hyperlink>
  );
}

export default Hyperlink;

Using that hyperlink:

        <Hyperlink onClick={() => alert('have a nice day')} href="/mileageplan/retrocredit/v1" isButton={true}>
          this form.
        </Hyperlink>

Exit criteria

No response

@joe-alaska joe-alaska added auro-hyperlink not-reviewed Issue has not been reviewed by Auro team members Type: Bug Bug or Bug fixes labels Nov 7, 2024
@jason-capsule42
Copy link
Member

https://stackoverflow.com/questions/43836886/failed-to-construct-customelement-error-when-javascript-file-is-placed-in-head

The problem here is almost certainly that you are dynamically creating the attribute and applying attributes on the element BEFORE you have inserted it into the DOM. Create the base element, append it into the DOM, and then add your attributes after.

@rmenner rmenner removed the not-reviewed Issue has not been reviewed by Auro team members label Nov 20, 2024
@rmenner rmenner linked a pull request Nov 20, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants