From 83d9a8322a18b3fd3e15e9acfef8e4fe36596b4a Mon Sep 17 00:00:00 2001 From: Ragura Date: Tue, 23 Apr 2024 13:10:50 +0200 Subject: [PATCH 1/2] fix: move src attribute to end of tag to fix lazy loading (#1317) --- src/runtime/components/nuxt-img.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/components/nuxt-img.ts b/src/runtime/components/nuxt-img.ts index 37388aa42..0df2f93b8 100644 --- a/src/runtime/components/nuxt-img.ts +++ b/src/runtime/components/nuxt-img.ts @@ -147,11 +147,11 @@ export default defineComponent({ return () => h('img', { ref: imgEl, - src: src.value, ...import.meta.server ? { onerror: 'this.setAttribute(\'data-error\', 1)' } : {}, ...attrs.value, ...ctx.attrs, class: props.placeholder && !placeholderLoaded.value ? [props.placeholderClass] : undefined, + src: src.value, }) }, }) From d16387da28765a37a38fd75d342c4aa13042cecb Mon Sep 17 00:00:00 2001 From: Ragura Date: Tue, 23 Apr 2024 13:44:31 +0200 Subject: [PATCH 2/2] test: fix snapshots --- test/unit/image.test.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/unit/image.test.ts b/test/unit/image.test.ts index b51016afa..bbc29c3a3 100644 --- a/test/unit/image.test.ts +++ b/test/unit/image.test.ts @@ -22,7 +22,7 @@ describe('Renders simple image', () => { }) it('Matches snapshot', () => { - expect(wrapper.html()).toMatchInlineSnapshot('""') + expect(wrapper.html()).toMatchInlineSnapshot(`""`) }) it('props.src is picked up by getImage()', () => { @@ -52,7 +52,7 @@ describe('Renders simple image', () => { densities: '1x 2x 3x', src: 'image.png', }) - expect(img.html()).toMatchInlineSnapshot('""') + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('empty densities (fallback to global)', () => { @@ -63,7 +63,7 @@ describe('Renders simple image', () => { densities: '', src: 'image.png', }) - expect(img.html()).toMatchInlineSnapshot('""') + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('empty string densities (fallback to global)', () => { @@ -74,7 +74,7 @@ describe('Renders simple image', () => { densities: ' ', src: 'image.png', }) - expect(img.html()).toMatchInlineSnapshot('""') + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('error on invalid densities', () => { @@ -93,7 +93,7 @@ describe('Renders simple image', () => { height: 400, sizes: '150', }) - expect(img.html()).toMatchInlineSnapshot('""') + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('with single sizes entry (responsive)', () => { @@ -103,7 +103,7 @@ describe('Renders simple image', () => { height: 400, sizes: 'sm:150', }) - expect(img.html()).toMatchInlineSnapshot('""') + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('de-duplicates sizes & srcset', () => { @@ -113,7 +113,7 @@ describe('Renders simple image', () => { sizes: '200:200px,300:200px,400:400px,400:400px,500:500px,800:800px', src: 'image.png', }) - expect(img.html()).toMatchInlineSnapshot('""') + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('encodes characters', () => { @@ -123,7 +123,7 @@ describe('Renders simple image', () => { sizes: '200,500:500,900:900', src: '/汉字.png', }) - expect(img.html()).toMatchInlineSnapshot('""') + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('correctly sets crop', () => { @@ -133,7 +133,7 @@ describe('Renders simple image', () => { height: 2000, sizes: 'xs:100vw sm:100vw md:300px lg:350px xl:350px 2xl:350px', }) - expect(img.html()).toMatchInlineSnapshot('""') + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('without sizes, but densities', () => { @@ -143,7 +143,7 @@ describe('Renders simple image', () => { height: 400, densities: '1x 2x 3x', }) - expect(img.html()).toMatchInlineSnapshot('""') + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('with nonce', () => { @@ -307,7 +307,7 @@ describe('Renders image, applies module config', () => { sizes: '200,500:500,900:900', }, }) - expect(img.html()).toMatchInlineSnapshot('""') + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('Module config .quality + props.quality => props.quality applies', () => { @@ -327,7 +327,7 @@ describe('Renders image, applies module config', () => { quality: 90, }, }) - expect(img.html()).toMatchInlineSnapshot('""') + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('Without quality config => default image', () => { @@ -345,7 +345,7 @@ describe('Renders image, applies module config', () => { sizes: '200,500:500,900:900', }, }) - expect(img.html()).toMatchInlineSnapshot('""') + expect(img.html()).toMatchInlineSnapshot(`""`) }) })