A document or window listener sits inside a list row
The message
MARKLESS_GLOBAL_EVENT_IN_ROW: <attributeName> sits inside an @for row, so every row listens on the <target> and one event runs the handler once for each row on the page.
A <target> listener belongs to the element it is written on. Each row is its own element, so each row adds its own listener.
Move <attributeName> to an element outside the @for, and find the row the event is about inside the handler.
https://markless.dev/errors/MARKLESS_GLOBAL_EVENT_IN_ROWWords in angle brackets change from case to case.
Why
A document or window listener belongs to the element it is written on, and each row is its own element. With a hundred rows, one key press runs the handler a hundred times. The page still builds; this is a warning because it is rarely what you meant.
Fix
Move the prop to an element outside the @for, and work out inside the handler which row the event is about, for example from event.target or from state that names the selected row.
Before
import { state } from '@markless/core';export function Files() @{ let rows = state([{ id: 'a', name: 'notes.txt' }]); <ul> @for (const row of rows; key row.id) { <li onDocumentKeyDown={(event) => { if (event.key === 'Delete') rows = rows.filter((other) => other.id !== row.id); }} > {row.name} </li> } </ul>}After
<ul onDocumentKeyDown={(event) => event.key === 'Delete' && remove(selected)}> @for (const row of rows; key row.id) { <li onClick={() => (selected = row.id)}>{row.name}</li> }</ul>Related
Where Markless raises it
Button sounds are from Josh Comeau's Button Sounds library.