[RENDERER]: clean up the renderer ahead of the part model rework

Aperta
#187 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@eddyloewen ci sta già lavorando.

Dal 28/10/2026.

  • #188 di @eddyloewen — aperta

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
frontend

Direzione di ricerca

Start with the named files in src/dom-parts/ and src/util/, especially ChildNodePart.js, TemplatePart.js, and TemplateResult.js; the issue also points to #184 and #185. Run the existing tests first, then benchmark with npm run bench:compare against main. Done means the tests pass, the listed cleanup and fixes are complete, clear rows is at least as fast as create rows, no other benchmark regresses, and changelog entries are added under Unreleased.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

Goal

Remove what is dead, fix what is quadratic and tighten the error handling in src/dom-parts/ and src/util/, without touching the marker format or the part semantics. Everything that #184 rewrites anyway stays as it is, so nothing here is done twice.

Tasks

Dead code

  • src/util/DOMHelper.js: diffNodes, diffAttributes, hasChildNodes, getNodePath and decodeHTML have no callers left, they are the renderer from before the dom-parts. Remove them.
  • src/util/DOMHelper.js: isOfSameNodeType() checks !nodeA && !nodeA.localName, which throws for null instead of returning false. Should be ||.
  • src/dom-parts/directives.js: the imports decodeAttribute and convertStringToTemplate are unused.

Performance

  • clear rows is slower than create rows, 19.4 ms against 8.1 ms for 1000 rows in the last local benchmark run. getNodesBetweenComments() in ChildNodePart.js walks backwards and builds its list with unshift, which is quadratic, then removes node by node. Walk forward, or delete with a Range from the start to the end marker. TemplatePart.refreshChildNodes() calls the same function after every update when a part sits at the template root.
  • ChildNodePart.arrayParts never shrinks. A list that once had 10,000 items and now has 10 keeps 9,990 template parts and their detached DOM. Trim to the array length.
  • unsafeHTML() parses with DOMParser on every call and returns fresh nodes. The diff keeps the rendered nodes because isEqualNode matches, but the parse and the deep compare are paid on every render even when the string did not change. Compare the string in the part before resolving the value.
  • processNodePart() creates the reserve text node for every child node part up front, also for parts that only ever render templates. Create it on first use.
  • TemplateResult.renderInto() runs Array.from(childNodes).find() for the template-part marker on every render. Only needed when there is no cached part for the node yet.

Errors

  • throw { name: 'ParseTemplateError', … } in TemplateResult.js throws plain objects: no stack, no instanceof. One Error subclass.
  • getValue() logs an unknown object with console.log and writes [object Object] into the SSR output. Warn with a message that says what to pass instead. The client renders such an object as text as well, both paths change together in #184.
  • render() with a string goes through innerHTML and leaves the cached TemplatePart of the node in place. A template() that switches between a string and a TemplateResult renders against stale state. renderInto() checks that the markers of the cached instance are still in the node.

Bug

  • #185, with the two tests.

Not in here

Comment walker consolidation, the multi-interpolation counters, the constructor cache in AttributePart and RawTextNodePart, the six WeakMaps: all of it is replaced by #184.

Done when

  • tests pass
  • npm run bench:compare against main: clear rows is at least as fast as create rows, nothing else slower
  • changelog entries under Unreleased
Lingua principale
JavaScript
Stelle
30
Fork
5
Merge medio
1h 57m
PR unite (30g)
10

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di webtides/element-js

Tutte le issue di webtides/element-js

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.