iTwin / iTwinUI

A design system for building beautiful and well-working web interfaces.
https://itwin.github.io/iTwinUI/
MIT License
92 stars 35 forks source link

fix clearing of existing `shadowRoot` in strict mode #1969

Closed mayank99 closed 1 month ago

mayank99 commented 1 month ago

Changes

This is left over from #1962

Basically, in strict mode, react executes all effects a bunch of times, so the shadow-root was getting cleared right after its content was mounted. The only way around this is to avoid clearing a shadow-root if the shadowRoot state variable has already been set.

Testing

I used this code in vite playground App.tsx to test manually in dev:

export { Full2 as default } from '../../../apps/react-workshop/src/Table.stories.tsx';
Before After
image image

It isn't possible to write a reliable test for this, since it's a dev + strict mode thing (not reproducible in prod).

However, I've added strict mode to ladle to help catch such issues in our stories during development.

Docs

N/A