[No QA] Fix import/no-cycle - part 1 - #99670
Conversation
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
344ae53 to
c254445
Compare
…the API <-> Middleware import cycle
… last three middlewares into the barrel
8eb1865 to
4733d21
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@thelullabyy Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
|
No product review needed. |
Explanation of Change
Move API middleware registration out of makeRequest to break the API <-> Middleware import cycle
src/libs/API/makeRequest.tsdid two unrelated jobs. It owned the request pipeline (buildLogParams,prepareRequest,processRequest), and it ran the 13addMiddleware()calls at module scope. Only thewiring half needs
@libs/Middleware, and six of those middlewares import user action modules, every one ofwhich imports
@libs/API. That closed anAPI -> Middleware -> action -> APIcycle, so anything importing@libs/APIpulled the whole action graph in behind it.The 13
addMiddleware()calls move to a newsrc/libs/Middleware/register.ts, unchanged and in the sameorder, keeping the comments that document why the order matters.
src/setup, the composition root thatindex.jsandtests/utils/TestHelper.tsalready share, imports it for the side effect. Storybook runs itsown entry point and never loads
src/setup, so it gets the same import.This changes no behavior.
addMiddlewareismiddlewares.push(middleware)and nothing else(
src/libs/Request.ts), so registration writes no Onyx state, and all fiveprocessWithMiddlewarecallsites run from callbacks, none during module evaluation.
import/no-cycledrops from 534 findings to 478 (-56), from 148 files to 130, and the largest stronglyconnected cluster from 116 files to 98.
18 files leave the cycle graph and none enters. All 11
libs/APIandlibs/Middlewarefiles are out.None of the 478 remaining cycle paths touches either directory, against 459 of the original 534.
Diffing all 4498 findings by rule,
import/no-cycleis the only count that movesThe eager startup closure goes from 1167 modules to 1168.
register.tsis the one that enters, and noneleaves. Startup therefore evaluates the same set of modules, though 16 of them (the
Middlewaremodules,Network/LoadTestanddeepReplaceKeysAndValues) now evaluate atindex.js:11rather thanindex.js:9,because they leave
src/App.tsx's closure. Their only module-scope side effects are twoOnyx.connectWithoutViewcalls inHandleUnusedOptimisticID.ts, and those still run beforeOnyx.init().The closure from
src/libs/API/index.tsgoes from 442 modules to 71. Action modules reachable from theAPI barrel drop from 76 to 8, and
Middlewaremodules to 0. This is a decoupling mechanism.new test suites:
Fixed Issues
$ #99650
PROPOSAL:
Tests
Test 1: App reloads its data after a cache clear
Test 2: Storybook boots
Offline tests
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
android.native.mov
Android: mWeb Chrome
android.web.mov
iOS: Native
ios.native.mov
iOS: mWeb Safari
ios.web.mov
MacOS: Chrome / Safari
web.mov