|
11 | 11 | * escape, all via the guarded-stub-headers choke point; setStatus |
12 | 12 | * enumerated), |
13 | 13 | * - PPR/cache() message-family EQUIVALENCE (same Error class, same family), |
14 | | - * - the pinned cache()-loader write exemption (vite-rsc-demo shop cart), |
| 14 | + * - the pinned cache()-loader write exemption — DSL (registered) loaders ONLY |
| 15 | + * (vite-rsc-demo shop cart); a handler-invoked loader body throws under |
| 16 | + * cache() because it is skipped with its handler on a hit (#725), |
| 17 | + * - a handler-invoked loader nested under a DSL loader stays exempt (the DSL |
| 18 | + * parent re-runs it every hit), |
15 | 19 | * - middleware merge order on the shell-HIT serve path |
16 | 20 | * (createResponseWithMergedHeaders: serve-owned headers win, middleware |
17 | 21 | * headers merge, Set-Cookie appends). |
@@ -150,26 +154,61 @@ describe("assertCachedHeaderWriteAllowed (the seam)", () => { |
150 | 154 | expect(cacheErr.message).toMatch(FAMILY_RE); |
151 | 155 | }); |
152 | 156 |
|
153 | | - it("cache() + loader: ALLOWED (pinned exemption — loaders re-run and merge per request)", () => { |
| 157 | + it("cache() + DSL loader: ALLOWED (pinned exemption — DSL loaders re-run and merge per request)", () => { |
154 | 158 | RangoContext.run(makeStore() as never, () => { |
155 | 159 | latchCachedHeaderScope("cache", "shop"); |
156 | 160 | runInsideLoaderScope(() => { |
157 | 161 | expect(() => |
158 | 162 | assertCachedHeaderWriteAllowed("ctx.setCookie()"), |
159 | 163 | ).not.toThrow(); |
160 | 164 | }); |
| 165 | + }); |
| 166 | + }); |
| 167 | + |
| 168 | + // #725 gap: a handler-invoked loader body (ctx.use from a handler, never |
| 169 | + // registered with loader()) runs only on the MISS — on a HIT the handler and |
| 170 | + // this loader are skipped, so its write would silently vanish. It must throw, |
| 171 | + // NOT ride the DSL exemption. Regression pin (red before the guard narrowed to |
| 172 | + // isInsideLoaderScope()). |
| 173 | + it("cache() + handler-invoked loader body: THROWS (handler skipped on hit, write would vanish)", () => { |
| 174 | + RangoContext.run(makeStore() as never, () => { |
| 175 | + latchCachedHeaderScope("cache", "shop"); |
161 | 176 | runInsideLoaderBodyScope( |
162 | 177 | () => { |
163 | | - expect(() => |
| 178 | + const err = captureError(() => |
164 | 179 | assertCachedHeaderWriteAllowed("ctx.setCookie()"), |
165 | | - ).not.toThrow(); |
| 180 | + ); |
| 181 | + expect(err.message).toContain("from a loader"); |
| 182 | + expect(err.message).toContain("cache() boundary"); |
| 183 | + expect(err.message).toContain("the handler is skipped"); |
| 184 | + expect(err.message).toMatch(FAMILY_RE); |
166 | 185 | }, |
167 | 186 | "CartLoader", |
168 | 187 | true, |
169 | 188 | ); |
170 | 189 | }); |
171 | 190 | }); |
172 | 191 |
|
| 192 | + // The DSL scope ALS survives into nested ctx.use bodies, so a handler-invoked |
| 193 | + // loader nested under a DSL loader stays exempt: the DSL parent re-runs on |
| 194 | + // every hit and re-invokes it, so no MISS/HIT divergence exists. |
| 195 | + it("cache() + handler-invoked loader body nested in a DSL loader: ALLOWED (DSL parent re-runs it every hit)", () => { |
| 196 | + RangoContext.run(makeStore() as never, () => { |
| 197 | + latchCachedHeaderScope("cache", "shop"); |
| 198 | + runInsideLoaderScope(() => { |
| 199 | + runInsideLoaderBodyScope( |
| 200 | + () => { |
| 201 | + expect(() => |
| 202 | + assertCachedHeaderWriteAllowed("ctx.setCookie()"), |
| 203 | + ).not.toThrow(); |
| 204 | + }, |
| 205 | + "NestedLoader", |
| 206 | + true, |
| 207 | + ); |
| 208 | + }); |
| 209 | + }); |
| 210 | + }); |
| 211 | + |
173 | 212 | it("first latch wins: a nested cache() does not downgrade a ppr scope", () => { |
174 | 213 | RangoContext.run(makeStore() as never, () => { |
175 | 214 | latchCachedHeaderScope("ppr", "product"); |
|
0 commit comments