question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: renderToStaticMarkup throw warning about SVG PascalCase and camelCase naming

See original GitHub issue

React version: 16.12.0

Error: Warning: <linearGradient /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.

The current behavior

Any SVG-inside node(LinearGradient, feDropShadow, etc), that should be in PascalCase/camelCase inside HTML indeed, throw me a warning above through React’s import { renderToStaticMarkup } from 'react-dom/server' renderToStaticMarkup method.

I use renderToStaticMarkup to parse and then insert its DOM inside global HTML (don’t ask me why 😃 ) on client-side, not SSR.

The expected behavior

Should not throw any warnings and render SVG-in tags in PascalCase without any efforts and tears in fact.

Thanks.

P.S. I saw this report, but it seems like it doesn’t fix for some reason https://github.com/facebook/react/issues/10415

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
dfltrcommented, Mar 17, 2020

I had a quick look at this one, and as far as I can tell the error is being thrown because getIntrinsicNamespace() tests specifically for an <svg> tag at the top level, so an orphaned <linearGradient> (or any other camelCase SVG child) is assumed to be in the HTML namespace. Because it’s assumed to be in the HTML namespace, it fails the naming convention test for HTML elements, hence the error.

The test could be expanded to cover the 32 valid SVG child tags that have camelCase names, which would make getIntrinsicNamespace ~653 bytes longer, but that would also result in lowercase SVG children, hyphenated children, and camelCase children all going through slightly different code paths for validation.

I’m still new around here so I’m not sure what the general policy is on balancing edge cases vs. library size vs. consistency so let me know.

0reactions
BiosBoycommented, Nov 11, 2020

A workaround would be to wrap your element in <svg> and then extract it from the output. Hope that helps!

Seems like this is a truly workaround for now. Worked for me!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I get rid of react error warnings telling me to change ...
I understand that react wants multi-word properties as camel case, but these SVGs need to be usable in a non-React context.
Read more >
Code coverage report for node-npmtest-react-dom ...
Similar to invariant but only logs a warning if the condition is not met. ... Since these are SVG attributes, their attribute names...
Read more >
SCREAMING_SNAKE_CASE in React Web Development
The message reads: Imported JSX component _Document must be in PascalCase or SCREAMING_SNAKE_CASE eslint(react/jsx-pascal-case) .
Read more >
Pascal case vs. camel case: What's the difference?
We'll show you the difference between the two common variable naming conventions, along with some examples.
Read more >
vue/component-name-in-template-casing
Rule Details #. This rule aims to warn the tag names other than the configured casing in Vue.js template. Options ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found