rob-race / react-trix

React wrapper around Trix editor from Basecamp + some lightweight features
ISC License
213 stars 42 forks source link

Change ID generation to UUID from timestamp #31

Closed cguess closed 4 years ago

cguess commented 4 years ago

Every Trix element needs its own unique id so that toolbars all affect the correct element and text is hydrated correctly. Previously this used a millisecond timestamp, and what was probably a hack to make sure that multiple elements generated didn't share the same id. This seems to work fine on Firefox and Chrome, however, for some reason, on Safari, I would often get collisions and it would break everything.

This commit replaced a timestamp with a UUID instead using the very popular uuid NPM module available here. This is even a proposal to be part of the JavaScript standard lib.

It does require one more dependecy but the uuid module itself has no dependencies and is a much better provider of uniquness than time is.