FormidableLabs / FormidableLabs/react-ssr-prepass

Guard/check missing in areHooksInputEqual()?

Open
#82 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
603
Forks
26
PR merge metrics
No merged PRs in 30d

Description

Hi,

I've noticed some server logs with the following error:

```
TypeError: Cannot read properties of undefined (reading 'length')
at areHookInputsEqual (/var/app/current/node_modules/react-ssr-prepass/dist/react-ssr-prepass.js:295:29)
at Object.useMemo (/var/app/current/node_modules/react-ssr-prepass/dist/react-ssr-prepass.js:301:6)
```

Looking at the function, it appears there's no guard/check that prevDeps may be undefined?

```
function areHookInputsEqual(
nextDeps: Array,
prevDeps: Array | null
) {
// NOTE: The warnings that are used in ReactPartialRendererHooks are obsolete
// in a prepass, since these issues will be caught by a subsequent renderer anyway
if (prevDeps === null) return false

for (let i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
if (!is(nextDeps[i], prevDeps[i])) return false
}

return true
}
```

I just wanted to highlight it as a potential issue. I'm not sure if it's implementation problem my end that's causing `prevDeps` to be undefined (rather than null)?

But just in case - in normal use - `prevDeps` can be undefined perhaps there should be a guard/check in place to protect against this? Could the check just be `if (!prevDeps) return false` instead?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.