next-routes icon indicating copy to clipboard operation
next-routes copied to clipboard

Critical need to fix that Object.assign issue

Open adriendomoison opened this issue 5 years ago • 5 comments

Hi!

Thanks a million for this amazing project.

Following #142 and #53 there is an urgent need to fix Object.assign, this needs at least to be polyfilled ASAP https://github.com/fridays/next-routes/blob/08e8bbeaa76c5ec194abea388a193bedac7f35fc/src/index.js#L96

This makes Googlebot crash 😬 so that's why it's pretty important 😅

Full error on Chromium 38:

Full error on Chromium 38

The result for us is that the Next.js error page is appended at the end of the current page when the page is crawled by Googlebot

Googlebot error

And as a direct result, that's what happened:

Result on ranking

Google fixed the title with time, but you can still reproduce what Googlebot sees by navigating to our website on Chromium 38 or other old browsers.

I was able to fix in on my local environment by replacing Object.assign(newProps, _this2.findAndGetUrls(nameOrUrl, params).urls); (line 175) in node_modules/next-routes/dist/index.js by

if (!Object.assign) {
      Object.defineProperty(Object, 'assign', {
          enumerable: false,
          configurable: true,
          writable: true,
          value: function(target) {
              'use strict';
              if (target === undefined || target === null) {
                  throw new TypeError('Cannot convert first argument to object');
              }
  
              var to = Object(target);
              for (var i = 1; i < arguments.length; i++) {
                  var nextSource = arguments[i];
                  if (nextSource === undefined || nextSource === null) {
                      continue;
                  }
                  nextSource = Object(nextSource);
  
                  var keysArray = Object.keys(Object(nextSource));
                  for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
                      var nextKey = keysArray[nextIndex];
                      var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
                      if (desc !== undefined && desc.enumerable) {
                          to[nextKey] = nextSource[nextKey];
                      }
                  }
              }
              return to;
          }
      });
  } else {
      Object.assign(newProps, _this2.findAndGetUrls(nameOrUrl, params).urls);
  }

The great news is that to fix this, it looks like you just need to merge #143 😁

Thanks!!

adriendomoison avatar Jul 05 '18 08:07 adriendomoison

I just run into the same problem, upgraded my site a few weeks ago and by chance I noticed that Googlebot wasn't properly rendering my site. It wasn't a catastrophe because most of the content is rendered server site, but some very important parts of the page is rendered on the client, so yeah, it was pretty bad. I fixed it by installing @babel/polyfill and importing it into my _app.js. I'm surprised to see this issue here since Jul with no responses. This repo hasn't been updated in months.

barros001 avatar Sep 30 '18 23:09 barros001

Same problem here. I'm gonna keep a local fork on our project.

oliviertassinari avatar Oct 04 '18 10:10 oliviertassinari

You can add a polyfill for Object.assign to your project if you need it. Would that solve the problem?

typeofweb avatar Oct 04 '18 23:10 typeofweb

@mmiszy Most people already have the Babel ponyfill, an extra polyfill is code duplication in people bundles.

oliviertassinari avatar Oct 05 '18 07:10 oliviertassinari

@oliviertassinari I'm suggesting you should import the polyfill for Object.assign from Babel (from core-js) if you need it. import 'core-js/features/object/assign' should do I guess?

typeofweb avatar Oct 05 '18 09:10 typeofweb