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

[Bug]: FileUploaderItem not working in ShadowDOM #16844

Closed
2 tasks done
wfdcfs opened this issue Jun 21, 2024 · 2 comments · Fixed by #17104
Closed
2 tasks done

[Bug]: FileUploaderItem not working in ShadowDOM #16844

wfdcfs opened this issue Jun 21, 2024 · 2 comments · Fixed by #17104

Comments

@wfdcfs
Copy link

wfdcfs commented Jun 21, 2024

Package

@carbon/react

Browser

Chrome, Safari, Firefox

Package version

1.60.1

React version

18.3.1

Description

We use the shadowDOM.
When I update beyond 1.39.0 (1.39.0 works for us), I have an issue with the FileUploaderItem component - this component works fine if not using shadowDOM.
The issue is with line https://github.com/carbon-design-system/carbon/blob/main/packages/react/src/components/FileUploader/FileUploaderItem.tsx#L111

const element = document.querySelector(`[title="${name}"]`);

In the shadowDOM, element returns as null and later the Carbon component tries to do setIsEllipsisApplied(element.offsetWidth < element.scrollWidth); - this is where it bombs out with the error:

TypeError: Cannot read properties of null (reading 'offsetWidth')
    at isEllipsisActive (FileUploaderItem.js:72:34)
    at eval (FileUploaderItem.js:77:5)
    at commitHookEffectListMount (react-dom.development.js:23184:26)
    at commitLayoutEffectOnFiber (react-dom.development.js:23302:17)
    at commitLayoutMountEffects_complete (react-dom.development.js:24722:9)
    at commitLayoutEffects_begin (react-dom.development.js:24708:7)
    at commitLayoutEffects_begin (react-dom.development.js:24690:11)
    at commitLayoutEffects (react-dom.development.js:24646:3)
    at commitRootImpl (react-dom.development.js:26857:5)
    at commitRoot (react-dom.development.js:26716:5)

Reproduction/example

https://stackblitz.com/edit/react-ts-mss5gp?file=index.tsx

Steps to reproduce

Just open the stackblitz link and you will see the error message.

Suggested Severity

Severity 2 = User cannot complete task, and/or no workaround within the user experience of a given component.

Application/PAL

No response

Code of Conduct

@s100
Copy link
Contributor

s100 commented Jul 10, 2024

Seeing a similar issue while testing using Mocha and JSDOM. You should be using refs for this purpose, not document.querySelector.

@s100
Copy link
Contributor

s100 commented Jul 10, 2024

We have an extremely hacky workaround:

const originalQuerySelector = document.querySelector
document.querySelector = function (query) {
  if (/^\[title=".*"]$/.test(query)) {
    return {
      offsetWidth: 0,
      scrollWidth: 0
    }
  }
  return originalQuerySelector.apply(this, arguments)
}

@guidari guidari moved this to ⏱ Backlog in Design System Jul 17, 2024
@guidari guidari moved this from ⏱ Backlog to 🏗 In Progress in Design System Aug 1, 2024
@guidari guidari moved this from 🏗 In Progress to 🚦 In Review in Design System Aug 5, 2024
@github-project-automation github-project-automation bot moved this from 🚦 In Review to ✅ Done in Design System Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants