Skip to content

Commit c4885b1

Browse files
committed
Merge remote-tracking branch 'origin/next' into fix/l2-remaining-bugs
2 parents afb074b + c54fb10 commit c4885b1

12 files changed

Lines changed: 677 additions & 84 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"solid-js": patch
3+
---
4+
5+
A server memo re-created at a still-pending slot now takes the slot's answer when the earlier flight settles it (#3815). A retry pass that re-creates a component while its async memo is in flight hands the new memo the slot's shared deferred, but only the earlier memo's promise settles it, so the new memo kept its `NotReadyError` on that already-resolved promise. A memo reading it then retried every microtask, so no timer fired again, the stream never ended and the process sat at 100% CPU. On rc.13 the trigger was a function hole that created a component returning a pending `lazy()` view. On `next` it is an `<Errored>` retry that re-creates a pending `<Loading>`, with a fresh promise per setup and a memo reading it. The joined memo now adopts the slot's value or error when the shared deferred settles, the same way a re-created async-iterable node already did.

‎.github/workflows/size.yml‎

Lines changed: 74 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ name: Size
99
# ships); the retained-module-graph assertions in
1010
# packages/signals/tests/treeshake.test.ts stay the which-module diagnostic
1111
# underneath.
12-
# The check job also runs on direct pushes to next: it is self-contained
13-
# (absolute limits, no base ref), and PR-only triggering let the
14-
# +createStore scenario sit failing at a release commit unnoticed — direct
15-
# pushes never measured. The compare job stays PR-only; it needs a PR
16-
# context (base branch, comment target). The floor-cap freeze step in check
17-
# is PR-only for the same reason (it diffs against the base branch).
12+
#
13+
# Three jobs. `head` measures the commit under test; `base` (PRs only)
14+
# measures the PR's base with the head's harness; `check` — the required
15+
# status — decides with both (scripts/size/gate.mjs): a scenario fails only
16+
# when it is over its brotli cap AND grew past the minified allowance over
17+
# the base. The decision needs the base's minified numbers, so the base
18+
# measurement moved from the old informational `compare` job (which ran after
19+
# `check`) into a job `check` waits on; `head` and `base` run in parallel.
20+
# Pushes to next are gated too, against the commit before the push —
21+
# PR-only triggering let the +createStore scenario sit failing at a release
22+
# commit unnoticed.
1823
on:
1924
push:
2025
branches: [next]
@@ -26,9 +31,7 @@ permissions:
2631
pull-requests: write
2732

2833
jobs:
29-
# The hard gate: self-contained on the PR head, fails when any scenario
30-
# exceeds its limit. Never depends on the base branch.
31-
check:
34+
head:
3235
runs-on: ubuntu-latest
3336
steps:
3437
- uses: actions/checkout@v4
@@ -48,46 +51,33 @@ jobs:
4851
- run: pnpm build
4952
- run: npm ci --no-audit --no-fund
5053
working-directory: scripts/size
51-
# size.mjs gates every scenario against its cap and prints the lazy
52-
# chunks and per-package minified bytes for each, so a bump is
53-
# attributed in the same log that reports it. The JSON feeds the
54-
# compare job's PR comment.
55-
- run: npm run size -- --json size-head.json
54+
# size.mjs prints the lazy chunks and per-package minified bytes for
55+
# each scenario, so a bump is attributed in the same log that reports
56+
# it. --no-gate: the decision is check's. Uploaded on pushes too — a
57+
# push to next's size-head is what `npm run ratchet -- --from` reads.
58+
- run: npm run size -- --json size-head.json --no-gate
5659
working-directory: scripts/size
57-
- if: always() && github.event_name == 'pull_request'
58-
uses: actions/upload-artifact@v4
60+
- uses: actions/upload-artifact@v4
5961
with:
6062
name: size-head
6163
path: scripts/size/size-head.json
62-
# The floor and page caps (scripts/size/floor-caps.json) are frozen: a PR
63-
# may lower them, never raise them, unless its body carries a
64-
# `Size-Exception:` line. Compared against the PR's base branch, so
65-
# PR events only.
66-
- if: github.event_name == 'pull_request'
67-
run: git fetch --no-tags --depth=1 origin "${{ github.base_ref }}"
68-
- if: github.event_name == 'pull_request'
69-
run: npm run check-floor-caps -- "origin/${{ github.base_ref }}"
70-
working-directory: scripts/size
71-
env:
72-
SIZE_EXCEPTION: ${{ github.event.pull_request.body }}
7364

74-
# Best-effort base-vs-head delta comment. Builds the base branch and
75-
# measures its artifacts with the HEAD's harness (SIZE_PACKAGES_ROOT), so
76-
# both columns come from the same scenarios and the same Rolldown; the head
77-
# numbers are the check job's. Informational and never blocks:
78-
# continue-on-error keeps bootstrap PRs (and any hiccup) green. PR events
79-
# only — it needs a base ref and a comment target.
80-
compare:
81-
# always(): the comment is most useful on the PR whose check failed.
82-
if: always() && github.event_name == 'pull_request'
83-
needs: check
65+
# Builds the base and measures its artifacts with the HEAD's harness
66+
# (SIZE_PACKAGES_ROOT), so both sides come from the same scenarios and the
67+
# same Rolldown. On a PR the head is the merge commit with base.sha, so the
68+
# difference is the PR's own change; on a push it is the pushed range
69+
# (`before`), so a merge that passed with a noise warning does not turn
70+
# next red on the absolute cap. continue-on-error: a base the head's
71+
# harness cannot build or measure leaves check on absolute caps instead of
72+
# blocking.
73+
base:
8474
runs-on: ubuntu-latest
8575
continue-on-error: true
8676
steps:
8777
- uses: actions/checkout@v4
8878
- uses: actions/checkout@v4
8979
with:
90-
ref: ${{ github.event.pull_request.base.sha }}
80+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
9181
path: base
9282
- uses: pnpm/action-setup@v4
9383
- uses: actions/setup-node@v4
@@ -106,23 +96,50 @@ jobs:
10696
working-directory: base
10797
- run: npm ci --no-audit --no-fund
10898
working-directory: scripts/size
109-
- run: node size.mjs --json size-base.json || true
99+
- run: node size.mjs --json size-base.json --no-gate
110100
working-directory: scripts/size
111101
env:
112102
SIZE_PACKAGES_ROOT: ${{ github.workspace }}/base
103+
- uses: actions/upload-artifact@v4
104+
with:
105+
name: size-base
106+
path: scripts/size/size-base.json
107+
108+
# The hard gate (the required status). always(): it runs when base failed;
109+
# a failed head leaves no size-head artifact and fails here.
110+
check:
111+
if: always()
112+
needs: [head, base]
113+
runs-on: ubuntu-latest
114+
steps:
115+
- uses: actions/checkout@v4
116+
- uses: actions/setup-node@v4
117+
with:
118+
node-version-file: ".nvmrc"
119+
- run: npm ci --no-audit --no-fund
120+
working-directory: scripts/size
121+
# gate.mjs's own tests; scripts/size is outside the workspace `pnpm test`.
122+
- run: npm test
123+
working-directory: scripts/size
113124
- uses: actions/download-artifact@v4
114125
with:
115126
name: size-head
116127
path: scripts/size
128+
- continue-on-error: true
129+
uses: actions/download-artifact@v4
130+
with:
131+
name: size-base
132+
path: scripts/size
133+
# The job summary carries the report on every run. The comment only
134+
# goes on PRs from this repository: a fork PR's token is read-only, so
135+
# createComment answers 403. Rendered before the gate step so a failing
136+
# PR still gets its table.
117137
- run: node report.mjs size-head.json size-base.json > size-comment.md
118138
working-directory: scripts/size
119-
# The job summary carries the report on every PR. The comment only goes
120-
# on PRs from this repository: a fork PR's token is read-only, so
121-
# createComment answered 403 and the job showed as failed on every
122-
# external PR.
123139
- run: cat size-comment.md >> "$GITHUB_STEP_SUMMARY"
124140
working-directory: scripts/size
125-
- if: github.event.pull_request.head.repo.full_name == github.repository
141+
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
142+
continue-on-error: true
126143
uses: actions/github-script@v7
127144
with:
128145
script: |
@@ -135,3 +152,16 @@ jobs:
135152
const mine = comments.find(c => c.user.type === "Bot" && c.body.startsWith(marker));
136153
if (mine) await github.rest.issues.updateComment({ owner, repo, comment_id: mine.id, body });
137154
else await github.rest.issues.createComment({ owner, repo, issue_number, body });
155+
- run: node gate.mjs size-head.json size-base.json
156+
working-directory: scripts/size
157+
# The floor and page caps (scripts/size/floor-caps.json) are frozen: a PR
158+
# may lower them, never raise them, unless its body carries a
159+
# `Size-Exception:` line. Compared against the PR's base branch, so
160+
# PR events only. always(): reported even when the gate step failed.
161+
- if: always() && github.event_name == 'pull_request'
162+
run: git fetch --no-tags --depth=1 origin "${{ github.base_ref }}"
163+
- if: always() && github.event_name == 'pull_request'
164+
run: npm run check-floor-caps -- "origin/${{ github.base_ref }}"
165+
working-directory: scripts/size
166+
env:
167+
SIZE_EXCEPTION: ${{ github.event.pull_request.body }}

‎packages/solid/src/server/signals.ts‎

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,17 @@ const SLOTS = /* @__PURE__ */ Symbol("settledSlots");
10491049
// fresh one per pass. Same lifetime and keying rationale as SLOTS above.
10501050
const PROJECTION_SLOTS = /* @__PURE__ */ Symbol("projectionSlots");
10511051

1052+
function adoptSlot(comp: ServerComputation<any>, slot: SlotRecord) {
1053+
if (slot.s === 1) {
1054+
comp.value = slot.v;
1055+
comp.error = undefined;
1056+
comp.errored = false;
1057+
} else {
1058+
comp.error = slot.v;
1059+
comp.errored = true;
1060+
}
1061+
}
1062+
10521063
function settleServerAsync<T, U>(
10531064
initial: T | PromiseLike<T>,
10541065
rerun: () => T | PromiseLike<T>,
@@ -1679,21 +1690,22 @@ function processResult<T>(
16791690
// Observe its rejection so a rejecting duplicate doesn't surface as an
16801691
// unhandled rejection (fatal under --unhandled-rejections=strict).
16811692
(result as any).then(undefined, () => {});
1682-
if (slot.s === 1) {
1683-
comp.value = slot.v;
1684-
comp.error = undefined;
1685-
comp.errored = false;
1686-
} else {
1687-
comp.error = slot.v;
1688-
comp.errored = true;
1689-
}
1693+
adoptSlot(comp, slot);
16901694
return;
16911695
}
16921696
const deferred: DeferredPromise<T> = slot ? slot.d! : createDeferredPromise<T>();
16931697
const serializes = !!(ctx?.async && ctx.serialize && id && !noHydrate);
16941698
if (!slot) {
16951699
recordSlot(0, undefined, deferred);
16961700
if (serializes) ctx.serialize(id, deferred.promise, deferStream);
1701+
} else {
1702+
// Joined flight (#3815): the slot may settle from the earlier node's
1703+
// promise, which never touches this comp — adopt it, or readers retry
1704+
// on that settled promise in microtasks forever.
1705+
const settle = () => {
1706+
if (slot.s !== 1 || !(loadingState?.served && serializes)) adoptSlot(comp, slot);
1707+
};
1708+
deferred.promise.then(settle, settle);
16971709
}
16981710
// Flatten one async level, mirroring the client core's handleAsync: a
16991711
// thenable that RESOLVES to an AsyncIterable — the shape an async stub
@@ -1859,21 +1871,11 @@ function processResult<T>(
18591871
const slotted = !!(id && ctx) && (serializes || !pumpsInScope(ctx, scopeOwner));
18601872
const slot: SlotRecord | undefined = slotted ? (ctx as any)[SLOTS]?.[id!] : undefined;
18611873
if (slot) {
1862-
const adopt = () => {
1863-
if (slot.s === 1) {
1864-
comp.value = slot.v;
1865-
comp.error = undefined;
1866-
comp.errored = false;
1867-
} else {
1868-
comp.error = slot.v;
1869-
comp.errored = true;
1870-
}
1871-
};
1872-
if (slot.s) return adopt();
1874+
if (slot.s) return adoptSlot(comp, slot);
18731875
// A known answer lands in this node too; under a served loading value
18741876
// the markup stays at commit #0 (the first-value lock).
18751877
const settle = () => {
1876-
if (slot.s !== 1 || !(loadingState?.served && serializes)) adopt();
1878+
if (slot.s !== 1 || !(loadingState?.served && serializes)) adoptSlot(comp, slot);
18771879
};
18781880
slot.d!.promise.then(settle, settle);
18791881
if (loadingState) {
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
*/
4+
/**
5+
* #3815 — a retry pass re-creates a component under the same owner ids while
6+
* its async memo is still in flight. The re-created memo joins the pending
7+
* slot (`ctx[SLOTS]`, server signals.ts) and must take the slot's answer when
8+
* the earlier flight settles it, or a memo reading it retries on that settled
9+
* promise in microtasks forever and no timer ever fires again.
10+
*/
11+
import { describe, expect, test } from "vitest";
12+
import { renderToStream } from "@solidjs/web";
13+
import {
14+
createComponent as h,
15+
createContext,
16+
createMemo,
17+
Errored,
18+
lazy,
19+
Loading,
20+
Show
21+
} from "solid-js";
22+
23+
const delay = <T,>(value: T, ms: number) => new Promise<T>(r => setTimeout(() => r(value), ms));
24+
25+
// Microtask starvation blocks every timer, so the guard lives in the memo.
26+
const RUN_CAP = 10_000;
27+
28+
function render(code: () => any) {
29+
return new Promise<string>((resolve, reject) => {
30+
let html = "";
31+
renderToStream(code, { manifest: {}, onError: reject } as any).pipe({
32+
write: (c: unknown) => void (html += String(c)),
33+
end: () => resolve(html)
34+
} as any);
35+
}).then(
36+
html => ({ html, error: undefined }),
37+
error => ({ html: "", error: String(error) })
38+
);
39+
}
40+
41+
describe("#3815 a re-created memo joining a pending slot", () => {
42+
test("the issue's shape: a hole returning a pending lazy view", async () => {
43+
const Profile = lazy(() => delay({ default: (props: any) => <h1>{props.user.name}</h1> }, 5));
44+
let runs = 0;
45+
function Page() {
46+
const user = createMemo(() => delay({ name: "Jon" }, 20));
47+
const info = createMemo(() => {
48+
if (++runs > RUN_CAP) throw new Error("info memo did not converge");
49+
user();
50+
return delay(["a", "b"], 20);
51+
});
52+
return <Profile user={user()} info={info()} />;
53+
}
54+
const out = await render(() => <main>{(() => <Page />) as any}</main>);
55+
expect(out.error).toBeUndefined();
56+
expect(runs).toBeLessThan(10);
57+
expect(out.html).toContain("Jon</h1>");
58+
});
59+
60+
// An <Errored> retry re-creating a pending <Loading> (#3750's shape) with a
61+
// fresh promise per setup and a memo reading it.
62+
test.each([false, true])(
63+
"an Errored retry re-creating a pending Loading settles its reader (async reader: %s)",
64+
async asyncInfo => {
65+
let runs = 0;
66+
const Page = () => {
67+
const user = createMemo(() => delay({ name: "Jon" }, 30));
68+
const info = createMemo(() => {
69+
if (++runs > RUN_CAP) throw new Error("info memo did not converge");
70+
const name = user().name;
71+
return asyncInfo ? delay(name, 5) : name;
72+
});
73+
return h(Loading, {
74+
fallback: "pending",
75+
get children() {
76+
return h(Show, {
77+
get when() {
78+
return info();
79+
},
80+
children: (n: any) => n()
81+
} as any);
82+
}
83+
});
84+
};
85+
const Context = createContext<boolean>();
86+
const App = () => {
87+
const later = createMemo(() => delay("LATER", 10));
88+
return h(Context as any, {
89+
value: true,
90+
get children() {
91+
return [
92+
h(Errored, {
93+
fallback: (e: any) => e().message,
94+
get children() {
95+
return h(Page, {});
96+
}
97+
}),
98+
() => later()
99+
];
100+
}
101+
});
102+
};
103+
const out = await render(() => h(App, {}));
104+
expect(out.error).toBeUndefined();
105+
expect(runs).toBeLessThan(20);
106+
expect(out.html).toContain("Jon");
107+
}
108+
);
109+
});

0 commit comments

Comments
 (0)