Is an object provision meant to couple its fields? A part's write to its own state waits for the app's action when the provision also reads a prop the action holds

オープン
#75 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
32/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
javascript, typescript

調査の方向性

Start with the ReactiveScript compiler’s lowering of provide object literals and the hold behavior described in the issue; the payload does not name compiler files or tests. Reproduce the supplied c.rx sequence and compare the listed provision forms, then check the behavior against ref/ as the report notes it was not tested. Done means deciding whether provision fields should couple and documenting or implementing a consistent behavior for the cases raised.

索引モデルが issue の本文から書いたものです。

説明

Found while building a component library on ReactiveScript. Written with Claude Fable 5.2 (in Claude Code), which also ran the reproductions; all of them were rerun before posting.

@reactivescript/compiler 0.3.1 through @solidjs/vite-plugin 3.0.0-next.57 on a Vite dev server, mounted with
const app = createApp({ root }); app.mount(main(app)) from @reactivescript/runtime 0.3.1, in Chromium, on
solid-js 2.0.0-rc.22 and on 2.0.0. A Playwright script clicks the buttons and reads the text of the <p>
elements.

https://github.com/solidjs/reactivescript/issues/20 was closed with:

When a write should land now, for example clearing an input, the guide covers it under "What lands together, and what waits" in guide/async.md, with onFlush (EF-8).

and asked for "a case where plain Solid and the lowered .rx actually behave differently". This is a case onFlush
does not reach, in a component library whose root part provides its state to the other parts, and the Solid
comparison is at the end.

api.js:

export const wait = (ms, value) => new Promise((resolve) => setTimeout(() => resolve(value), ms));

c.rx:

import { wait } from "./api.js"

context menu: { open: boolean; disabled: boolean }

component Popup() {
  <p>open: {(use menu).open ? "yes" : "no"}</p>
}

component Menu(props: { disabled: boolean }) {
  source open := false
  provide menu = { open: open, disabled: props.disabled }
  <div>
    <button onClick={() => { open := !open }}>toggle</button>
    <Popup />
  </div>
}

export default component App() {
  source step := 1
  action next() {
    step := 2
    try { await wait(300, 0) } catch (e) { }
  }
  <div>
    <button onClick={() => { next() }}>next</button>
    <p>step: {step}</p>
    <Menu disabled={step == 2} />
  </div>
}
step screen
mount step: 1, open: no
click toggle step: 1, open: yes
click toggle step: 1, open: no
click next step: 1, open: no
click toggle step: 1, open: no
100 ms later step: 1, open: no
the wait resolves step: 2, open: yes

The provision is one equation over open and props.disabled, and Popup reads it, so the menu's open := !open
joins the app's hold on step (H-3). Menu and Popup have no await and no action; App does not contain the
provision. In a library they are in different packages. The compiler reports nothing.

Each row is one change to c.rx, then click next, click toggle:

change at the toggle click
In Menu's handler, let o = !open; onFlush(() => { open := o }) open: no until the wait resolves
context menuOpen: boolean and context menuDisabled: boolean, provide menuOpen = open, provide menuDisabled = props.disabled, and Popup reads use menuOpen open: yes
context menu: { open: () => boolean; disabled: () => boolean }, provide menu = { open: () => open, disabled: () => props.disabled }, and Popup reads (use menu).open() open: yes
provide menu = { open: open, disabled: latest props.disabled } open: yes. With <p>disabled: {(use menu).disabled ? "yes" : "no"}</p> added to Popup, that paragraph shows disabled: yes from the click on next, beside step: 1 (this addition ran on rc.22 only)
In App, source step = 1 and guess step := 2 in place of source step := 1 and step := 2 step: 2 at the click on next, then open: yes at the toggle

An app avoids the wait by not holding a plain write, which AC-1c allows on purpose: "A write meant to be held — a
transition […] is written in a declared action".

In Solid a context value is usually an object of getters or accessors, and that shape does not couple. The page
below, on solid-js alone with the same clicks, shows open: no at the toggle click as written (one memo over the
object, which is what provide emits) and open: yes with ?getters in the URL:

<!doctype html> <button>next</button><button>toggle</button>
<p></p>
<p></p>
<script type="module">
  import { createRoot, createSignal, createMemo, createRenderEffect, action } from "solid-js";
  const getters = new URLSearchParams(location.search).has("getters");
  const [next, toggle] = document.querySelectorAll("button");
  const [stepText, openText] = document.querySelectorAll("p");
  createRoot(() => {
    const [step, setStep] = createSignal(1);
    const [open, setOpen] = createSignal(false);
    const disabled = () => step() === 2;
    // the context value: an object of getters, or one memo over the whole object (what `provide` emits)
    const menu = getters
      ? () => ({
          get open() {
            return open();
          },
          get disabled() {
            return disabled();
          },
        })
      : createMemo(() => ({ open: open(), disabled: disabled() }));
    const hold = action(function* () {
      setStep(2);
      yield new Promise((r) => setTimeout(r, 300));
    });
    next.onclick = () => hold();
    toggle.onclick = () => setOpen((o) => !o);
    createRenderEffect(step, (v) => {
      stepText.textContent = "step: " + v;
    });
    createRenderEffect(
      () => menu().open,
      (v) => {
        openText.textContent = "open: " + (v ? "yes" : "no");
      },
    );
  });
</script>

The question: is provide name = { … } meant to couple its fields, so that a write to the source behind one waits
for a hold on another? If yes, which row of the table should a component library use?

If no, one way: an object literal on the right of provide lowers each field to a getter, which is the functions
row written by the compiler. CP-6b says the compiler's facts already record "a read of one field of props or a
store"; that is compile-time knowledge, not an existing lowering. The cost, as far as I can see it:

  • the provision stops being one value (RG-7b: "makes e the context's value"), so a consumer of the whole object
    (an effect (use name), an argument to JS, a spread) needs a rule;
  • each field is evaluated per reader unless it gets its own memo, which adds nodes;
  • the literal form then differs from x = { a: e1, b: e2 } followed by provide name = x, against E-2;
  • which right-hand sides qualify (nested literals, spreads, computed keys, a conditional of two literals) has to
    be decided.

Not tested: any of the .rx programs against ref/.

主要言語
TypeScript
スター
127
フォーク
7
平均マージ
15時間 42分
マージ済み PR(30日)
63

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

solidjs/reactivescript のほかの issue

solidjs/reactivescript の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。