Page MenuHomePhabricator

[lib] Remove KeyserverInfoPartial type
ClosedPublic

Authored by ashoat on Nov 28 2023, 8:36 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 8, 3:14 PM
Unknown Object (File)
Thu, Nov 7, 10:09 PM
Unknown Object (File)
Oct 30 2024, 8:21 PM
Unknown Object (File)
Oct 1 2024, 11:30 PM
Unknown Object (File)
Oct 1 2024, 11:30 PM
Unknown Object (File)
Oct 1 2024, 11:30 PM
Unknown Object (File)
Oct 1 2024, 11:30 PM
Unknown Object (File)
Oct 1 2024, 11:30 PM
Subscribers

Details

Summary

Following the Flow upgrade, I'm looking at replacing all usages of $Shape in our codebase. Context here.

When I swapped the $Shape in KeyserverInfoPartial into a Partial, it revealed a type error. The issue is that the urlPrefix and connectionStatus we pass to createBoundServerCallsSelector are nullable, but that function requires them to be set.

I investigated further and found that we don't actually use KeyserverInfoPartial in any case where its "partialness" is necessary... it appears we just get the KeyserverInfos from the Redux store and pass them in. As such, I deleted the type and replaced usages with KeyserverInfos.

Depends on D10082

Test Plan

Flow

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

This was so because we pass paramOverride to useKeyserverCall that looks like this:

const serverCallParamOverride = React.useMemo(
  () => ({
    keyserverInfos: {
      [(keyserverURL: string)]: {
        urlPrefix: keyserverURL,
      },
    },
  }),
  [keyserverURL],
);

So the keyserverInfos are not of type KeyserverInfos, because they are missing some fields.
We spread paramOverride into bindCallKeyserverEndpointToAction, and override the keyserverInfos field. So it does take partial KeyserverInfos sometimes. I think this is just to complicated for flow to catch.

Currently we always expect urlPrefix to be provided, but connectionStatus can probably fallback to default. Although I think this would require checking if getVersion still works, because I can see that in callServerEndpoint if connectionStatus === 'connected' we use the socket, and otherwise we use the fetch, so we would stat using the socket I think? I remember @ginsu having a similar issue, but I can't find the discussion

  1. Revert changes in earlier iteration
  2. Default to disconnected if no ConnectionStatus
  3. Require that urlPrefix is always specified in KeyserverInfoPartial

Thanks @inka!

I think this is just to complicated for flow to catch.

I looked into why Flow is unable to correctly typecheck the code snippet in your last comment, which should have printed a type error in my initial revision of this diff. It looks like the computed property there is confusing Flow: replacing that with a normal property correctly flagged the type error.

Currently we always expect urlPrefix to be provided

I updated the diff to require that KeyserverInfoPartial always specifies urlPrefix.

connectionStatus can probably fallback to default. Although I think this would require checking if getVersion still works, because I can see that in callServerEndpoint if connectionStatus === 'connected' we use the socket, and otherwise we use the fetch, so we would stat using the socket I think? I remember @ginsu having a similar issue, but I can't find the discussion

To avoid using the socket, I opted to default to disconnected when no connectionStatus is specified.

This revision is now accepted and ready to land.Nov 30 2023, 1:40 AM
This revision was automatically updated to reflect the committed changes.