enhance-dev / enhance-ssr

Server side render for custom elements.
140 stars 9 forks source link

WIP: Remove nanoID dependency for WASM compatibility #57

Open ryanbethel opened 7 months ago

ryanbethel commented 7 months ago

Currently, this is a temporary hack to remove NanoId as a dependency. It is not required for a secure token or anything that requires a cryptographically solid random number. A better solution should be implemented.

Another temporary option to match the UUID format is:

export default function uuid() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  });
}
console.log(uuid())
kristoferjoseph commented 5 months ago

@ryanbethel what would you recommend we do with this? I am open to removing nanoid but I am unclear if this solution is a good enough change.

ryanbethel commented 5 months ago

Yeah, that is probably not good enough. It was just a temporary work around. I will look into what options we have inside quickJS compiled to WASM. I know we don't have full crypto randomness, but for the purpose of element unique id's I don't think we need that.