From d29c91ea4bbbc7a708b69efdcec65f3fa83e083c Mon Sep 17 00:00:00 2001 From: Ottomated Date: Thu, 16 Nov 2023 16:07:11 -0800 Subject: [PATCH 1/7] fix VITE_ASSET issue --- packages/enhanced-img/src/preprocessor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/enhanced-img/src/preprocessor.js b/packages/enhanced-img/src/preprocessor.js index 222ad6189954..1c637c3089cb 100644 --- a/packages/enhanced-img/src/preprocessor.js +++ b/packages/enhanced-img/src/preprocessor.js @@ -211,7 +211,7 @@ function get_attr_value(node, attr) { function img_attributes_to_markdown(content, attributes, details) { const attribute_strings = attributes.map((attribute) => { if (attribute.name === 'src') { - return `src=${details.src}`; + return `src={"${details.src}"}`; } return content.substring(attribute.start, attribute.end); }); @@ -268,7 +268,7 @@ function img_to_picture(content, node, image) { let res = ''; for (const [format, srcset] of Object.entries(image.sources)) { - res += ``; + res += ``; } res += ` Date: Thu, 16 Nov 2023 21:56:59 -0800 Subject: [PATCH 2/7] changeset --- .changeset/slow-students-run.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/slow-students-run.md diff --git a/.changeset/slow-students-run.md b/.changeset/slow-students-run.md new file mode 100644 index 000000000000..ff8bcb6d3607 --- /dev/null +++ b/.changeset/slow-students-run.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/enhanced-img': patch +--- + +Fixes compilation for client chunks From aeeca6345f93590ab259288c996799e04f0fab74 Mon Sep 17 00:00:00 2001 From: Ottomated Date: Thu, 16 Nov 2023 22:47:43 -0800 Subject: [PATCH 3/7] fix tests --- packages/enhanced-img/src/preprocessor.js | 4 ++-- packages/enhanced-img/test/Output.svelte | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/enhanced-img/src/preprocessor.js b/packages/enhanced-img/src/preprocessor.js index 1c637c3089cb..04e1cb399c27 100644 --- a/packages/enhanced-img/src/preprocessor.js +++ b/packages/enhanced-img/src/preprocessor.js @@ -211,7 +211,7 @@ function get_attr_value(node, attr) { function img_attributes_to_markdown(content, attributes, details) { const attribute_strings = attributes.map((attribute) => { if (attribute.name === 'src') { - return `src={"${details.src}"}`; + return `src=${details.src}`; } return content.substring(attribute.start, attribute.end); }); @@ -271,7 +271,7 @@ function img_to_picture(content, node, image) { res += ``; } res += ``; diff --git a/packages/enhanced-img/test/Output.svelte b/packages/enhanced-img/test/Output.svelte index 61b9820c27a3..f6e08021b472 100644 --- a/packages/enhanced-img/test/Output.svelte +++ b/packages/enhanced-img/test/Output.svelte @@ -14,21 +14,21 @@ non-enhanced test -basic test +basic test -dimensions test +dimensions test -directive test +directive test -spread attributes test +spread attributes test -sizes test +sizes test -event handler test +event handler test -alias test +alias test -absolute path test +absolute path test svg test From 090af8661be1ca15474cce8c5f620d645ba25c66 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 18 Nov 2023 08:29:19 -0800 Subject: [PATCH 4/7] optimize --- packages/enhanced-img/src/preprocessor.js | 8 +++++++- packages/enhanced-img/test/Output.svelte | 16 ++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/enhanced-img/src/preprocessor.js b/packages/enhanced-img/src/preprocessor.js index 04e1cb399c27..f8499e9482e8 100644 --- a/packages/enhanced-img/src/preprocessor.js +++ b/packages/enhanced-img/src/preprocessor.js @@ -270,8 +270,14 @@ function img_to_picture(content, node, image) { for (const [format, srcset] of Object.entries(image.sources)) { res += ``; } + // Need to handle src differently when using either Vite's renderBuiltUrl or relative base path in Vite. + // See https://github.com/vitejs/vite/blob/b93dfe3e08f56cafe2e549efd80285a12a3dc2f0/packages/vite/src/node/plugins/asset.ts#L132 + const src = + image.img.src.startsWith('"+') && src.endsWith('+"') + ? `{"${image.img.src.substring(2, image.img.src.length - 2)}"}` + : `"${image.img.src}"`; res += ``; diff --git a/packages/enhanced-img/test/Output.svelte b/packages/enhanced-img/test/Output.svelte index f6e08021b472..fe7caca8a830 100644 --- a/packages/enhanced-img/test/Output.svelte +++ b/packages/enhanced-img/test/Output.svelte @@ -14,21 +14,21 @@ non-enhanced test -basic test +basic test -dimensions test +dimensions test -directive test +directive test -spread attributes test +spread attributes test -sizes test +sizes test -event handler test +event handler test -alias test +alias test -absolute path test +absolute path test svg test From 04e03892c758fd6cd3156e73c2851ccd850f7a3a Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 18 Nov 2023 08:34:53 -0800 Subject: [PATCH 5/7] fix --- packages/enhanced-img/src/preprocessor.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/enhanced-img/src/preprocessor.js b/packages/enhanced-img/src/preprocessor.js index f8499e9482e8..8e21bdb9eb82 100644 --- a/packages/enhanced-img/src/preprocessor.js +++ b/packages/enhanced-img/src/preprocessor.js @@ -272,8 +272,9 @@ function img_to_picture(content, node, image) { } // Need to handle src differently when using either Vite's renderBuiltUrl or relative base path in Vite. // See https://github.com/vitejs/vite/blob/b93dfe3e08f56cafe2e549efd80285a12a3dc2f0/packages/vite/src/node/plugins/asset.ts#L132 + /** @type {string} */ const src = - image.img.src.startsWith('"+') && src.endsWith('+"') + image.img.src.startsWith('"+') && image.img.src.endsWith('+"') ? `{"${image.img.src.substring(2, image.img.src.length - 2)}"}` : `"${image.img.src}"`; res += ` Date: Sat, 18 Nov 2023 08:35:21 -0800 Subject: [PATCH 6/7] infer type --- packages/enhanced-img/src/preprocessor.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/enhanced-img/src/preprocessor.js b/packages/enhanced-img/src/preprocessor.js index 8e21bdb9eb82..bf1289a25878 100644 --- a/packages/enhanced-img/src/preprocessor.js +++ b/packages/enhanced-img/src/preprocessor.js @@ -272,7 +272,6 @@ function img_to_picture(content, node, image) { } // Need to handle src differently when using either Vite's renderBuiltUrl or relative base path in Vite. // See https://github.com/vitejs/vite/blob/b93dfe3e08f56cafe2e549efd80285a12a3dc2f0/packages/vite/src/node/plugins/asset.ts#L132 - /** @type {string} */ const src = image.img.src.startsWith('"+') && image.img.src.endsWith('+"') ? `{"${image.img.src.substring(2, image.img.src.length - 2)}"}` From c1ea90a87941c2b01d82ba28e7fd7d35e3b21888 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 18 Nov 2023 08:39:51 -0800 Subject: [PATCH 7/7] Update .changeset/slow-students-run.md --- .changeset/slow-students-run.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/slow-students-run.md b/.changeset/slow-students-run.md index ff8bcb6d3607..13f28a5479ad 100644 --- a/.changeset/slow-students-run.md +++ b/.changeset/slow-students-run.md @@ -2,4 +2,4 @@ '@sveltejs/enhanced-img': patch --- -Fixes compilation for client chunks +fix: correctly generate client-side code