From b0ff3d08f4185623e60a84be8ea0f14f84081f85 Mon Sep 17 00:00:00 2001
From: "raeyoung.kim" <52588326+raeyoung-kim@users.noreply.github.com>
Date: Tue, 17 Sep 2024 06:11:00 +0900
Subject: [PATCH] Fix startTime error on Android 9 with Chrome 74 (#67391)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
### What?
Fixes the error `Cannot read property 'startTime' of null` on Chrome 74
for Android 9 by ensuring the `beforeHydrationMeasure` and
`hydrationMeasure` are not falsy values before accessing their
properties.
### Why?
The application crashes on Chrome 74 for Android 9 due to `null` or
other falsy values being returned in certain situations. This fix
ensures that the `startTime` property is only accessed if it is not a
falsy value, thereby preventing the crash.
### How?
Added a falsy check before accessing the `startTime` property in the
performance measurement logic. Specifically, modified the code at [this
location](https://github.com/vercel/next.js/blob/b9bd23baec14508400c502b3651f4cf2497e883b/packages/next/src/client/index.tsx#L498)
Co-authored-by: JJ Kasper
---
packages/next/src/client/index.tsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/packages/next/src/client/index.tsx b/packages/next/src/client/index.tsx
index dc5ba991c6450..f830642717c2f 100644
--- a/packages/next/src/client/index.tsx
+++ b/packages/next/src/client/index.tsx
@@ -496,8 +496,8 @@ function markHydrateComplete(): void {
if (
process.env.NODE_ENV === 'development' &&
// Old versions of Safari don't return `PerformanceMeasure`s from `performance.measure()`
- beforeHydrationMeasure !== undefined &&
- hydrationMeasure !== undefined
+ beforeHydrationMeasure &&
+ hydrationMeasure
) {
tracer
.startSpan('navigation-to-hydration', {