[]previous and next page

Common mistakes

Common mistakes in the Control flow in depth guide.

For agentsUpdated
  • Destructuring the Show callback argument. {({ name }) => ...} reads once; the argument is an accessor. Call it: current().name.
  • Reading a Show accessor 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 about 0. It works because 0 is falsy; the same holds for "". Use when={list.length > 0} when you want it explicit.
  • Index versus For for objects. Index keeps rows by position, so reordering a list of objects rewrites every row's item() instead of moving nodes. Use For.
  • Keying with the array index. Use a stable id, see Lists and keys.
  • Expecting Portal to 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 of body (see the SSR guide, "Portals on the server").