Lowered `<Show>` (`lowerShow`, the production default) shows a different screen than the `<Show>` component while a write is held
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- javascript, typescript
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- TypeScript
- Stars
- 37k
- Forks
- 1.2k
- Avg merge
- 8h 43m
- Merged PRs (30d)
- 365
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from solidjs/solid
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 38/100
Maintainers usually reply within 1 day
-
[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 handlesPossibly taken @MilindChatrabhuji claimed this 2 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Maintainers usually reply within 1 day
Similar issues
-
agentscan:mixed-signals pending triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
vueuse/vueuse#5737 · 2 comments ·
Maintainers usually reply within 9 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Marker-Inc-Korea/AutoRAG#2288 ·
Maintainers usually reply within 1 day
-
Resources: New templates of Guangzhou Metro Line 13Possibly taken @rmt-svc claimed this today. Openresources
Difficulty 1/5 Under an hour Newbie friendliness 76/100
railmapgen/rmg-templates#2730 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
web
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day