Commit b0ff3d08 authored by raeyoung.kim's avatar raeyoung.kim Committed by JJ Kasper

Fix startTime error on Android 9 with Chrome 74 (#67391)

### 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.

<img width="1164" alt="Screenshot 2024-07-02 at 11 14 53 PM"
src="https://github.com/vercel/next.js/assets/52588326/34df95b6-a4fe-4886-96b8-a3c873a2ae6a">

### 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: 's avatarJJ Kasper <jj@jjsweb.site>
parent 49566f5a
......@@ -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', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment