Skip to content

fix: react-hooks lint rules as errors, and the ticket report's period chart in the ECharts showcase - #234

Merged
eizedev merged 3 commits into
mainfrom
fix/react-hooks-lint
Nov 25, 2026
Merged

eizedev merged 3 commits into
mainfrom
fix/react-hooks-lint

Conversation

@eizedev

@eizedev eizedev commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Summary

The lint follow-up of #217: the React code passes eslint-plugin-react-hooks recommended-latest, and exhaustive-deps is an error. Two bugs in the ECharts showcase's ticket report are fixed too.

Refs #217

Lint (npm run lint before: 9 warnings; with the stricter rules 18 errors; now 0)

  • shared/js/useLatest.js (new): a ref with the latest value for handlers registered once. It is written in useInsertionEffect, not during render. React 18.3.1 has no useEffectEvent. The insertion effect runs before every layout effect of the commit, children's included, so a callback that pivotkit fires from its own layout effect reads the new props.
  • Effect dependencies are complete. One dependency is left out on purpose, with the reason on its line: the chart is created only for another renderer or locale, and a new theme goes to the living chart.
  • useTemplateEndpoints: new server templates reset the local ones during the render that brings them, not in an effect after it.
  • usePsuTheme keeps its object when the colours did not change, so psuTheme can be a dependency.

Showcase, ticket report

  • "Opened per day: this period vs previous period" ended today. The generated tickets end yesterday and stay in $Cache: for days, so the last days of "This period" were 0. The period now ends on the newest ticket's day.
  • The two "Average" labels overlapped when the first series had the lower average. The module puts series 0 at insideEndTop and series 1 at insideEndBottom, so those labels face each other. The previous period's label is now at the start of its line.
  • "Tickets per day" cast a culture-formatted date string with [datetime], which throws a FormatException under de-DE. The test below found this.

Whole-change check

I read every changed file in full. Each function has one job.

File What it does now Extracted or reused Why the rest fits
shared/js/useLatest.js Holds the latest value in a ref, written in an insertion effect. It replaces three hand-written ref.current = props copies (ECharts, Perspective, Pivot). AGENTS.md lists it under Layout. It has one job and no state.
shared/js/psuTheme.js Reads the theme and keeps the old object when nothing changed. Nothing new. One more comparison in the observer.
EChart.jsx Same component; refs written in effects, dependencies complete. Export and full screen are module-level functions that take the props or element. remember is a useCallback. customTheme is memoized by its key. The init and theme effects stay separate on purpose: a theme change must not recreate the chart. The function is 22 lines shorter, and the growth baseline is lowered.
Perspective.jsx Same component. The table effect depends on prepared (data and column names). useLatest for latest and modeRef. New columnNames with the same rows now reach the viewer (CHANGELOG).
PivotReport.jsx Same component. useLatest for latest and viewRef. Nothing else changed.
useStoredView.js, useLoadedFile.js, useTemplateEndpoints.js Same hooks. The ref parameter is latestRef, so the compiler rules see a ref. Nothing new. The added dependencies are stable refs and setters, so effects do not run more often. The template reset is the documented "adjust state during render" pattern.
eslint.config.js recommended-latest rules, exhaustive-deps as an error. The plugin's own preset, not a hand-written list. The comment states the rule for disables.
Showcase.ps1 (ECharts demo) The period follows the data; labels at opposite ends; no culture-dependent cast. It uses -Options deep merge (mergeOptions) instead of a module change. A module-level fix that places labels by which average is higher is a separate change (see below).
tests/powershell/ECharts.Tests.ps1 It runs the ticket page with stubs and a cache aged by two days. Same stub pattern as PivotDemo.Tests.ps1. Without the fix it fails: days 58 to 60 have Current = 0.

Not changed here, worth a follow-up: the module's markLineOf alternates top and bottom by series index. Close averages, where the second is higher, overlap in any chart, not only in the showcase.

Neutral review

A read-only reviewer reviewed the first commit in its own worktree: target, "behaviour must not change", the React 18.3.1 constraint, evidence for every finding.

  1. Perspective's new prepared dependency also reacts to new columnNames. The comment "keeps its layout" was wrong for that case. Fixed: I corrected the comment and the CHANGELOG says that the view starts again, as with new columns.
  2. The theme and option effects now also run when only PSU's background, surface or font colour changes. That is correct, because the theme reads them. Kept.
  3. The suggestion was to avoid the remaining react-hooks/refs disable with useState. I tried that before the review: the immutability rule then flags the tooltip state mutations. Kept, with the reason in the code.
  4. Minor: a blank line in a CHANGELOG list (fixed); AGENTS.md did not name useLatest.js (fixed).
  5. Open: does pivotkit call onViewChange or onDataLoad during render? Answered below: no.

Checked on PowerShell Universal

PSU 2026.3.4, the four modules built from this branch, every app that uses them restarted. Each page loaded the branch's bundles: ECharts index.7ffb21e4…, Perspective index.1371585b…, Pivot index.54516e00…. Chromium unless noted.

Point Result
Ticket report period chart Both series have 0 zero days (zeros: 0). The labels are at insideEndTop and insideStartBottom. The screenshots in light and dark, 1400 and 390 px wide, show the two "Average" labels apart. On main: ('This period', 3 zeros, 'insideEndTop'), ('Previous period', 0, 'insideEndBottom').
EChart click One POST per click. The table title changes (Tickets: Applications, P1 (58)).
EChart brush One POST. The table is filtered (Tickets: 11/5/2026 to 11/15/2026 (181)).
EChart click and zoom through Get-UDElement, linked charts with -Group, hover tooltip psu.spec: 48 passed in all three browsers.
-LightTheme / -DarkTheme Palette #003b6f, #f28c28 in light and #6fa8dc, #f6b26b after PSU's switch.
CSV export, full screen The download chart.csv arrived. Full screen turned on.
Zoom over a theme change Lost: 40–60 becomes 0–100. Main behaves the same (same script on the main build). This is not caused by this change; worth an issue of its own.
Perspective toolbar Edit view toggles aria-pressed. Chart switches to Y Bar and Table to Datagrid.
Perspective click One POST per click.
Perspective layout over PSU's theme switch A changed sort is reset, because PSU mounts the component again. Main behaves the same; not caused by this change.
Pivot: view in the address bar and sessionStorage, -OnViewChange, -OnCellClick, a loaded file with Undo/Redo and "Back to original data", templates in the browser, light/dark, phone width psu-pivot.spec: 113 passed, 12 skipped, 1 failed: WebKit "Back to original data after more files…" with "ResizeObserver loop completed with undelivered notifications", the known #218, also failing on main. psu-pivot-demo.spec: 24 passed, 6 skipped. Screenshots light and dark, 1400 and 390 px: no page errors.
Pivot: templates on the server with sign-in Not checked: the role tests need reader and admin credentials (skipped in the spec).
Does pivotkit call the callbacks during render? No, from pivotkit-react 0.10.0's dist/index.js. onViewChange is called only in apply, which is called from commit, undo/redo and restore, which are event handlers. restore is also called from a mount effect (history.restore(view), line 4273) and the mount layout effect of useKeepData (line 4094). onDataLoad is called from tell in import-ui.js (load, undo/redo, restoreData in that layout effect). Since useLatest writes in an insertion effect, which runs before those layout effects, these callbacks see the current props.

Afterwards the instance runs the build from main again (with its pinned pivotkit packages), and the apps load.

Checklist

  • Linked issue
  • A fix comes with a test that fails without it; no test weakened, skipped or deleted
  • The pages in docs/ and the module's CHANGELOG.md describe the new state
  • A visible change: checked on a PSU instance in light and dark theme, narrow and wide window, with the events it fires (PSU version: 2026.3.4)

Test plan

  • npm run lint (exit 0, --max-warnings 0), npm test (219 pass, 0 fail), npm run growth (all ok), Invoke-Pester -Path tests/powershell (380 passed, 0 failed, 7 skipped), Invoke-ScriptAnalysis.ps1 (exit 0), Build-Module.ps1 for the four modules, the site build, and npm run test:browser (87 passed in Chromium, Firefox and WebKit; the PSU specs were skipped there and run separately above)
  • PSU specs as above

🤖 Generated with Claude Code

eizedev and others added 3 commits November 25, 2026 22:37
…e ECharts showcase

- shared/js/useLatest.js: the latest props for handlers registered once, written in an insertion
  effect instead of during render (React 18 has no useEffectEvent)
- EChart, Perspective, PivotReport and the pivot hooks: refs no longer written during render, effect
  dependencies complete; the chart-creating effect keeps its two dependencies on purpose (disabled
  with the reason)
- useTemplateEndpoints: new server templates reset the local ones during render, not in an effect
- usePsuTheme keeps its object when the colours did not change
- eslint.config.js: recommended-latest rules on, exhaustive-deps an error
- ECharts showcase: the period chart ends on the newest ticket's day, the averages are labelled at
  opposite ends, the per-day chart no longer parses dates in the server's culture

Refs #217

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… names, useLatest in AGENTS.md

Refs #217

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant