Repository: withastro/astro
File: packages/astro/src/assets/vite-plugin-assets.ts (TypeScript)

Code before:
					const emitFile = shouldEmitFile ? this.emitFile.bind(this) : undefined;
					const imageMetadata = await emitESMImage(
						id,
						this.meta.watchMode,
						id.endsWith('.svg'),
						emitFile,
					);

					if (!imageMetadata) {
						throw new AstroError({
							...AstroErrorData.ImageNotFound,
							message: AstroErrorData.ImageNotFound.message(id),
						});
					}

					// We can only reliably determine if an image is used on the server, as we need to track its usage throughout the entire build.
					// Since you cannot use image optimization on the client anyway, it's safe to assume that if the user imported
					// an image on the client, it should be present in the final build.
					if (options?.ssr) {
						if (id.endsWith('.svg')) {
							const contents = await fs.promises.readFile(imageMetadata.fsPath, {
								encoding: 'utf8',
							});
							// We know that the contents are present, as we only emit this property for SVG files
							return {
								code: makeSvgComponent(imageMetadata, contents, settings.config.experimental?.svg),
							};
						}
						return {
							code: `export default ${getProxyCode(
								imageMetadata,
								settings.buildOutput === 'server',
							)}`,
						};
					} else {
						globalThis.astroAsset.referencedImages.add(imageMetadata.fsPath);
						return {
							code: `export default ${JSON.stringify(imageMetadata)}`,
						};
					}
				}
			},
		},
		fontsPlugin({ settings, sync, logger }),
	];
}


Review comment (suggestion):
```suggestion
								code: makeSvgComponent(imageMetadata, contents, settings.config.experimental.svg),
```

Code after:
					const emitFile = shouldEmitFile ? this.emitFile.bind(this) : undefined;
					const imageMetadata = await emitESMImage(
						id,
						this.meta.watchMode,
						id.endsWith('.svg'),
						emitFile,
					);

					if (!imageMetadata) {
						throw new AstroError({
							...AstroErrorData.ImageNotFound,
							message: AstroErrorData.ImageNotFound.message(id),
						});
					}

					// We can only reliably determine if an image is used on the server, as we need to track its usage throughout the entire build.
					// Since you cannot use image optimization on the client anyway, it's safe to assume that if the user imported
					// an image on the client, it should be present in the final build.
					if (options?.ssr) {
						if (id.endsWith('.svg')) {
							const contents = await fs.promises.readFile(imageMetadata.fsPath, {
								encoding: 'utf8',
							});
							// We know that the contents are present, as we only emit this property for SVG files
							return {
								code: makeSvgComponent(imageMetadata, contents, settings.config.experimental.svgo),
							};
						}
						return {
							code: `export default ${getProxyCode(
								imageMetadata,
								settings.buildOutput === 'server',
							)}`,
						};
					} else {
						globalThis.astroAsset.referencedImages.add(imageMetadata.fsPath);
						return {
							code: `export default ${JSON.stringify(imageMetadata)}`,
						};
					}
				}
			},
		},
		fontsPlugin({ settings, sync, logger }),
	];
}