You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What runtime/platform is your app running on? (with version if possible)
Node v22.12.0
What steps can reproduce the bug?
When using useContext in an async component if an await happens before calling useContext function the context is not set to the value used in the provider.
The context in AwaitAfterUseContext will have the messages array, while in AwaitBeforeUseContext it will be null.
import{serve}from"@hono/node-server";import{Hono}from"hono";import{useContext,createContext,typeFC}from"hono/jsx";constMessagesContext=createContext<typeofmessagesCtxData>(null);constapp=newHono();constAwaitAfterUseContext: FC=async()=>{constmessages=useContext(MessagesContext);awaitnewPromise((r)=>setTimeout(r,1000));return(<><h1>HelloHono!</h1><ul>{messages.map((message)=>{return<li>{message}!!</li>;})}</ul></>);};constAwaitBeforeUseContext: FC=async()=>{awaitnewPromise((r)=>setTimeout(r,1000));constmessages=useContext(MessagesContext);return(<><h1>HelloHono!</h1><ul>{messages.map((message)=>{return<li>{message}!!</li>;})}</ul></>);};constmessagesCtxData=["Good Morning","Good Evening","Good Night"];app.get("/after",(c)=>{returnc.html(<MessagesContext.Providervalue={messagesCtxData}><AwaitAfterUseContext/></MessagesContext.Provider>);});app.get("/before",(c)=>{returnc.html(<MessagesContext.Providervalue={messagesCtxData}><AwaitBeforeUseContext/></MessagesContext.Provider>);});constport=3000;console.log(`Server is running on http://localhost:${port}`);serve({fetch: app.fetch,
port,});
What is the expected behavior?
After the await the context would be set to the correct value used in the provider.
What do you see instead?
The context is not set to the value used in the provider, instead it has de initial value.
Additional information
No response
The text was updated successfully, but these errors were encountered:
What version of Hono are you using?
4.6.16
What runtime/platform is your app running on? (with version if possible)
Node v22.12.0
What steps can reproduce the bug?
When using useContext in an async component if an await happens before calling useContext function the context is not set to the value used in the provider.
The context in
AwaitAfterUseContext
will have the messages array, while inAwaitBeforeUseContext
it will be null.What is the expected behavior?
After the await the context would be set to the correct value used in the provider.
What do you see instead?
The context is not set to the value used in the provider, instead it has de initial value.
Additional information
No response
The text was updated successfully, but these errors were encountered: