Describe the bug
Imagine you have a select element and its option elements in different Preact components, both subscribed to the same signal (or reading from the same context).
const Options = () =>
items.value.map((item) => (
<option key={item.id} value={item.id}>
{item.id}
</option>
));
const Select = ({ children }) => {
const selectedItem = items.value.find((item) => item.selected).id;
return <select value={selectedItem}>{children}</select>;
};
<Select>
<Options />
</Select>
If you try to add a new option and immediately select it, Preact first updates the value attribute of the select element in the DOM before adding the new option, and therefore the change of the value attribute fails.
To Reproduce
Interestingly, the same code in React works fine: https://stackblitz.com/edit/vitejs-vite-m6klnuay
Steps to reproduce the behavior: just click on the button.
Expected behavior
After clicking the button, the select value should be the third, newly added option, but it's not. Actually, it is correct in the virtual DOM, but not in the DOM.
The same code works if you refactor it so that both elements are in a single element.
Describe the bug
Imagine you have a
selectelement and itsoptionelements in different Preact components, both subscribed to the same signal (or reading from the same context).If you try to add a new option and immediately select it, Preact first updates the
valueattribute of theselectelement in the DOM before adding the newoption, and therefore the change of thevalueattribute fails.To Reproduce
Interestingly, the same code in React works fine: https://stackblitz.com/edit/vitejs-vite-m6klnuay
Steps to reproduce the behavior: just click on the button.
Expected behavior
After clicking the button, the select value should be the third, newly added option, but it's not. Actually, it is correct in the virtual DOM, but not in the DOM.
The same code works if you refactor it so that both elements are in a single element.