Skip to content

Commit

Permalink
Allow Googlebot and older browsers to render HeadProvider (#63)
Browse files Browse the repository at this point in the history
* Allow Googlebot and older browsers to render HeadProvider

Per [MDN](https://developer.mozilla.org/en-US/docs/Web/API/NodeList) the `NodeList` returned by `querySelectorAll` only supports `forEach` in modern browsers. The most notable browser missing off this list if Chromium ~41, which is the rendering ending that Googlebot is based on. By removing the `NodeList` `forEach` call, also per the MDN article, we can get Google rendering again.

* Use old school way of node removal

* Update size snapshot

* Revert `remove` change

* Add workaroudn explanation
  • Loading branch information
praxxis authored and tizmagik committed Sep 19, 2018
1 parent b294fa7 commit ea811cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
24 changes: 12 additions & 12 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"dist/index.umd.js": {
"bundled": 7804,
"minified": 3404,
"gzipped": 1401
"bundled": 7905,
"minified": 3433,
"gzipped": 1408
},
"dist/index.min.js": {
"bundled": 7674,
"minified": 3291,
"gzipped": 1350
"bundled": 7775,
"minified": 3320,
"gzipped": 1356
},
"dist/index.cjs.js": {
"bundled": 6456,
"minified": 3628,
"gzipped": 1281
"bundled": 6557,
"minified": 3657,
"gzipped": 1289
},
"dist/index.esm.js": {
"bundled": 6068,
"minified": 3315,
"gzipped": 1187,
"bundled": 6169,
"minified": 3344,
"gzipped": 1195,
"treeshaked": {
"rollup": {
"code": 420,
Expand Down
3 changes: 2 additions & 1 deletion src/HeadProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export default class HeadProvider extends React.Component {

componentDidMount() {
const ssrTags = document.head.querySelectorAll(`[data-rh=""]`);
ssrTags.forEach(ssrTag => ssrTag.remove());
// `forEach` on `NodeList` is not supported in Googlebot, so use a workaround
Array.prototype.forEach.call(ssrTags, ssrTag => ssrTag.remove());
}

render() {
Expand Down

0 comments on commit ea811cf

Please sign in to comment.