fix: share context engine registry across bundled chunks (#40115)

Merged via squash.

Prepared head SHA: 6af4820b7d0ea64d96f2f894ef3b0e5750b776aa
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
This commit is contained in:
Josh Lehman
2026-03-08 11:56:01 -07:00
committed by GitHub
parent 9914b48c57
commit 4bfa800cc7
3 changed files with 37 additions and 5 deletions

View File

@@ -198,6 +198,19 @@ describe("Registry tests", () => {
expect(getContextEngineFactory("reg-overwrite")).toBe(factory2);
expect(getContextEngineFactory("reg-overwrite")).not.toBe(factory1);
});
it("shares registered engines across duplicate module copies", async () => {
const registryUrl = new URL("./registry.ts", import.meta.url).href;
const suffix = Date.now().toString(36);
const first = await import(/* @vite-ignore */ `${registryUrl}?copy=${suffix}-a`);
const second = await import(/* @vite-ignore */ `${registryUrl}?copy=${suffix}-b`);
const engineId = `dup-copy-${suffix}`;
const factory = () => new MockContextEngine();
first.registerContextEngine(engineId, factory);
expect(second.getContextEngineFactory(engineId)).toBe(factory);
});
});
// ═══════════════════════════════════════════════════════════════════════════