observing of props in useEffect is inconsistent with component rendering

Aperta
#1,908 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
javascript, typescript
Ambito
frontend

Direzione di ricerca

Inizia eseguendo la riproduzione fornita di Test e Root e confronta le props lette nel template con quelle lette all'interno di useEffect. Traccia l'interazione tra props, signal, proxy e rendering; il lavoro è completo quando l'incoerenza è stata risolta oppure il comportamento supportato di reactive-props è stato stabilito chiaramente e coperto da un test di regressione.

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

Descrizione

The following example prints 1 then 2 in the console, but never 3.
The template does render 1 then 2 then 3 however.

We expect all read of this.props.o.val to be reactive in the same way, but it is not the case.

I understand the canonical way to proceed here would be to pass the signal as props instead of its return value.
But the example is still valid, and the inconsistency of props in terms of effect and rendering is highly problematic.

Because of this, onWillUpdateProps cannot be simply converted to equivalent useEffect, because callers need to provide a signal.

import { Component, mount, xml, props, types, useEffect, proxy, signal } from "@odoo/owl";

class Test extends Component {
    static template = xml`<span t-out="this.props.o.val"/>`;
    props = props(["o"]);
    setup() {
        useEffect(() => console.log(this.props.o.val));
    }
}

class Root extends Component {
    static template = xml`<div>Hello Owl!<Test o="this.obj()"/></div>`;
    static components = { Test };

    obj = signal(proxy({ val: 1 }));

    setup() {
        setTimeout(() => this.obj().val = 2, 100);
        setTimeout(() => this.obj.set(proxy({ val: 3 })), 200);
    }
}

mount(Root, document.body, { templates: TEMPLATES, dev: true });

Side remark, but I don't understand why props.signal="..." is not the default if the given value is not a signal. It seems extremely confusing and error prone to allow non-reactive values as props, but with just a little bit of magic to still trigger re-rendering. This is even more strange as .alike already exists for case where we would want to disable the auto-wrapping behavior.

Lingua principale
TypeScript
Stelle
1.6k
Fork
435
Merge medio
13h 18m
PR unite (30g)
5

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 odoo/owl

Tutte le issue di odoo/owl

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.