Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard/check missing in areHooksInputEqual()? #82

Open
tomkelsey opened this issue Jul 26, 2022 · 0 comments
Open

Guard/check missing in areHooksInputEqual()? #82

tomkelsey opened this issue Jul 26, 2022 · 0 comments

Comments

@tomkelsey
Copy link

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<mixed>,
  prevDeps: Array<mixed> | 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant