Skip to content

Commit

Permalink
Fix startTime error on Android 9 with Chrome 74 (#67391)
Browse files Browse the repository at this point in the history
### 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: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
raeyoung-kim and ijjk authored Sep 16, 2024
1 parent aa66ee4 commit d2a17d9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/next/src/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,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', {
Expand Down

0 comments on commit d2a17d9

Please sign in to comment.