Lowered `<Show>` (`lowerShow`, the production default) shows a different screen than the `<Show>` component while a write is held
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, typescript
Direzione di ricerca
Start by reading the lower_show.rs lowering mentioned in the issue and the behavior added in #4730, then compare the generated ternary with the Show component under the supplied universal renderer repro. Trace how both forms interact with Loading, latest, and a pending read; the linked pull request #5099 is already open. Done means both lowerShow settings produce the expected screens in both repro cases, with the branch held until its read resolves.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
The same component renders a different screen depending on whether @solidjs/compiler lowers <Show> to a ternary (lowerShow: true, the default when dev is off, added in #4730) or keeps the component (lowerShow: false, the dev default). The difference shows up while a write is held by a pending async read under <Loading>, and it goes in both directions:
- With a plain
<Show when={s() > 0}>and a display-ahead<Show when={latest(() => s()) > 0}>side by side, the lowered build leaves alatest(() => s())text at the old value. The component build shows the new value. - With only the display-ahead
<Show>, the component build attaches the branch with its hole empty. The lowered build keeps the fallback.
So a production build and a dev build of the same app show different screens for the same steps, and neither one gives the screen SCENARIOS.md S-46 rules on in both cases.
Found at: solid-js 2.0.3, @solidjs/signals 2.0.3, @solidjs/universal 2.0.3, @solidjs/compiler 2.0.2 (the published latest), and next c74567ab1. It shows the same way under the development and the production export conditions. I did not bisect it, and I only ran it on the universal renderer, not @solidjs/web with a DOM.
How it was found: running a ReactiveScript program's Solid view (plain createSignal/createMemo/<Show>/<Loading> code, compiled by @solidjs/compiler) against the program's own compiled output, on the same renderer and the same steps. Across 800 generated programs and 3,168 runs, 20 programs showed a different screen. All 20 matched again when the view was compiled with lowerShow: false. The repro below is the reduced shape, rebuilt in plain Solid.
Repro
Save as repro.mjs in a folder with solid-js, @solidjs/compiler and @solidjs/universal installed, then run node --conditions=browser --conditions=development repro.mjs. It compiles one component twice, with lowerShow off and on, and runs both on the same runtime. a asks a request that never answers, so setS(2), which would show a, is held.
import { transform } from "@solidjs/compiler";
import { writeFileSync } from "node:fs";
import { fileURLToPath, pathToFileURL } from "node:url";
import { flush } from "solid-js";
// A minimal string-tree renderer, as a module the compiled JSX imports.
const renderer = fileURLToPath(new URL("./renderer.mjs", import.meta.url));
writeFileSync(renderer, `import { createRenderer } from "@solidjs/universal";
export { Show, Loading, Errored } from "solid-js";
const R = createRenderer({
createElement: (tag) => ({ tag, children: [] }),
createTextNode: (text) => ({ text }),
replaceText: (n, v) => { n.text = v; },
isTextNode: (n) => "text" in n,
setProperty() {},
getParentNode: (n) => n.parent,
getFirstChild: (n) => n.children?.[0],
getNextSibling: (n) => n.parent && n.parent.children[n.parent.children.indexOf(n) + 1],
insertNode(p, n, anchor) {
if (n.parent) n.parent.children.splice(n.parent.children.indexOf(n), 1);
const i = anchor ? p.children.indexOf(anchor) : -1;
i < 0 ? p.children.push(n) : p.children.splice(i, 0, n);
n.parent = p;
},
removeNode(p, n) { p.children.splice(p.children.indexOf(n), 1); n.parent = undefined; },
});
export const { render, effect, memo, createComponent, createElement, createTextNode, insertNode, insert, spread, setProp, mergeProps } = R;
export const text = (n) => ("text" in n ? String(n.text) : n.children.map(text).join(""));
`);
const app = (plain, gate) => `
import { createSignal, createMemo, latest, Loading, Errored, Show } from "solid-js";
import { render, text } from ${JSON.stringify(renderer)};
export function run() {
const pending = () => new Promise(() => {});
const root = { tag: "root", children: [] };
let setS;
function App() {
const [s, set] = createSignal(1);
setS = set;
const a = createMemo(() => pending(s()));
return (
<Errored fallback={<p>error</p>}>
<Loading fallback={<p>loading</p>}>
{<>
${plain ? `<Show when={s() > 0} fallback={<p>[plain off] </p>}><p>[plain on {a()}] </p></Show>` : ""}
<p>[latest {latest(() => s())}] </p>
${gate ? `<Show when={latest(() => s()) > 0} fallback={<p>[gate off]</p>}><p>[gate on {a()}]</p></Show>` : ""}
</>}
</Loading>
</Errored>
);
}
render(() => <App />, root);
return { screen: () => text(root), setS };
}`;
const settle = async () => { for (let i = 0; i < 3; i++) { await new Promise((r) => setTimeout(r, 0)); flush(); } };
for (const [name, plain, gate] of [["both", true, true], ["gate only", false, true]]) {
for (const lowerShow of [false, true]) {
const code = transform(app(plain, gate), { filename: "app.jsx", generate: "universal", moduleName: renderer, lowerShow }).code;
const file = fileURLToPath(new URL(`./app-${name.replace(" ", "-")}-${lowerShow}.mjs`, import.meta.url));
writeFileSync(file, code);
const a = (await import(pathToFileURL(file).href)).run();
await settle();
a.setS(0); await settle();
const before = a.screen();
a.setS(2); await settle();
console.log(`${name.padEnd(9)} lowerShow: ${String(lowerShow).padEnd(5)} after setS(0): ${JSON.stringify(before).padEnd(36)} after setS(2): ${JSON.stringify(a.screen())}`);
}
}
Observed
both lowerShow: false after setS(0): "[plain off] [latest 0] [gate off]" after setS(2): "[plain off] [latest 2] [gate off]"
both lowerShow: true after setS(0): "[plain off] [latest 0] [gate off]" after setS(2): "[plain off] [latest 0] [gate off]"
gate only lowerShow: false after setS(0): "[latest 0] [gate off]" after setS(2): "[latest 2] [gate on ]"
gate only lowerShow: true after setS(0): "[latest 0] [gate off]" after setS(2): "[latest 2] [gate off]"
Each case gives the same screen when it runs alone in its own process.
Expected
The same screen with lowerShow on and off, and in both cases the screen S-46 case 1 rules on: the display-ahead reader shows the new value, and the branch it opens is born held, so its fallback stays until a lands.
- both:
[plain off] [latest 2] [gate off]. The component build shows this. The lowered build leaves[latest 0], so thelatestreader does not read ahead. - gate only:
[latest 2] [gate off]. The lowered build shows this. The component build shows[gate on ], the branch attached with its hole empty, which S-46 lists as forbidden ("F-2: never an empty slot").
Needed to reproduce
- The plain
<Show when={s() > 0}>and its pending content decide the first case. Without it (the "gate only" case), the lowered build is the one that is right. - The
<Show>s sit in a fragment that is the only child of<Loading>. That is a positionlower_show.rslowers. As siblings directly under<Loading>, neither build lowers them, and both show thelowerShow: falsescreens, including[gate on ]in the "gate only" case. So the empty slot does not need the fragment.
Related
- #4730 added the lowering. Its doc comment describes the ternary as "what
<Show>does for JSX children withoutkeyed". - #4806 (closed) was the display-ahead
<Show>attaching early for text, fragment and function children. The "gate only" component row is the same symptom with an element child under<Loading>, which that issue lists as correct. - #4936 (closed) was a lowered
<Show>re-reading itswhen. It is a different problem.
I have not traced where the two forms part in the runtime.
- Lingua principale
- TypeScript
- Stelle
- 37k
- Fork
- 1.2k
- Merge medio
- 8h 43m
- PR unite (30g)
- 365
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di solidjs/solid
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
I maintainer di solito rispondono entro 1 giorno
-
[2.0.4] Nested `<Errored>`: the outer boundary stays on an error the inner one rethrew, after the next error is one the inner one handlesForse già presa @MilindChatrabhuji l’ha presa 2 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di solidjs/solid
Issue simili
-
agentscan:mixed-signals pending triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
vueuse/vueuse#5737 · 2 commenti ·
I maintainer di solito rispondono entro 9 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Marker-Inc-Korea/AutoRAG#2288 ·
I maintainer di solito rispondono entro 1 giorno
-
Resources: New templates of Guangzhou Metro Line 13Forse già presa @rmt-svc l’ha presa oggi. Apertaresources
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
railmapgen/rmg-templates#2730 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
web
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno