Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/app/src/settings/providers/extensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ export const SettingsExtensions: Component<{
() => plugins.view(),
(current) => {
if (current.status !== "ready") return
dispatchUpdate({
type: "list.loaded",
ready: current.value.ready !== false,
outdated: packageFlags(current.value.data),
})
dispatchUpdate({ type: "list.loaded", outdated: packageFlags(current.value.data) })
},
{ defer: true },
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,19 @@ test("an update runs once per package, then refreshes the list and hides the but

// The server reloads its plugins after the update returns, so the refresh can read the old flag. Before, any list load
// cleared what the update learned and the Update button came back until the next reload.
test("a list read before the server reloaded keeps an update's finding until a settled list agrees", () => {
test("a list read before the server reloaded keeps an update's finding until a list agrees", () => {
const run = harness()

run.dispatch({ type: "update.requested", target: a })
run.dispatch({ type: "update.succeeded", id: 0 })
const updated = run.machine.state

run.dispatch({ type: "list.loaded", ready: false, outdated: { [a]: true } })
run.dispatch({ type: "list.loaded", ready: true, outdated: { [a]: true } })
run.dispatch({ type: "list.loaded", outdated: { [a]: true } })

expect(run.machine.state).toBe(updated)
expect(pluginUpdateView(run.machine.state, listed(a, true)).outdated).toBe(false)

run.dispatch({ type: "list.loaded", ready: true, outdated: { [a]: false } })
run.dispatch({ type: "list.loaded", outdated: { [a]: false } })

expect(run.machine.state).not.toBe(updated)
expect(pluginUpdateView(run.machine.state, listed(a, true)).outdated).toBe(true)
Expand Down
8 changes: 3 additions & 5 deletions packages/app/src/settings/providers/plugin-update-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export type PluginUpdateEvent =
| { readonly type: "update.succeeded"; readonly id: number }
| { readonly type: "update.failed"; readonly id: number; readonly message: string }
/**
* The plugin list loaded again. `ready` is false while the server is still reloading its plugins, when the list's
* flags may predate the latest check or update; `outdated` maps each listed package to its flag.
* The plugin list loaded again; `outdated` maps each listed package to its flag. A list read while the server still
* reloads its plugins can predate the latest check or update, so a finding is only dropped once a list agrees with it.
*/
| { readonly type: "list.loaded"; readonly ready: boolean; readonly outdated: Readonly<Record<string, boolean>> }
| { readonly type: "list.loaded"; readonly outdated: Readonly<Record<string, boolean>> }
/** Another server: forget what this one's checks and updates learned. */
| { readonly type: "server.changed" }
| { readonly type: "disposed" }
Expand Down Expand Up @@ -69,8 +69,6 @@ export function transitionPluginUpdate(state: PluginUpdateState, event: PluginUp
if (event.type === "server.changed") return step({ status: "idle", nextId: state.nextId, findings: {}, updating: [] })

if (event.type === "list.loaded") {
if (!event.ready) return step(state)

const settled = Object.keys(state.findings).filter(
(target) => !(target in event.outdated) || event.outdated[target] === state.findings[target]?.outdated,
)
Expand Down
Loading