Panic "RefCell already borrowed" in `new_wasm_module_source` when a wasm module is imported again through a redirect#37172
Version: Deno 2.9.8
Dynamically importing a wasm module through a URL that redirects to an already loaded wasm module panics. In ModuleMap::new_wasm_module_source, the Ref from self.data.borrow() in the if let condition stays alive for the whole block, so the self.data.borrow_mut() on the next line panics (libs/core/modules/map/wasm.rs#L39-L42). That branch runs when the requested specifier is new but the redirect target is already in sources. Static imports don't get there because the module graph resolves them to the final URL first, but a dynamic import with a computed specifier does. The code is unchanged on main. Moving the lookup into a let before the if let avoids the overlapping borrow.
server.ts:
const wasm = new Uint8Array([
0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 127, 3, 2, 1, 0, 7, 10, 1, 6,
97, 110, 115, 119, 101, 114, 0, 0, 10, 6, 1, 4, 0, 65, 42, 11,
]);
Deno.serve({ port: 8000 }, (req) =>
new URL(req.url).pathname === "/a"
? Response.redirect("http://localhost:8000/mod.wasm", 302)
: new Response(wasm, { headers: { "content-type": "application/wasm" } }));
main.js:
const base = "http://localhost:8000";
await import(`${base}/mod.wasm`);
await import(`${base}/a`);