kopia lustrzana https://github.com/Tldraw/Tldraw
[bugfix] Avoid randomness at init time to allow running on cloudflare. (#3016)
Describe what your pull request does. If appropriate, add GIFs or images showing the before and after. Follow up to #2987 ### Change Type - [x] `patch` — Bug fix ### Release Notes - Prevent using randomness API at init time, to allow importing the tldraw package in a cloudflare worker.pull/3017/head
rodzic
ba6cba64c6
commit
1d5a9efa17
|
@ -50,8 +50,9 @@ function iOS() {
|
|||
* A string that is unique per browser tab
|
||||
* @public
|
||||
*/
|
||||
export const TAB_ID: string =
|
||||
window?.[tabIdKey] ?? window?.sessionStorage[tabIdKey] ?? `TLDRAW_INSTANCE_STATE_V1_` + uniqueId()
|
||||
export const TAB_ID: string = window
|
||||
? window[tabIdKey] ?? window.sessionStorage[tabIdKey] ?? `TLDRAW_INSTANCE_STATE_V1_` + uniqueId()
|
||||
: '<error>'
|
||||
if (window) {
|
||||
window[tabIdKey] = TAB_ID
|
||||
if (iOS()) {
|
||||
|
|
|
@ -240,18 +240,24 @@ const channel =
|
|||
|
||||
channel?.addEventListener('message', (e) => {
|
||||
const data = e.data as undefined | UserChangeBroadcastMessage
|
||||
if (data?.type === broadcastEventKey && data?.origin !== broadcastOrigin) {
|
||||
if (data?.type === broadcastEventKey && data?.origin !== getBroadcastOrigin()) {
|
||||
globalUserPreferences.set(migrateUserPreferences(data.data))
|
||||
}
|
||||
})
|
||||
|
||||
const broadcastOrigin = uniqueId()
|
||||
let _broadcastOrigin = null as null | string
|
||||
function getBroadcastOrigin() {
|
||||
if (_broadcastOrigin === null) {
|
||||
_broadcastOrigin = uniqueId()
|
||||
}
|
||||
return _broadcastOrigin
|
||||
}
|
||||
const broadcastEventKey = 'tldraw-user-preferences-change' as const
|
||||
|
||||
function broadcastUserPreferencesChange() {
|
||||
channel?.postMessage({
|
||||
type: broadcastEventKey,
|
||||
origin: broadcastOrigin,
|
||||
origin: getBroadcastOrigin(),
|
||||
data: {
|
||||
user: getUserPreferences(),
|
||||
version: userMigrations.currentVersion,
|
||||
|
|
Ładowanie…
Reference in New Issue