Open
Description
Duplicate Check
- I have searched the opened issues and there are no duplicates
Describe the bug
page.client_storage.get_async does'n work when called from page.on_connect callback.
Here is a sample code:
import flet
import flet as ft
from flet import (
Page,
colors
)
async def on_connect_callback(e):
try:
await e.page.client_storage.get_async('token')
except Exception as e:
print(e)
async def main(page: Page):
print("ddd")
page.on_connect = on_connect_callback
page.title = "Flet Trello clone"
page.padding = 0
page.bgcolor = colors.BLUE_GREY_200
page.views.clear()
page.views.append(flet.View(
appbar=flet.AppBar(title=flet.Text("sdf"), bgcolor=colors.GREEN)
))
await page.update_async()
In the code I contained the get_async call in a try block and I printed the resulted exception and it says:
**Timeout waiting for invokeMethod clientStorage:get({'key': 'token'}) call
**
I ran the code with fastapi like this:
from fastapi import FastAPI, Request, WebSocket
from fastapi.responses import RedirectResponse
from api.common.db.sql import engine
from api.auth import router as auth_router
from api.config import BASE_DIR
from sqlmodel import SQLModel
import flet_fastapi
from ui.main import main as main_ui
app = FastAPI()
@app.on_event("startup")
async def startup():
SQLModel.metadata.create_all(engine)
pass
flet_fastapi_app = flet_fastapi.app(main_ui)
app.mount('/ui', flet_fastapi_app) # this is where we mount the felt to fastapi
#
app.include_router(
router=auth_router,
prefix='/auth'
)
@app.get('/')
async def home():
return RedirectResponse('/ui')
command: uvicorn main:app --reload
But I wanted to check if it happens when running with felt only. so, I created a test.py file and comply the ui/main.py UI code and then:
command: felt test.py --web
This time it doesn't show any error.
Code sample
Logs
import flet
import flet as ft
from flet import (
Page,
colors
)
async def on_connect_callback(e):
try:
await e.page.client_storage.get_async('token')
except Exception as e:
print(e)
async def main(page: Page):
print("ddd")
page.on_connect = on_connect_callback
page.title = "Flet Trello clone"
page.padding = 0
page.bgcolor = colors.BLUE_GREY_200
page.views.clear()
page.views.append(flet.View(
appbar=flet.AppBar(title=flet.Text("sdf"), bgcolor=colors.GREEN)
))
await page.update_async()
from fastapi import FastAPI, Request, WebSocket
from fastapi.responses import RedirectResponse
import flet_fastapi
app = FastAPI()
flet_fastapi_app = flet_fastapi.app(main_ui)
app.mount('/ui', flet_fastapi_app) # this is where we mount the felt to fastapi
#
app.include_router(
router=auth_router,
prefix='/auth'
)
@app.get('/')
async def home():
return RedirectResponse('/ui')
To reproduce
/ represents the root of the project
- copy the main_ui code into a separate file /ui/main.py
- copy the main.py code /main.py
- copy the test.py code into /test.py
- run main.py with uvicorn main:app --reload for running the felt with fastapi
- run test.py with flet test.py --web for running with flet
Expected behavior
No response
Screenshots / Videos
Screenshots / Video demonstration
[Upload media here]
Operating System
Linux
Operating system details
Debian GNU/Linux 12 (bookworm)
Flet version
0.19.0
Regression
I'm not sure / I don't know
Suggestions
No response
Logs
Logs
[Paste your logs here]
Additional details
No response