Repository navigation
fix: convert notification store to thunks - #633
Open
KhushalSainS wants to merge 1 commit into
Open
KhushalSainS wants to merge 1 commit into
KhushalSainS wants to merge 1 commit into
Conversation
2 of 22 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fix the
core/wp-notificationsdata store and replace the brokencontrols/resolvers with thunks. Add a typed REST→client normalisation layer and make
the reducer safe for unregistered contexts and unknown ids.
Why?
The store never received fetched notifications and would crash on common operations
once the REST endpoint starts returning data. The bugs were invisible only because
the endpoint currently returns
[]:resolvers.fetchUpdatesreturnedhydrate()instead of dispatching it, so aresolver's return value was discarded and nothing entered the store.
registerContextwas a selector that mutated state in place (called viaselect),so subscribers were never notified.
HYDRATE/ADDspread a possibly-missingstate[context], throwing aTypeErrorfor any unregistered context.
findContextreturnedundefinedon no match, soDELETE/UPDATEindexedstate[undefined](a double dismissal triggered it).CLEARmutated the previous state before spreading.controls.FETCHreadnotice.date, but the REST schema emitscreated_at.selectors.fetchUpdatesreturned the whole state just to trigger the resolver.Fixes #619.
How?
src/store/controls.tsandsrc/store/resolvers.tsand replace them with afetchUpdatesthunk (thunks are supported by default in@wordpress/data10.x).Concurrent dispatches are de-duplicated so overlapping resolver calls issue one request.
src/store/normalize.tsmapping the REST payload to the clientNotice:created_at → date,is_dismissible → dismissible,channel_title → source,icon → { dashicons }, and theaccept_link/accept_label/dismiss_labelaction fields.registerContextto an action plus aREGISTER_CONTEXTreducer case, and dispatchit from
wp-notifications.ts.CLEARmutating, and upsert by id using an indexMap(linear merge).getNotices( context )so the first read of a context fetches.findContext/findNotice/getNoticesagainst missing data.@jest-environmentJSDoc tag in thetests/**ESLint override.npm run test:jsis intentionally left as-is (still stubbed) in this repo, so the new testsrun manually rather than in CI.
Testing Instructions
npm ci.npx jest --selectProjects unit.HYDRATEinto an unregistered context,DELETEof an unknown id,CLEARnot mutating,created_at → date, and thefetchUpdatesthunk hydrating the store (with concurrent-fetch de-duplication).npm run lint:jsand confirm no errors.Use of AI Tools
AI assistance: Yes
Tool: OpenAI Codex