CodeVetter · Repo Unpack · Behavior traces
reduxjs/redux-toolkit
The following traces follow inspected execution paths through initialization, fetching, editing, authentication, rehydration, and generation. They include cache-hit, failure, and subscription branches that change observable behavior. These are source-derived walkthroughs, not runtime observations.
- API initialization: React createApi calls baseCreateApi, applies defaults, initializes modules, then injectEndpoints evaluates definitions and calls each module's injectEndpoint; core attaches select/initiate and React attaches named hooks.
- Basic startup: index.tsx calls setupStore, which configures the Pokémon reducer and middleware, then renders Provider/App; App calls useGetPokemonByNameQuery('bulbasaur') against the endpoint's Pokémon URL.
- Query initiation: useQuerySubscriptionCommonImpl dispatches initiate; buildInitiateAnyQuery serializes arguments and dispatches queryThunk. Its condition permits upserts first, rejects an in-flight duplicate, honors forcing, and otherwise skips fulfilled cached entries.
- Request completion: executeRequest invokes the endpoint transport and transforms/validates its output; executeEndpoint returns fulfillWithValue, buildSlice writes the cache, and useQueryState selects the result for loading/error/data rendering.
- Post edit: PostDetail calls updatePost({id,name}).unwrap(); mutation pending triggers onQueryStarted, which dispatches updateQueryData('getPost', id), then awaits queryFulfilled and undoes patches on rejection. The UI shows an error toast and exits editing in finally.examples/query/react/optimistic-update/src/features/posts/PostDetail.tsx#L104-L123examples/query/react/optimistic-update/src/app/services/posts.ts#L36-L54packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts#L443-L487packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts#L489-L503
- After a tagged mutation, buildInvalidationByTagsHandler calculates invalidatesTags and queues them while delayed invalidation has pending requests; once processed, matching unobserved queries are removed and subscribed initialized queries dispatch a forced refetch.
- Login: Login awaits login(formState).unwrap(), dispatches setCredentials, and navigates to '/'; prepareHeaders reads auth.token for later requests. PrivateOutlet selects auth.user to render Outlet or redirect, while the mock protected handler checks the bearer header.
- Persistence/generation boundaries: a REHYDRATE extractor supplies API state, completed cache entries are restored, and cache collection schedules retention cleanup. The OpenAPI CLI instead resolves config, changes to its directory, requires it, expands parseConfig, and awaits generateEndpoints for each output.