tldraw/packages/utils
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
..
api Publish api.json (#2034) 2023-10-08 15:00:58 +00:00
src fix vite HMR issue (#2279) 2023-12-01 16:48:30 +00:00
api-extractor.json transfer-out: transfer out 2023-04-25 12:01:25 +01:00
api-report.md fix vite HMR issue (#2279) 2023-12-01 16:48:30 +00:00
CHANGELOG.md Update CHANGELOG.md [skip ci] 2023-11-10 10:49:37 +00:00
LICENSE readmes 2023-05-04 13:47:56 +01:00
package.json Update CHANGELOG.md [skip ci] 2023-11-10 10:49:37 +00:00
README.md readmes 2023-05-04 13:47:56 +01:00
tsconfig.json transfer-out: transfer out 2023-04-25 12:01:25 +01:00

@tldraw/utils

License

The source code in this repository (as well as our 2.0+ distributions and releases) are currently licensed under Apache-2.0. These licenses are subject to change in our upcoming 2.0 release. If you are planning to use tldraw in a commercial product, please reach out at hello@tldraw.com.