-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SVG viewBox
attribute getting stripped in HTML
#1523
Comments
This was fixed in #1316 but when I install with Yarn it still has the old unfixed code. |
Same issue here, without using |
I just fixed my issue by updating to 1.9.1 and removing the |
The problem still persists in 1.9.3 using build mode with and without a .posthtmlrc file being present. |
Same here... This is very troublesome. |
I am having this problem as well... |
@Zacaree Someone in another issue mentioned a different
|
Perhaps a good idea to open up an issue in posthtml to ask for safer transforms by default. |
@DeMoorJasper The issue isn't PostHTML's defaults; it's that Parcel applies different PostHTML settings to |
Even with the <svg viewBox="22 22 44 44">
<circle cx="44" cy="44" r="20.2" fill="none" stroke-width="3.6"></circle>
</svg> Can only get this working by moving the But yeah, I agree @andrewbanchich, the different settings for |
@andrewbanchich Can't find where serve and prod config differ? Can you point me to the code where this happens? Not sure why this would happen, the only thing I can think about is |
@andrewbanchich Awesome! Solution:
Thank you! |
Not working for me for some kind of reason 😩 parcel/src/transforms/posthtml.js Line 10 in 038ade6
|
@hacknug your snippet has it set to |
@DeMoorJasper None of those things fixed any issues for me. I don't know where in Parcel's code it is because I'm not a Parcel dev, but I know it is applying different configs to production vs dev builds because |
Alright, I actually just tried to explain that this is probably caused by htmlnano, as that's the only thing that differs between Well as the config solves this issue I guess we can close it, or open an issue in posthtml, as I don't think we should be changing the defaults |
The thing is this only works when it's inside {
"recognizeSelfClosing": true,
"lowerCaseAttributeNames": true
} module.exports = {
recognizeSelfClosing: true,
lowerCaseAttributeNames: false,
plugins: [
require('posthtml-include')({ root: 'src' }),
require('posthtml-expressions')({}),
],
} |
@DeMoorJasper should this also work when using {
"minifySvg": false
} |
I have the same problem with the id property in an svg tag. The only thing that helped was not minifying svgs at all :( |
Hi, I'm working on a little side project with vuejs and decided to give a try to parcel. I first tried this file: [.posthtmlrc] {
"recognizeSelfClosing": true,
"lowerCaseAttributeNames": false
} It worked with Then I added this file: [.htmlnanorc] {
"minifySvg": false
} Would it be possible to make the first file options default in parcel ? I think it should :) Thanks a lot for the answeres above! |
👍Perfect, but I also needed to clear the build cache: |
I also had to add both as per @benavern example. Otherwise all |
parcel/packages/core/parcel-bundler/src/transforms/htmlnano.js Lines 13 to 14 in d24e09a
we probably ought drop a little |
This fix didn't work for me (using Parcel 2), however this one does: https://gitmemory.com/issue/posthtml/posthtml/283/493249105
|
Hi, The htmlnano setting key must be `minifySvg` and not `minifySVG` . This PR probably fixes parcel-bundler#441 Ref: https://github.com/posthtml/htmlnano#minifysvg parcel-bundler/parcel#1523 (comment)
|
Due to SVG minification in htmlnano using SVGO the attributes seem to be removed. parcel-bundler/parcel#1523 (comment)
For newer version, you need to put {
"plugins": [
{
"name": "preset-default",
"params": {
"overrides": {
"removeViewBox": false
}
}
}
]
} |
since viewBox will be removed when bundled for prod parcel-bundler/parcel#1523
I need the view box, what alternative we have? |
🐛 bug report
I am having issues with
viewBox
being removed from inline SVG in my HTML file. I have passed my own options via.posthtmlrc
but I am still seeing the attribute removed on production build?🎛 Configuration (.babelrc, package.json, cli command)
🤔 Expected Behavior
When running
parcel build
the HTML output should include SVG code with theviewBox
attribute.😯 Current Behavior
Output from
parcel build
results in HTML SVG with out theviewBox
attribute as expected.💁 Possible Solution
I have looked into it and it appears
HTMLAsset.js
is callingposthtml-parser
with its own config of{lowerCaseAttributeNames: true}
which causesviewBox
to be removed.HTMLAsset.js
should use the config provided in.posthtmlrc
or no config.🔦 Context
I am building a static HTML page with inline SVG code. This breaks the rendering of my SVG because the
width
andheight
attributes do not match theviewBox
positioning.💻 Code Sample
Example Gist.
🌍 Your Environment
The text was updated successfully, but these errors were encountered: