tldraw/packages
alex 390c45c7eb
fix vite HMR issue (#2279)
This is an attempt at #1989. The big issue there is when `shapeUtils`
change when you're relying on tldraw to provide you with the store
instead of providing your own. Our `useTLStore` component had a bug
where it would rely on effects & a ref to detect when its options had
changed whilst still scheduling updates. Fresh opts would come in, but
they'd be different from the ones in the ref, so we'd schedule an
update, so the opts would come in again, but they'd still be different
as we hadn't run effects yet, and we'd schedule an update again (and so
on).

This diff fixes that by storing the previous opts in state instead of a
ref, so they're updating in lockstep with the store itself. this
prevents the update loop.

There are still situations where we can get into loops if the developer
is passing in custom tools, shapeUtils, or components but not memoising
them or defining them outside of react. As a DX improvement, we do some
auto-memoisation of these values using shallow equality to help with
this issue.

### Change Type

- [x] `patch` — Bug fix


### Test Plan

- [x] Unit Tests

### Release Notes

- Fixes a bug that could cause crashes due to a re-render loop with HMR
#1989
2023-12-01 16:48:30 +00:00
..
assets Update CHANGELOG.md [skip ci] 2023-11-10 10:49:37 +00:00
editor fix vite HMR issue (#2279) 2023-12-01 16:48:30 +00:00
state Replace getters in examples (#2261) 2023-11-28 17:33:10 +00:00
store No impure getters pt10 (#2235) 2023-11-16 12:07:33 +00:00
tldraw fix vite HMR issue (#2279) 2023-12-01 16:48:30 +00:00
tlschema Add prettier caching (#2212) 2023-11-14 09:06:52 +00:00
utils fix vite HMR issue (#2279) 2023-12-01 16:48:30 +00:00
validate Update CHANGELOG.md [skip ci] 2023-11-10 10:49:37 +00:00