This document outlines the current architecture,
leveraging React v19's useActionState hook for form handling and state management,
combined with internal use of AsyncGenerator for efficient data processing within the search action.
- Use
useActionStatefor unified form submission and state management. - Eliminate manual loading state handling at the component level.
- Collocate primary data fetching orchestration logic within the action function.
- The main action function manages the overall search lifecycle orchestration.
useActionStateprovides a single point for final state updates to the UI.- Clear, unidirectional data progression from user input to final result state.
- Internal functions (
fetchAllRevisions,findOneOccurrence) utilizeAsyncGeneratorextensively. - Revision IDs and content are fetched and processed in batches/streams, minimizing memory usage for large histories.
- The action function consumes this generator pipeline, awaiting the final result.
graph TD
A[App] -->|useActionState| B(Search State)
B --> C[SearchForm]
C -->|form action| D{Search Action}
D -->|orchestrates| E[Internal Generator Pipeline]
E -->|fetches/processes| F[MediaWiki APIs]
F -->|results| E
E -->|final result| D
D -->|returns final state| G(Search State Update)
G --> H[ResultView]
Note
While the overall flow uses useActionState with a single final state update,
the "Search Action" internally uses an AsyncGenerator pipeline (fetchAllRevisions, findOneOccurrence)
to efficiently process potentially large revision histories in batches.
- Handles the complete search workflow orchestration:
- Input validation.
- Calls
fetchAllRevisions(anAsyncGenerator) to get a stream of revisions. - Passes the revision stream (which now includes content) to
genFindMap. genFindMapconsumes this generator, applying the search predicate to find the target text efficiently.- Awaits the final result (found revision ID or null) from
genFindMap.
- Handles optional
startRevIdandendRevIdform inputs to limit the revision range. - Returns a single, comprehensive final
SearchStateobject compatible withuseActionState.
fetchAllRevisions: Fetches revision IDs page by page from the API, yielding IDs as anAsyncGenerator.genFindMap& Helpers: Consumes the revision generator (which includes content), applies the search predicate, and returns the first match found.
- App: Manages state via
useActionStatehook, consuming the final state fromsearchAction. - SearchForm: Collects user input (wiki, title, text, order, optional 'start revision ID', optional 'end revision ID'), triggers the action.
- ResultView: Renders the final search result or error state.
- React v19 (
useActionState) - TypeScript
AsyncGeneratorfor internal data processing- Fetch API (with streaming JSON parsing)
- Improved state collocation via
useActionState. - Simplified async handling at the component level.
- Built-in pending/loading states from
useActionState. - Optimistic UI updates managed by
useActionState. - Efficient handling of large revision histories via internal
AsyncGeneratorpipelines, minimizing memory footprint. - Enhanced user experience through clear state transitions.
- Exposing intermediate progress states (would require changing
searchActionto be a generator itself and adapting state management). - Advanced caching strategies.
- More robust error handling granularity.
- Internationalization support.
- Server and client rendering compatibility exploration.
- Ensuring graceful degradation in various scenarios (e.g., JavaScript disabled, API errors).
- Potential use of Server Components.