diff --git a/.changeset/twenty-monkeys-thank.md b/.changeset/twenty-monkeys-thank.md new file mode 100644 index 000000000000..02ce782ab007 --- /dev/null +++ b/.changeset/twenty-monkeys-thank.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes style-only change detection for Astro files if both the markup and styles are updated diff --git a/packages/astro/src/vite-plugin-astro/hmr.ts b/packages/astro/src/vite-plugin-astro/hmr.ts index 2fca4aff54ad..861fccae4b71 100644 --- a/packages/astro/src/vite-plugin-astro/hmr.ts +++ b/packages/astro/src/vite-plugin-astro/hmr.ts @@ -65,7 +65,7 @@ const scriptRE = /'; + const newCode = ''; + assert.equal(isStyleOnlyChanged(oldCode, newCode), false); + }); + + it('should return true if only style has changed', () => { + const oldCode = ''; + const newCode = ''; + assert.equal(isStyleOnlyChanged(oldCode, newCode), true); + }); + + it('should return false if style tags are added or removed', () => { + const oldCode = ''; + const newCode = ''; + assert.equal(isStyleOnlyChanged(oldCode, newCode), false); + }); + + it('should return false if frontmatter has changed', () => { + const oldCode = ` +--- +title: Hello +--- +`; + const newCode = ` +--- +title: Hi +--- +`; + assert.equal(isStyleOnlyChanged(oldCode, newCode), false); + }); + + it('should return false if both frontmatter and style have changed', () => { + const oldCode = ` +--- +title: Hello +--- +`; + const newCode = ` +--- +title: Hi +--- +`; + assert.equal(isStyleOnlyChanged(oldCode, newCode), false); + }); + + it('should return false if both markup and style have changed', () => { + const oldCode = '