Skip to content

feat: expose update check state#530

Closed
Chenjiujiu wants to merge 1 commit intoreactnativecn:masterfrom
Chenjiujiu:feat/check-state
Closed

feat: expose update check state#530
Chenjiujiu wants to merge 1 commit intoreactnativecn:masterfrom
Chenjiujiu:feat/check-state

Conversation

@Chenjiujiu
Copy link
Copy Markdown
Contributor

@Chenjiujiu Chenjiujiu commented Mar 26, 2026

说明

useUpdate() 增加 checkState 导出,用于统一提供最近一次检查更新的状态、结果和错误信息。

目的

让业务侧在任何时候都可以明确知道“最近一次检查是否已经执行完成”,从而更方便地实现一些依赖检查完成时机的后续功能。

例如:

  • 检查完成后再展示后续 UI
  • 检查完成后再执行某些业务逻辑
  • 区分检查中、已完成、跳过、失败等状态

包含内容

checkState 包含以下字段:

  • status
  • result
  • error

支持的状态:

  • idle
  • checking
  • completed
  • skipped
  • error

验证

  • bun test src/__tests__
  • bun lint

Summary by CodeRabbit

  • New Features

    • Added update check state tracking with five distinct statuses: idle, checking, completed, skipped, and error.
    • Persistent error state now captures and retains the most recent update check failure for improved debugging.
  • Bug Fixes

    • Enhanced error handling logic to properly normalize and manage failures during update checks.
  • Tests

    • Added test coverage for error persistence and state clearing in update check workflows.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 26, 2026

📝 Walkthrough

Walkthrough

Added update check status tracking functionality by introducing checkState context field that transitions through IDLE, CHECKING, COMPLETED, SKIPPED, and ERROR states. The client.lastCheckError field persists the most recent check failure, which the provider synchronizes with the context state.

Changes

Cohort / File(s) Summary
Type Definitions
src/type.ts, src/index.ts
Introduced UPDATE_CHECK_STATUS constant with five status values and UpdateCheckState interface for check-status tracking. New exports added to public API.
Client State Management
src/client.ts
Added lastCheckError?: Error field to Pushy class. On checkUpdate() start, field is cleared; on success, set to undefined; on failure, normalized error is stored and reported.
Context Integration
src/context.ts
Extended defaultContext and UpdateContext type to include checkState field initialized to UPDATE_CHECK_STATUS.IDLE.
Provider Implementation
src/provider.tsx
Implemented checkState management with setCheckState() and status transitions throughout checkUpdate() lifecycle. Enhanced dismissError to clear checkState.error. Manages CHECKING, COMPLETED, SKIPPED, and ERROR state transitions based on check results and timing.
Test Coverage
src/__tests__/client.test.ts
Added two test cases verifying lastCheckError behavior: error persistence and clearing on successful retry, and clearing when check is blocked after prior failure.

Sequence Diagram

sequenceDiagram
    actor Consumer as Context Consumer
    participant Provider as UpdateProvider
    participant Client as Pushy Client
    participant API as Update API

    Consumer->>Provider: calls checkUpdate()
    Provider->>Provider: setCheckState(CHECKING)
    Provider->>Client: checkUpdate()
    
    Client->>API: fetch /checkUpdate/
    alt Check Succeeds
        API-->>Client: response
        Client->>Client: lastCheckError = undefined
        Client-->>Provider: { upToDate, ... }
    else Check Fails
        API-->>Client: error
        Client->>Client: normalize to Error<br/>lastCheckError = Error
        Client-->>Provider: throw Error
    end
    
    Provider->>Provider: read Client.lastCheckError
    alt Success
        Provider->>Provider: setCheckState(COMPLETED)
    else Failure
        Provider->>Provider: setCheckState(ERROR, error)
    end
    
    Provider-->>Consumer: updated checkState available

    Consumer->>Consumer: render with current checkState.status
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A state machine hops through the day,
From IDLE to CHECKING in every way,
When errors arise, we store them with care,
And COMPLETED at last, updates flow fair!
Tracking the journey, each status so bright,
The Pushy client runs smooth and right! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: expose update check state' directly and concisely describes the main change: adding a new checkState export to expose update check status, result, and error information to consumers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/provider.tsx`:
- Around line 200-201: The spread of a possibly undefined result from
client.checkUpdate() into rootInfo causes rootInfo to become {} (truthy) and
bypass the early return; change the assignment so that rootInfo remains falsy
when checkUpdate returns undefined (e.g., assign rootInfo = result ? { ...result
} : undefined) and ensure any downstream logic that builds versions (the array
filtered with .filter(Boolean)) relies on that falsy rootInfo to short-circuit;
update references around client.checkUpdate, rootInfo, and the versions
processing so empty objects are not treated as valid version entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b1b1886a-165b-4ac7-85fa-50f2e158cbe0

📥 Commits

Reviewing files that changed from the base of the PR and between c2c66b0 and 41a9e6d.

📒 Files selected for processing (6)
  • src/__tests__/client.test.ts
  • src/client.ts
  • src/context.ts
  • src/index.ts
  • src/provider.tsx
  • src/type.ts

@Chenjiujiu Chenjiujiu closed this Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant