Repository navigation
Conversation
…undefined when the metric query is not ready
|
@muzimu217 is attempting to deploy a commit to the codersett's projects Team on Vercel. A member of the Team first needs to authorize it. |
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 happens
Opening the OS situation metric page can render a blank screen. When the page crashes, the console shows:
This is not limited to one bad URL. The page reaches the crashing state in three ordinary situations:
NoSsr, so it renders on the client only.router.queryis still an empty object on that first pass, which meansmetricisundefinedeven for a perfectly valid URL such as/os-situation/metrics/push./os-situation/metrics/anythingresolvesmetricto a string that is not a key of the categories map.import_export.DataView/index.tsxspecial-cases onlyimport_export; every other value falls through to<ChartsLine metric={metric} />with whatever the router holds.Why it crashes
useCategoriesData()returns an object with a fixed set of keys:ChartsLine.tsxlooks the route parameter up in that object and then iterates the result without checking it:ChartsLinehas no error boundary above it, so the throw takes down the whole page.Why this is an oversight rather than a design choice
The sidebar on the very same page reads the exact same map and already guards it:
SideBarsurvives the emptyrouter.queryand unknown segments;ChartsLinedoes not. The two components disagree about whethercategoriesData[metric]can beundefined, and it clearly can.The change
One line, following the
SideBarprecedent. No new helpers, no control-flow rewrite, no behaviour change for a valid metric — a known metric still renders every chart group, an unknown one renders the empty container, which is what the sidebar already shows in that state.No UI copy was touched, so no
i18n/enori18n/zhupdates are needed.Verification
Before (fix stashed), a component test rendering the real
Chartscomponent:After:
The third case is the important one: it confirms the optional chain does not swallow the normal path.
A dependency-free Node reproduction of the two lines gives the same red/green split, with the
pushcase producing byte-identical output before and after:CI gates
yarn test:ci— 32 suites / 138 tests pass (run withTZ=UTC; three date-formatting suites fail on a non-UTC machine both with and without this change, they are pre-existing and timezone-dependent)yarn build—✓ Compiled successfullytsc --noEmit— no new errors (76 pre-existing, all*.svgmodule declarations; zero in the changed file)Scope
Single file, single line:
apps/web/src/modules/os-situation/DataView/ChartsLine.tsx.