question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Flow doesn't work in Shadow DOM

See original GitHub issue

Describe the Bug

I need to use React Flow inside Shadow DOM, but I ran into several errors:

  1. Uncaught TypeError: Failed to execute ‘getComputedStyle’ on ‘Window’: parameter 1 is not of type ‘Element’.

image

I made a small local fix in node_modules to check new behavior: replaced this document.querySelector('.react-flow__viewport') whith this document.querySelector('#shadow').shadowRoot.querySelector('.react-flow__viewport') - '#shadow' is my element with Shadow DOM.

And I got the following bug

  1. There are broken view for nodes and edges

image

Your Example Website or App

https://github.com/KislyakovDS/react-flow-with-shadow-dom

Steps to Reproduce the Bug or Issue

  1. Go to https://react-flow-with-shadow-dom.vercel.app/
  2. Open browser console to see error

Expected behavior

As a user, I expected behavior from this example https://reactflow.dev/docs/examples/overview/

Screenshots or Videos

No response

Platform

  • OS: [Windows]
  • Browser: [Chrome]
  • Version: [103.0.5060.114]

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
KislyakovDScommented, Jul 25, 2022

Thanks for quick fix))

1reaction
moklickcommented, Jul 25, 2022

Alright. Thanks again! Fixed in v10.3.12

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scroll doesn't work in Shadow DOM #4512 - GitHub
I have a project that is entirely written in Shadow DOM. To my surprise, react-select doesn't work properly in shadow root. Styles don't...
Read more >
Click event not firing when React Component in a Shadow DOM
As it turns out the Shadow DOM retargets click events and encapsulates the events in the shadow. React does not like this because...
Read more >
Troubleshooting Guide - React Flow
Doesn't work : import ReactFlow from 'reactflow'; import 'reactflow/dist/style.css'; import MyCustomNode from './MyCustomNode'; const nodes = [
Read more >
Virtual DOM and Internals - React
The Shadow DOM is a browser technology designed primarily for scoping variables and CSS in web components. The virtual DOM is a concept...
Read more >
Shadow DOM - Material UI - MUI
The shadow DOM lets you encapsulate parts of an app to keep them separate from global styles that target the regular DOM tree....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found