[UPDATES]: one update cycle for elements and stores, hooks and watchers run once per batch
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript
- Área
- frontend
Línea de trabajo
Start with requestUpdate() and Store.requestUpdate(), then inspect test/unit/updates.test.js and the related store tests to map current scheduling and watcher behavior. The design calls for one shared microtask cycle across elements and stores, covering connection handling, observers, and server rendering. Done means the listed update and store behaviors pass, the element-js-ssr-renderer suite stays green, and docs/features/watch.md and docs/features/store.md describe the cycle and hook arguments.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Goal
A property set schedules one update cycle. Any number of sets on an element or a store in the same tick end in one render, one beforeUpdate, one afterUpdate and one watcher call per changed property. Elements and stores share the cycle: a store notifies each observer once per tick, and a property that a watcher derives from another one lands in the same render.
Context
requestUpdate()triggersbeforeUpdateon every call and reschedules therequestAnimationFrame. Two property sets call the hook twice for one render. The batching test intest/unit/updates.test.jsis commented out because of this.- Watchers run in the
.finally()of each request's promise, after the render. A property that a watcher sets renders one frame later. Setting the same property three times in a tick calls its watcher three times, with the intermediate values. - The frame callback uses the options of the last request. A
requestUpdate({ notify: false })after a notifying request silences the hooks of the whole batch. disconnectedCallback()cancels the frame and drops the pending resolvers. An awaitedrequestUpdate()on an element that leaves the DOM never settles.Store.requestUpdate()has no batching. Every set notifies every observer, callsobserver.watch()twice, passes(store, store)as new and old value (#108) and dispatches one-changedevent per set (#91). Store watchers run synchronously before the update, element watchers after it.requestAnimationFramepauses in background tabs, an awaited update hangs there.
Design
One scheduler for BaseElement and Store, microtask based:
// in the property setter
this._changedProperties ??= new Map();
if (!this._changedProperties.has(property)) this._changedProperties.set(property, oldValue);
this._state[property] = newValue;
this._updatePromise ??= Promise.resolve().then(() => this.performUpdate());
performUpdate() {
const changed = this._changedProperties;
this.beforeUpdate(changed);
for (const [property, oldValue] of changed) this.watch()[property]?.(this[property], oldValue);
this.update();
this.afterUpdate(changed);
// notify events, resolve updateComplete
}
changedPropertiesis aMap<property, oldValue>. The first old value of a tick wins, the last new value is on the instance.beforeUpdateandafterUpdatereceive the map as an optional argument,watch()keeps its(newValue, oldValue)signature.- The first set of a tick queues
performUpdate()as a microtask.requestUpdate()queues the same cycle with no changed property and returnsupdateComplete, so the current API keeps working. - Watchers run before the render, once per changed property. A set made in
beforeUpdateor in a watcher joins the running cycle, its watcher runs in the same loop, and the render sees the derived value. A set made inafterUpdatestarts a new cycle. updateCompleteresolves after the cycle.disconnectedCallback()lets a pending cycle settle, nothing dangles.- The first cycle after connect runs
connected()andafterUpdate()withoutbeforeUpdate, as it does today. Thenotifyoption goes away in favor of this first-cycle rule. performUpdate()returns early for an element that is not connected and keeps the changed properties, the connect runs the cycle. This also covers the server: the dom-shim ofelement-js-ssr-renderernever connects an element, so property sets during a server render schedule nothing, as the no-oprequestAnimationFramedoes today.Storeruns the same scheduler. A set marks the key as changed and queues one microtask.performUpdate()runs the store's own watchers once per key, then notifies each observer once: an element getsrequestUpdate()and its watcher for the store property receives(store, previousState), withpreviousStatea plain object of the state before the tick. A function observer receives the changed map. A parent store marks the nested store's key as changed and joins the same tick. Replacing a nested store unsubscribes the old one.- Changes to timing and watcher order go into the changelog. The docs promise "next frame", they describe the microtask cycle instead.
Store lifecycle (#111) stays separate, it sits on subscribe and unsubscribe and does not touch the cycle.
Done when
- the three commented out tests in
test/unit/updates.test.jsare enabled and pass: the asynchronous update, one render with onebeforeUpdateand oneafterUpdatefor several sets, a property derived in a watcher rendered in the same cycle - a watcher runs once per changed property per cycle, with the first old and the last new value of the tick
- three sets on a store in one tick notify each observer once, element watchers for store properties receive the previous state, closes #91 and #108
await el.requestUpdate()resolves in a background tab and on an element that was disconnected in the meantime- the test suite of
element-js-ssr-rendererstays green on the dom-shim, no cycle runs on the server docs/features/watch.mdanddocs/features/store.mddescribe the cycle and the hook arguments
- Lenguaje dominante
- JavaScript
- Estrellas
- 30
- Forks
- 5
- Merge medio
- 1 h 57 min
- PR fusionados (30 d)
- 10
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de webtides/element-js
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
webtides/element-js#201 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
webtides/element-js#198 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
webtides/element-js#194 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
webtides/element-js#193 ·
Los mantenedores suelen responder en 1 día
-
[RENDERER]: only the first raw text element with interpolations is handled, a line break inside one breaks it tooPosiblemente ocupada @eddyloewen la tomó hace 28 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
webtides/element-js#185 ·
Los mantenedores suelen responder en 1 día
Todos los issues de webtides/element-js
Issues similares
-
area:testing bug effort:low model:light plan planner:gpt-6-2-sol tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
enhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
Agent360dk/browser-mcp#124 ·
Los mantenedores suelen responder en 2 días
-
area:site feature good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
pacocartones/free-llm-api-hub#829 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
Jason-Vaughan/TangleClaw#3270 ·
Los mantenedores suelen responder en 1 día