You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the last release 4.3.0, we introduced a feature for falling back to existing title when titleProp is set to true. But the feature is not working as expected in an application. It doesn't fallback to existing title.
To Reproduce
Fork create-react-app and update the @svgr/webpack package in packages/react-scripts to 4.3.0 and update packages/react-scripts/config/webpack.config.js to include the +titleProp option in svgr loader.
Run yarn to install all the dependencies
Commit your changes if necessary
Create an application with this create-react-app setup by running yarn create-react-app my-app
Now go into the my-app folder and change the logo.svg to add a title
<svg...>
+ <title>React Logo</title>
Import this svg as ReactComponent in App.js
- import logo from "./logo.svg"+ import { ReactComponent as Logo } from "./logo.svg"
function App () {
return (
<div className="App">
<header className="App-header">
- <img src={logo} className="App-logo" alt="logo" />+ <Logo className="App-logo" />
Now run the application with yarn start and inspect the title element in the developer tools. We see an empty title element (<title></title>).
Expected behavior
I expect the title element to be <title>React Logo</title>
Possible Issues
Looking at the source code of packages/babel-plugin-svg-dynamic-title/src/index.js, we see that the children of the title element are joined with the .value which works only for JSXText but not for JSXExpressionContainer. And it seems like in the application I tested, it was returning the title's children as JSXExpressionContainer.
Possible Solution
Instead returning the title expression from conditional check ({title === undefined ? 'Fallback_Title_Children' : title}), we can return the title element itself ({title === undefined ? <title>{Fallback_Title_Children}</title> : <title>{title}</title>}). That way, we do not need to handle any cases that may occur for the children of existing title.
The text was updated successfully, but these errors were encountered:
🐛 Bug Report
In the last release
4.3.0
, we introduced a feature for falling back to existing title whentitleProp
is set totrue
. But the feature is not working as expected in an application. It doesn't fallback to existing title.To Reproduce
create-react-app
and update the@svgr/webpack
package inpackages/react-scripts
to4.3.0
and updatepackages/react-scripts/config/webpack.config.js
to include the+titleProp
option in svgr loader.yarn
to install all the dependenciescreate-react-app
setup by runningyarn create-react-app my-app
my-app
folder and change thelogo.svg
to add a title<svg...> + <title>React Logo</title>
App.js
yarn start
and inspect thetitle
element in the developer tools. We see an empty title element (<title></title>
).Expected behavior
I expect the title element to be
<title>React Logo</title>
Possible Issues
Looking at the source code of
packages/babel-plugin-svg-dynamic-title/src/index.js
, we see that the children of the title element arejoined
with the.value
which works only forJSXText
but not forJSXExpressionContainer
. And it seems like in the application I tested, it was returning the title's children as JSXExpressionContainer.Possible Solution
Instead returning the title expression from conditional check (
{title === undefined ? 'Fallback_Title_Children' : title}
), we can return the title element itself ({title === undefined ? <title>{Fallback_Title_Children}</title> : <title>{title}</title>}
). That way, we do not need to handle any cases that may occur for the children of existing title.The text was updated successfully, but these errors were encountered: