From e86e2c7cd501984e242e95d5ab41c95de9b8e0ad Mon Sep 17 00:00:00 2001 From: OfirHaf Date: Fri, 15 May 2026 10:56:01 +0300 Subject: [PATCH] fix: add DEV warning for style directive values with trailing semicolons --- .../src/internal/client/dom/elements/style.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/svelte/src/internal/client/dom/elements/style.js b/packages/svelte/src/internal/client/dom/elements/style.js index 5a84604d09..6c00103607 100644 --- a/packages/svelte/src/internal/client/dom/elements/style.js +++ b/packages/svelte/src/internal/client/dom/elements/style.js @@ -1,3 +1,4 @@ +import { DEV } from 'esm-env'; import { to_style } from '../../../shared/attributes.js'; import { hydrating } from '../hydration.js'; @@ -15,10 +16,18 @@ function update_styles(dom, prev = {}, next, priority) { if (value == null) { dom.style.removeProperty(key); } else { + var str_value = String(value); + + if (DEV && /;+\s*$/.test(str_value)) { + // eslint-disable-next-line no-console + console.warn( + `[svelte] Style directive value for "${key}" has a trailing semicolon which is invalid and will be removed. Remove the trailing ";" from the value.` + ); + } + // setProperty rejects values with trailing semicolons; strip them so that // reactive updates behave consistently with the initial cssText assignment - var str_value = String(value).replace(/;+\s*$/, ''); - dom.style.setProperty(key, str_value, priority); + dom.style.setProperty(key, str_value.replace(/;+\s*$/, ''), priority); } } }