pub fn try_get_global_state<'a, I>(&self, cx: Scope<'a>) -> Result<Option<&'a I>, ClientError>
    where
        I: MakeUnrx + AnyFreeze + Clone,
        I::Unrx: MakeRx<Rx = I>,
    {
        let global_state_ty = self.global_state.0.borrow();
        // Bail early if the app doesn't support global state
        if let GlobalStateType::None = *global_state_ty {
            return Ok(None);
        }
        // Getting the held state may change this, so we have to drop it
        drop(global_state_ty);

        let intermediate_state =
            if let Some(held_state) = self.get_held_global_state::<I::Unrx>()? {
                held_state
            } else {
                let global_state_ty = self.global_state.0.borrow();
                // We'll get the server-given global state
                if let GlobalStateType::Server(server_state) = &*global_state_ty {
                    // Fall back to the state we were given, first
                    // giving it a type (this just sets a phantom type parameter)
                    let typed_state = server_state.clone().change_type::<I::Unrx>();
                    // This attempts a deserialization from a `Value`, which could fail
                    let unrx = typed_state
                        .into_concrete()
                        .map_err(|err| ClientInvariantError::InvalidState { source: err })?;
                    let rx = unrx.make_rx();
                    // On the engine-side, do not set this as the active state, because that
                    // would compromise any capsules trying to access this (see #280)
                    #[cfg(client)]
                    {
                        // Set that as the new active global state
                        drop(global_state_ty);
                        let mut active_global_state = self.global_state.0.borrow_mut();
                        *active_global_state = GlobalStateType::Loaded(Box::new(rx.clone()));
                    }

                    rx
                } else {
                    // There are two alternatives: `None` (handled with an early bail above) and
                    // `Loaded`, the latter of which would have been handled as the
                    // active state above (even if we prioritized frozen state, that
                    // would have returned something; if there was an active global state,
                    // we would've dealt with it). If we're here it was `Server`.
                    unreachable!()
                }
            };

        Ok(Some(create_ref(cx, intermediate_state)))
    }
The underlying logic for `.get_global_state()`, except this will return
`None` if the app does not have global state.

This will return an error if the state from the server was found to be
invalid.
packages/perseus/src/reactor/global_state.rs