Weird behaviour with ampersand(&) keyword in urls #2351
-
The following mdx [this is a link](https://pbs.twimg.com/media/F6FamBAWIAE3HrA?format=png&name=small) is outputted as following html <img src="https://pbs.twimg.com/media/F6FamBAWIAE3HrA?format=png&name=small" alt="test"> You see the I'm using nextjs mdx btw. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Welcome @xoldyckk! 👋 [this is a link](https://pbs.twimg.com/media/F6FamBAWIAE3HrA?format=png&name=small) produces the React component: /*@jsxRuntime automatic @jsxImportSource react*/
const {jsx: _jsx} = arguments[0];
function _createMdxContent(props) {
const _components = {
a: "a",
p: "p",
...props.components
};
return _jsx(_components.p, {
children: _jsx(_components.a, {
href: "https://pbs.twimg.com/media/F6FamBAWIAE3HrA?format=png&name=small",
children: "this is a link"
})
});
}
function MDXContent(props = {}) {
const {wrapper: MDXLayout} = props.components || ({});
return MDXLayout ? _jsx(MDXLayout, Object.assign({}, props, {
children: _jsx(_createMdxContent, props)
})) : _createMdxContent(props);
}
return {
default: MDXContent
}; 📓 note that there is no modification to the encoding It is likely another transform or library in your application modifying the URL. |
Beta Was this translation helpful? Give feedback.
-
Importantly, that transform doesn't break anything. Browsers do understand it, in fact they want it. If your image is broken, that's because something else. Using & amp; is fine. |
Beta Was this translation helpful? Give feedback.
@xoldyckk Focus on creating a minimal reproducible example https://stackoverflow.com/help/minimal-reproducible-example
When I took the sandbox you shared, and pulled out tailwind and the experimental next options, then added the recommended options from https://mdxjs.com/docs/getting-started/#nextjs
It does renders with
&
instead of&
https://codesandbox.io/p/sandbox/nextjs-mdx-forked-k7l629?file=/next.config.mjs:10,1You are welcome to tinker around and try to figured out which extra layer you added was the precise root cause of
&
.But MDX and
@next/mdx
work fine when using the default/recommended configuration.