Is it possible to get the context value in an async function called from a component?
Even runWithOwner() gives me the default value of the context, not the enclosing value, after the first await.
const Ctx = createContext('default');
return <Ctx.Provider value={'not-default'} >{
(() => {
runWithOwner(getOwner()!, async () => {
const f = async () => {};
console.log('before', useContext(Ctx));
await f();
console.log('after', useContext(Ctx));
});
return '';
})()
}</Ctx.Provider >;
Tried enclosing the async call in runWithOwner()
Update: I 'solved' it by using signals instead of context. It's an import of a global variable either way, but signals work...
const [Sig, setSig] = createSignal('default');
const Ctx = createContext('default');
const f = async (where: string) => {
console.log(where, 'ctx', useContext(Ctx), 'sig', Sig());
};
return <Ctx.Provider value={setSig('not-default')} >{
(() => {
(async () => {
await f('first');
await f('broken');
})();
return '';
})()
}</Ctx.Provider >;