Skip to content
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

Error when meta content includes quote #44

Closed
zhangciwu opened this issue Jul 27, 2018 · 10 comments
Closed

Error when meta content includes quote #44

zhangciwu opened this issue Jul 27, 2018 · 10 comments

Comments

@zhangciwu
Copy link

zhangciwu commented Jul 27, 2018

Version: v3.0.0
Error stack:

index.esm.js?d732:58 Uncaught DOMException: Failed to execute 'querySelector' on 'Element': 'meta[property="og:title"][content=""Có tâm" như Lý Quý Khánh chụp ảnh cho Hà Hồ: Lần nào cũng hết hồn chim én!"][data-rh=""]' is not a valid selector.
    at HeadTag.componentDidMount (webpack-internal:///./node_modules/react-head/dist/index.esm.js:74:33)
    at commitLifeCycles (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:14361:22)
    at commitAllLifeCycles (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:15462:7)
    at HTMLUnknownElement.callCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:100:14)
    at Object.invokeGuardedCallbackDev (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:138:16)
    at invokeGuardedCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:187:29)
    at commitRoot (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:15603:7)
    at completeRoot (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:16618:34)
    at performWorkOnRoot (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:16563:9)
    at performWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:16482:7)

Quite serious that page just gone white.

It seems cause of meta content which include double quote mark(")
Maybe do not use content as part of querySelector? (or perform suitable escaping before query)

And, I only want head tags performs on server, and leave it alone at client side (My MPA do not use front-ending routing), Maybe add some option to do this.

@zhangciwu
Copy link
Author

My workaround:

import {createElement} from 'react';
import {HeadTag, Meta} from 'react-head';

const HeadTagSsrOnly = HeadTag;

// remove all client refresh actions.
HeadTagSsrOnly.prototype.componentDidMount = () => {
  // nothing
};

HeadTagSsrOnly.prototype.componentWillUnmount = () => {
  // nothing
};

export { HeadTagSsrOnly};

Only for MPA without front-ending routing

@TrySound
Copy link
Collaborator

@tizmagik Seems like there is something wrong with selector builder

@tizmagik
Copy link
Owner

Yea, this is the same issue as #16 -- I think we just need to escape the selector

@zhangciwu
Copy link
Author

Using content as query isn't quite smart( content can be various and very long)
Maybe react's key mechanism is a good solution
Require key when insert head tags and using it to manipulate dom then

@tizmagik
Copy link
Owner

tizmagik commented Jul 28, 2018

We need some kind of deterministic key that we are aware of/control on both server and client side — open to suggestions!

Edit: Hm, actually maybe we only need to know that react-head places the tags, so maybe we don’t need such a deterministic key?

@zhangciwu
Copy link
Author

zhangciwu commented Jul 28, 2018

Seems buildSelector is used to remove SSR tags only,
Maybe just tagging SSR tags for all (like add a "ssr" attribute to the html)
And at client just remove all tags with that attribute

Need to select a name that will not be used by others, like "__ssr__" (kind of python style)

@TrySound
Copy link
Collaborator

We already use data-rh by the way

@zhangciwu
Copy link
Author

So just delete all document.querySelectorAll('head [data-rh]') to remove SSR tags?

@tizmagik
Copy link
Owner

I think so, that should work. Would you be able to submit a PR and try it out?

zhangciwu added a commit to zhangciwu/react-head that referenced this issue Jul 30, 2018
zhangciwu added a commit to zhangciwu/react-head that referenced this issue Aug 10, 2018
TrySound added a commit that referenced this issue Aug 14, 2018
Ref #44

In this diff I remove selector builder in favour of querying and
removing all SSR tags.

This should fix the problem with language characters and unescaped
quotes.
TrySound added a commit that referenced this issue Aug 16, 2018
Ref #44

In this diff I remove selector builder in favour of querying and
removing all SSR tags.

This should fix the problem with language characters and unescaped
quotes.
@tizmagik
Copy link
Owner

This is now fixed with the latest v3.0.0 release. Please feel free to open a new issue if there's still any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants