parcel icon indicating copy to clipboard operation
parcel copied to clipboard

`<svg>` tag makes the next siblings disappear

Open byF opened this issue 7 months ago • 1 comments

🐛 bug report

If you try to parcel an HTML file such as this:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>
    <div>
      <svg></svg>
      <p>aaa</p>
      <p>bbb</p>
    </div>
  </body>
</html>

the HTML file produced by Parcel will have two newlines instead of paragraphs, i.e.

<div>
  <svg></svg>


</div>

This happens only for the tags which follow after the svg tag.

🎛 Configuration (.babelrc, package.json, cli command)

Default settings, running parcel build test.html

🌍 Your Environment

Software Version(s)
Parcel 2.15.2
Node 22.15.0
npm/Yarn 11.3.0
Operating System macOS Sequoia 15.5

byF avatar May 29 '25 17:05 byF

I have a similar problem in my project.

When I tried to migrate from 2.13 to 2.15 I thought there was a problem with the svg tag.

However, when creating a basic project to report it, I can reproduce the problem with a very basic html file and without svgs. The sample project is https://github.com/rferrerasm/parcel-minimal-example.

I get a partially minifyed, truncated index.html:

<!DOCTYPE html><html lang=en><meta charset=utf-8><meta name=viewport content="width=device-width, initial-scale=1.0"><title>Title</title><body>
    <p>
      Body.
    </p>
  


I am using Windows 11. I have tried Node 20, 22 and 24 all with the same results.

rferrerasm avatar Jun 08 '25 12:06 rferrerasm

Im having the same issue. It seems like it's only happening when building a file not in development mode. Maybe related to https://github.com/parcel-bundler/parcel/pull/10090

sailerinteractive avatar Jun 25 '25 08:06 sailerinteractive

I'm getting this issue as well. I had to go back to 2.14.4 to get it working. From 2.15.0 and up it doesn't work

joshfester avatar Jul 25 '25 22:07 joshfester

A Containerfile with minimal reproduction:

FROM node:24-alpine
WORKDIR /app
RUN npm install -g parcel@latest
RUN echo '<div><p>Before</p><svg><circle/></svg><p>After</p><p>Also removed</p></div>' > index.html && \
    parcel build index.html && \
    echo "=== Original ===" && cat index.html && \
    echo "=== Built ===" && cat dist/index.html && \
    grep -q "Also removed" dist/index.html || (echo "❌ BUG: Siblings after <svg> gone" && exit 1)
$ podman build .
...
dist/index.html    46 B    90ms
=== Original ===
<div><p>Before</p><svg><circle/></svg><p>After</p><p>Also removed</p></div>
=== Built ===
<div><p>Before</p><svg><circle /></svg></div>

TjeuKayim avatar Nov 05 '25 15:11 TjeuKayim

This is not a solution, but a temporary workaround. Add this to your .parcelrc to be able to use the latest versions when experiencing this issue.

  "optimizers": {
    "*.html": []
  },

sailerinteractive avatar Nov 14 '25 12:11 sailerinteractive

Alternative workaround that keeps most optimizations enabled: config .htmlnanorc.json

{
  "minifySvg": false
}

TjeuKayim avatar Nov 14 '25 13:11 TjeuKayim