`Slot` 在一个懒惰子对象解析为另一个懒惰子对象时抛出异常(继承自 #3165 / #3680,可能也继承自 #4082)
/**
- Minimal reproduction for #3165. Follow-up to #3680 / 8961a25, which unwraps a React Flight
- "lazy" child via
use()but only one level — a chunk resolving to a reference to another chunk - isn't handled. No Next.js/RSC/Flight runtime needed: nesting one hand-built lazy wrapper inside
- another reproduces it, since the bug is in
Slot's unwrap logic, not in how the value got there. */ import { cleanup, render, screen } from "@testing-library/React"; import { afterEach, describe, expect, it } from "vitest"; import { Slot, Slottable } from "@radix-ui/React-slot";
const REACT_LAZY_TYPE = Symbol.for("React.lazy");
/** The real shape React Flight uses for an unresolved (or resolved-to-another-chunk) child. */ function flightLazy(value: React.ReactNode): React.ReactNode { const payload = { status: "fulfilled", value, reason: null, then(resolve: (value: React.ReactNode) => void) { resolve(value); }, };
return { $$typeof: REACT_LAZY_TYPE, _payload: payload, _init: () => payload.value } as never; }
afterEach(cleanup);
describe("Slot given a lazy chunk that resolves to another lazy chunk", () => { it("renders a single level of nesting fine", () => { render({flightLazy(Click)});
expect(screen.getByRole("link")).toHaveAttribute("href", "/resolved");
});
it("throws on a second level of nesting, as bare children", () => { expect(() => render({flightLazy(flightLazy(Click))}) ).toThrow(/Slot failed to slot onto its children/); });
it("throws on a second level of nesting, inside Slottable alongside a sibling (Slot's own documented multi-child pattern)", () => {
expect(() =>
render(
…
内容来源: radix-ui/primitives