abhaynikam/react-trix-rte

getUniqInputId is not always unique

Closed this issue · 2 comments

Hello, and thank you for your great work on this project!

I think I have found a little bug in the utils.js file. If the getUniqInputId() is called twice within the same millisecond, it will return the same result. In that case, the getUniqInputID() will not return unique IDs.

export const getUniqInputId = (prefix = 'react-trix-rte-input-') => {
const uniqueDateTimestamp = new Date().getTime();
return `${prefix}${uniqueDateTimestamp}`
}

These ID collisions can cause some issues when rendering many <ReactTrixRTEInput> elements at the same time.

I am not very familiar with the performance constraints of this package and whether it would be worth the effort, but I think using the uuid package to generate these IDs would ensure they are unique.

Another suggestion I can think of is adding a Math.random() addition to salt the current implementation with a random number.

Please let me know what you think of these suggestions, I would love to write a PR and help out!

Thank you again for all your work, it's been great to work with!

@rjclaasen Sorry for the late reply. I think we can try the Math.random() to add extra salt to the unique ID generated. Please feel free to make a PR for the changes. I would be happy to test and release a new version of the package 😊

@rjclaasen Could you create a PR for this?