vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.44k stars 27.04k forks source link

`performance` error #36059

Closed himberjack closed 2 years ago

himberjack commented 2 years ago

Provide environment information

next 12.1.4 react 17.0.2 react-dom 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

For some users in production, for various of browsers and OS, we sometimes get the following error.

We saw this code is part of the client: https://github.com/vercel/next.js/blob/39318883783668d96b65391b62197fc0767dd26d/packages/next/client/index.tsx#L586

TypeError: undefined is not an object (evaluating 'performance.getEntriesByName("Next.js-hydration").forEach')
  at te(./node_modules/next/dist/client/index.js:844:47)
  at ? (./node_modules/next/dist/client/page-loader.js:114:9)
  at forEach([native code])
  at ? (chunks/main-f290bc8384acaedd.js:110:23)
  at Yi(./node_modules/react-dom/cjs/react-dom.production.min.js:219:278)
  at Ri(./node_modules/react-dom/cjs/react-dom.production.min.js:259:285)
  at Ri([native code])
  at Pf(./node_modules/scheduler/index.js:4:3)
  at gg(./node_modules/react-dom/cjs/react-dom.production.min.js:122:422)
  at Uj(./node_modules/react-dom/cjs/react-dom.production.min.js:253:69)
  at Lj(./node_modules/react-dom/cjs/react-dom.production.min.js:244:190)
  at bi([native code])
  at ? (./node_modules/react-dom/cjs/react-dom.production.min.js:123:206)
  at Pf(./node_modules/scheduler/index.js:4:3)
  at gg(./node_modules/react-dom/cjs/react-dom.production.min.js:122:422)
  at jg(./node_modules/react-dom/cjs/react-dom.production.min.js:123:157)
  at ig(./node_modules/react-dom/cjs/react-dom.production.min.js:123:94)
  at Jg(./node_modules/react-dom/cjs/react-dom.production.min.js:237:299)
  at documentElement(./node_modules/react-dom/cjs/react-dom.production.min.js:285:192)
  at tk(./node_modules/react-dom/cjs/react-dom.production.min.js:288:43)
  at hydrate(./node_modules/react-dom/cjs/react-dom.production.min.js:296:84)
  at ? (./node_modules/next/dist/client/page-loader.js:94:46)
  at noscript(chunks/main-f290bc8384acaedd.js:94:71)
  at ? (./node_modules/next/dist/client/index.js:783:44)
  at _unsupportedIterableToArray(chunks/pages/_app-9282cbc679e8547d.js:8:3)

We are not sure how to disable this performance module completely.

Expected Behavior

Doesn't need to crash

To Reproduce

N/A

ijjk commented 2 years ago

Hi, can you share any additional info, are you leveraging swcMinify, do you have any custom config? A repo and exact browser where you are seeing this would help debug also. Before any performance calls we check that it is defined as can be seen here: https://github.com/vercel/next.js/blob/39318883783668d96b65391b62197fc0767dd26d/packages/next/shared/lib/utils.ts#L385-L389

himberjack commented 2 years ago

Hi, I don't have steps unfortunately, it seems to happen sporadically. How can we disable the performance monitor completely?

balazsorban44 commented 2 years ago

Currently, it's not possible to turn off performance monitoring.

A likely scenario is that some of your users are on unsupported/older versions of browsers.

Could that be the case?:

https://developer.mozilla.org/en-US/docs/Web/API/Performance#browser_compatibility

UPDATE: From my findings, even Opera supports performance.getEntriesByName now, so the MDN table might be out of date.

himberjack commented 2 years ago

Hi @balazsorban44 It happens on all major browsers:

image

We also noticed that maybe the fact that the user seems to click on the same page (for unknown reason), it happens: image

balazsorban44 commented 2 years ago

Could you maybe share at least your code of the /universal page and your next.config.js as requested in https://github.com/vercel/next.js/issues/36059#issuecomment-1095320001? I would like to investigate this further.

himberjack commented 2 years ago

Sorry, there you go:

const path = require('path');
const withTM = require('next-transpile-modules')(['xxxxxxxxxx/ooooooooo-sdk']);
const { PHASE_PRODUCTION_SERVER, PHASE_DEVELOPMENT_SERVER } = require('next/constants');
const { init } = require('xxxxxxxxxx/yyyyyyy-utils/secrets-manager');
const { i18n } = require('./next-i18next.config');
const { withSentryConfig } = require('@sentry/nextjs');

const sentryWebpackPluginOptions = {
  silent: true
};

/** @type {import('next').NextConfig} */
const nextConfig = {
  async rewrites() {
    return [
      {
        source: '/robots.txt',
        destination: '/api/robots'
      },
      {
        source: '/ads.txt',
        destination: '/api/adstxt'
      },
      {
        source: '/:lang*/sitemap.xml',
        destination: '/api/sitemap'
      },
      {
        source: '/sitemap/:lang',
        destination: '/api/sitemap'
      },
      { source: '/pb_config_(.*)', destination: '/api/pb_config' },
      { source: '/user-config', destination: 'https://old.example.com/user-config' },
      {
        source: '/src/:path*',
        destination: 'https://old.example.com/src/:path*'
      },
      {
        source: '/dist/:path*',
        destination: 'https://old.example.com/dist/:path*'
      },
      {
        source: '/api/v1/:path*',
        destination: 'https://old.example.com/api/v1/:path*'
      },
      { source: '/:category/:slug/:slide', destination: '/:category/:slug?slide=:slide' },
      { source: '/aboutus', destination: '/static/aboutus' },
      { source: '/dmca', destination: '/static/dmca' },
      { source: '/privacy', destination: '/static/privacy' },
      { source: '/tos', destination: '/static/tos' }
    ];
  },
  poweredByHeader: false,
  reactStrictMode: true,
  i18n: {
    locales: ['en', 'de', 'es', 'fr', 'it', 'pt', 'ja'],
    defaultLocale: 'en'
  },
  images: {
    domains: ['xxxxxxxxx']
  },
  webpack: (config, options) => {
    config.module.rules.push(
      // this separate rule is required to make sure that the Prebid.js files are babel-ified.  this rule will
      // override the regular exclusion from above (for being inside node_modules).
      {
        test: /.js$/,
        include: new RegExp(`\\${path.sep}prebid\\.js`),
        use: {
          loader: 'babel-loader',
          // presets and plugins for Prebid.js must be manually specified separate from your other babel rule.
          // this can be accomplished by requiring prebid's .babelrc.js file (requires Babel 7 and Node v8.9.0+)
          // as of Prebid 6, babelrc.js only targets modern browsers. One can change the targets and build for
          // older browsers if they prefer, but integration tests on ie11 were removed in Prebid.js 6.0
          options: require('prebid.js/.babelrc.js')
        }
      }
    );
    return config;
  }
};

const withBundleAnalyzer =
  process.env.NODE_ENV === 'development'
    ? require('@next/bundle-analyzer')({
        enabled: process.env.ANALYZE === 'true'
      })
    : null;

const decoratedNextConfig = withSentryConfig(withTM(nextConfig), sentryWebpackPluginOptions);

module.exports = async (phase, { defaultConfig }) => {
  if ([PHASE_PRODUCTION_SERVER, PHASE_DEVELOPMENT_SERVER].includes(phase)) await init();

  if (withBundleAnalyzer) return withBundleAnalyzer(decoratedNextConfig);
  else return decoratedNextConfig;
};

Since this is a production env, I can only share the URL: www.discoverytime.com/universal

himberjack commented 2 years ago

And it happens on more links, not only /universal obviously

github-actions[bot] commented 2 years ago

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.