Code Monkey home page Code Monkey logo

Comments (5)

tizmagik avatar tizmagik commented on May 17, 2024

Hey thanks for the nice note :)

I think what you're running into is React's auto-escaping by default? There's some ways around that documented here: https://shripadk.github.io/react/docs/jsx-gotchas.html -- does that help?

from react-head.

JoshuaToenyes avatar JoshuaToenyes commented on May 17, 2024

Hi, @tizmagik – Sorry for the delayed response. Yes, I read through that. Unfortunately, I don't see a workaround for attributes. dangerouslySetInnerHTML is the closest... but isn't for attributes.

Unless I missing something obvious... Work correctly in the browser, just not with renderToStaticMarkup.

from react-head.

tizmagik avatar tizmagik commented on May 17, 2024

Oh interesting, hmm... do you know if the problem is specific to react-head or to renderToStaticMarkup?

from react-head.

JoshuaToenyes avatar JoshuaToenyes commented on May 17, 2024

I've got something going on with my GitHub notifications because I never get a notice when you respond...

Looks like it's an issue with ReactDOM's renderToStaticMarkup. Here's a runkit:
http://runkit.com/joshuatoenyes/reactdom-ampersand-test

Which leads me back to the workaround... Seem's like this is definitely a JSX "gotcha."

So unless there's some known workaround that I'm not aware of (which seems like the case), I think the only solutions are:

a) not include ampersands in URL's (what I'm doing now)
b) build a custom React renderer for React Head that doesn't escape in SSR

I'll fix my notifications :) cheers.

from react-head.

JoshuaToenyes avatar JoshuaToenyes commented on May 17, 2024

It looks like React Helmet can allow special characters in generated SSR output by flipping the encodeSpecialCharacters property to false.

They're manually building the tag strings:
https://github.com/nfl/react-helmet/blob/420810c644f94c3743f7b088321dbd62a8037b7b/src/HelmetUtils.js#L514

Obviously a more complex approach than React Head takes.

I'm going to close this issue by noting for posterity that React Head doesn't support this particular corner case since all rendered components for SSR are piped through React and therefore subject to React's JSX escaping rules.

Thanks!

from react-head.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.