Common mistakes
Common mistakes in the Control flow in depth guide.
- Destructuring the Show callback argument.
{({ name }) => ...}reads once; the argument is an accessor. Call it:current().name. - Reading a
Showaccessor after the branch ended, for example in a timer callback. It throws the stale accessor error. Capture the plain value first. - Using
Show when={list.length}to hide an empty list and then wondering about0. It works because0is falsy; the same holds for"". Usewhen={list.length > 0}when you want it explicit. - Index versus For for objects.
Indexkeeps rows by position, so reordering a list of objects rewrites every row'sitem()instead of moving nodes. UseFor. - Keying with the array index. Use a stable id, see Lists and keys.
- Expecting
Portalto render in place on the server. It renders nothing in place there. Its content goes to the render's portal collector, and the document emits it at the end ofbody(see the SSR guide, "Portals on the server").