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

Fix: Primereact uses document.getElementById(undefined) for appending… #6081

Closed
wants to merge 1 commit into from

Conversation

kl-nevermore
Copy link
Contributor

Fix #6079

Copy link

vercel bot commented Mar 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
primereact ⬜️ Ignored (Inspect) Visit Preview Mar 4, 2024 8:18am
primereact-v9 ⬜️ Ignored (Inspect) Visit Preview Mar 4, 2024 8:18am

@@ -21,7 +21,7 @@ export const useStyle = (css, options = {}) => {

const styleContainer = context?.styleContainer || document.head;

styleRef.current = styleContainer.querySelector(`style[data-primereact-style-id="${name}"]`) || document.getElementById(id) || document.createElement('style');
styleRef.current = styleContainer.querySelector(`style[data-primereact-style-id="${name}"]`) || document.querySelector(`#${id}`) || document.createElement('style');
Copy link

@yikstinis yikstinis Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change won't fix the issue. New selector document.querySelector('#undefined') will select the same element with id="undefined".. :(

Copy link

@yikstinis yikstinis Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I belive, you have to do something like that:

const getCurrentStyleRef = () => {
  const existingStyleContainerChild = styleContainer.querySelector(
    `style[data-primereact-style-id="${name}"]`,
  );
  if (existingStyleContainerChild) {
    return existingStyleContainerChild;
  }
  // First, check that id is defined!
  if (id !== undefined) {
    // And select element by defined id on the page after:
    const existingElementWithId = document.getElementById(id);
    if (existingElementWithId) {
      return existingElementWithId;
    }
  }
  return document.createElement('style');
};
styleRef.current = getCurrentStyleRef();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I made a mistake, sorry. I forgot add during the testing with #

@kl-nevermore kl-nevermore deleted the 6079 branch March 4, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Primereact uses document.getElementById(undefined) for appending component styles
2 participants