Preprocess the event. Args: app: The app to apply the middleware to. state: The client state. event: The event to preprocess. Returns: An optional delta or list of state updates to return.
(
self, app: App, state: BaseState, event: Event
)
| 20 | """Middleware to handle initial app hydration.""" |
| 21 | |
| 22 | async def preprocess( |
| 23 | self, app: App, state: BaseState, event: Event |
| 24 | ) -> StateUpdate | None: |
| 25 | """Preprocess the event. |
| 26 | |
| 27 | Args: |
| 28 | app: The app to apply the middleware to. |
| 29 | state: The client state. |
| 30 | event: The event to preprocess. |
| 31 | |
| 32 | Returns: |
| 33 | An optional delta or list of state updates to return. |
| 34 | """ |
| 35 | # If this is not the hydrate event, return None |
| 36 | if event.name != get_hydrate_event(state): |
| 37 | return None |
| 38 | |
| 39 | # Clear client storage, to respect clearing cookies |
| 40 | state._reset_client_storage() |
| 41 | |
| 42 | # Mark state as not hydrated (until on_loads are complete) |
| 43 | setattr(state, constants.CompileVars.IS_HYDRATED, False) |
| 44 | |
| 45 | # Get the initial state. |
| 46 | delta = await _resolve_delta(state.dict()) |
| 47 | # since a full dict was captured, clean any dirtiness |
| 48 | state._clean() |
| 49 | |
| 50 | # Return the state update. |
| 51 | return StateUpdate(delta=delta, events=[]) |
nothing calls this directly
no test coverage detected