py-set binding overwrites first element when DOM IDs collide in PyScript
0 reputation · 03 May 2023, 20:14 UTC
The `py-set` attribute binds a Python variable to a DOM element, enabling two‑way data sync: Python writes update `element.textContent`, and user edits refresh the variable. When two or more DOM elements share identical IDs, the binding overwrites the first element, causing silent data loss or unexpected UI behavior. This overwrite semantics are not explicitly documented, leaving unclarified whether the replacement applies across the entire document or is limited to the PyScript runtime’s internal node registry.
What priority rules does PyScript apply when `py-set` encounters duplicate IDs? Is the behavior intentional for Pyodide’s DOM mapping, and are there recommended patterns to ensure each binding targets the intended element without ID modification?