diff --git a/.changeset/long-roses-shave.md b/.changeset/long-roses-shave.md new file mode 100644 index 0000000000..65c6d09227 --- /dev/null +++ b/.changeset/long-roses-shave.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Omit nullish and falsy (non-zero) values when stringifying object-form `style` attributes in Astro files diff --git a/packages/astro/src/runtime/server/render/util.ts b/packages/astro/src/runtime/server/render/util.ts index fca449fcf0..89d51ba6cb 100644 --- a/packages/astro/src/runtime/server/render/util.ts +++ b/packages/astro/src/runtime/server/render/util.ts @@ -28,6 +28,7 @@ const kebab = (k: string) => k.toLowerCase() === k ? k : k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`); const toStyleString = (obj: Record) => Object.entries(obj) + .filter(([k, v]) => typeof v === 'string' && v.trim() || typeof v === 'number') .map(([k, v]) => { if (k[0] !== '-' && k[1] !== '-') return `${kebab(k)}:${v}`; return `${k}:${v}`;