Lowered `<Show>` (`lowerShow`, the production default) shows a different screen than the `<Show>` component while a write is held
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- javascript, typescript
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- TypeScript
- 星标
- 37k
- 派生
- 1.2k
- 平均合并
- 8 小时 43 分钟
- 30 天内合并 PR
- 365
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
solidjs/solid 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 38/100
维护者通常 1 天内回复
-
[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 handles可能已有人在做 @MilindChatrabhuji 于 2 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 25/100
维护者通常 1 天内回复
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 69/100
activepieces/activepieces#17974 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
OHDSI/Data2Evidence#3777 ·
维护者通常 3 天内回复
-
bug enhancement
难度 1/5 1 小时以内 新手友好度 90/100
AOSSIE-Org/PictoPy#1802 · 2 条评论 ·
维护者通常 3 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
Termix-SSH/Plugin-Snippets#26 · 1 条评论 ·
维护者通常 1 天内回复
-
agent-reported bug from-app needs-triage
难度 2/5 1-3 小时 新手友好度 72/100
nightly-labs/openbot#20504 ·
维护者通常 1 天内回复