solid icon indicating copy to clipboard operation
solid copied to clipboard

Solid reads `0` from `undefined` in the `<Switch>` component

Open victor-wm opened this issue 3 years ago • 2 comments

Describe the bug

When using a resource that errors in the when condition of a Match within Switch, Solid will try to write undefined to the memo result. But that fails because the equals function defined in https://github.com/solidjs/solid/blob/main/packages/solid/src/render/flow.ts#L144 tries to access a[0] === b[0] with b being undefined which fails with

TypeError: Cannot read properties of undefined (reading '0')
    at Object.equals [as comparator] (esm.sh/v110/[email protected]/es2022/solid-js.development.js:1582:38)
    at writeSignal (esm.sh/v110/[email protected]/es2022/solid-js.development.js:703:33)

Your Example Website or App

https://playground.solidjs.com/anonymous/8c7b2f6b-310b-4449-8d07-9b5d200798ec

Steps to Reproduce the Bug or Issue

See playground -

There you can edit the code to have the onError commented out to have different behavior:

  • With onError and when={resource()} -- only TypeError is seen
  • With onError and when={throws()} -- Thrown error shows twice, TypeError shows once
  • Without onError and when={resource()} -- Only resource error is seen
  • Without onError and when={throws} -- Only Thrown error is seen

Expected behavior

Expected to see it not throwing due to a Solid implementation bug

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 1.6.11

Additional context

No response

victor-wm avatar Mar 03 '23 22:03 victor-wm

On 1.6.9 this causes Solids reactivity to go stale and not update at all.

victor-wm avatar Mar 03 '23 22:03 victor-wm

Also fixed by https://github.com/solidjs/solid/commit/b8a3ff131e46bb57837062933dc0e1df63feb054

ryansolid avatar Mar 06 '23 09:03 ryansolid