Lowered `<Show>` (`lowerShow`, the production default) shows a different screen than the `<Show>` component while a write is held
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript, typescript
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 37k
- Forks
- 1.2k
- Merge medio
- 8 h 43 min
- PR fusionados (30 d)
- 365
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una 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 solidjs/solid
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
Los mantenedores suelen responder en 1 día
-
[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 handlesPosiblemente ocupada @MilindChatrabhuji la tomó hace 2 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
Los mantenedores suelen responder en 1 día
Todos los issues de solidjs/solid
Issues similares
-
agentscan:mixed-signals pending triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
vueuse/vueuse#5737 · 2 comentarios ·
Los mantenedores suelen responder en 9 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Marker-Inc-Korea/AutoRAG#2288 ·
Los mantenedores suelen responder en 1 día
-
Resources: New templates of Guangzhou Metro Line 13Posiblemente ocupada @rmt-svc la tomó hoy. Abiertoresources
Dificultad 1/5 Menos de una hora Aptitud para principiantes 76/100
railmapgen/rmg-templates#2730 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
web
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día