Skip to content

Commit 8931dc9

Browse files
authored
Merge pull request #388 from knockout/claude/ecstatic-einstein-TV40A
docs(agents): add ko-* static-expression freeze gotcha to guide.md
2 parents a25d564 + 0395977 commit 8931dc9

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

tko.io/public/agents/guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ tko.applyBindings({ removeTodo: t => todos.remove(t) }, root)
294294
- **`dispose()` on computed/subscriptions** stops updates. After disposal, reading returns last cached value.
295295
- **HTML-producing computeds** should return `null` for empty output, not `false` or an empty fragment — bindings and JSX observers handle `null` cleanly.
296296
- **Binary HTML attributes** (`disabled`, `readonly`, `hidden`, `required`, `checked`, `selected`) omit the attribute when the value is `null`, `undefined`, or `false`. Use `|| undefined` in computeds to make "no attribute" explicit: `disabled={this.computed(() => shouldBeDisabled() || undefined)}`. Never return the string `"false"` — it keeps the attribute set.
297+
- **Pass the observable itself to `ko-*` attrs — not a called expression.** `ko-text={obs()}` calls `obs()` once at render time and gives TKO a static value; the DOM never updates after the initial render. Write `ko-text={obs}` (pass the observable). For derived expressions, hoist to a `ko.pureComputed`: `const label = ko.pureComputed(() => a() + b())`, then `ko-text={label}`.
297298
- **Prefer named computed variables over inline computeds in JSX.** A computed created inline in JSX is easier to accidentally recreate on each render than one bound to a class field or `const`.
298299

299300
## Testing

0 commit comments

Comments
 (0)