From 72f64abeb64363a8fd8a49adb693295c766a691d Mon Sep 17 00:00:00 2001 From: typhonrt Date: Thu, 6 Jan 2022 17:23:52 -0800 Subject: [PATCH] Switch unique_id from `Date.now` to `Math.random`; include basic typing for variable assignment. --- src/runtime/internal/style_manager.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/runtime/internal/style_manager.ts b/src/runtime/internal/style_manager.ts index 0ae588c2f0..3e0098e956 100644 --- a/src/runtime/internal/style_manager.ts +++ b/src/runtime/internal/style_manager.ts @@ -9,9 +9,9 @@ const active_docs = new Set(); let active = 0; // A suitable unique ID to create separate style sheets per Svelte runtime. Fixes issue #7026. -// It is possible a more universal / UUID may be relevant to use instead of `Date.now` in the future. +// It is possible a more universal / UUID may be relevant to use instead of `Math.random` in the future. // Define unique keys to store the style transitions so one Svelte runtime does not clobber the data of another. -const unique_id = Date.now(); +const unique_id = Math.random(); const svelte_stylesheet = `__svelte_stylesheet_${unique_id}`; const svelte_rules = `__svelte_rules_${unique_id}`; @@ -37,8 +37,8 @@ export function create_rule(node: Element & ElementCSSInlineStyle, a: number, b: const name = `__svelte_${hash(rule)}_${uid}`; const doc = get_root_for_style(node) as ExtendedDoc; active_docs.add(doc); - const stylesheet = doc[svelte_stylesheet] || (doc[svelte_stylesheet] = append_empty_stylesheet(node).sheet as CSSStyleSheet); - const current_rules = doc[svelte_rules] || (doc[svelte_rules] = {}); + const stylesheet: CSSStyleSheet = doc[svelte_stylesheet] || (doc[svelte_stylesheet] = append_empty_stylesheet(node).sheet as CSSStyleSheet); + const current_rules: Record = doc[svelte_rules] || (doc[svelte_rules] = {}); if (!current_rules[name]) { current_rules[name] = true; @@ -70,7 +70,7 @@ export function clear_rules() { raf(() => { if (active) return; active_docs.forEach(doc => { - const stylesheet = doc[svelte_stylesheet]; + const stylesheet: CSSStyleSheet = doc[svelte_stylesheet]; let i = stylesheet.cssRules.length; while (i--) stylesheet.deleteRule(i); doc[svelte_rules] = {};