Repository navigation
refactor(react): build <PivotReport> from hooks and small components - #734
Merged
Merged
Conversation
warnOnce, measured, the first-load part of the data steps, unusedNotes (with a test), layerOpen and useFormPrefix move out of PivotReport.jsx into modules the new hooks can import. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Report kept its state, effects and callbacks in one 1,270-line function. Each concern now lives in a hook of its own file (use-*.js) and the stand-alone parts of the markup in components; Report composes them. Props, events, markup and behaviour stay the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… baseline Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hooks cost the first load about 2.6 KiB gzip in property names that cannot be minified. Opening a link's view (link-open.js) now loads with pivotkit-core/link, which a link needs anyway, so the first load is back under its budget. data-steps.js is gone again: as a module shared with the import UI it was a file of its own in the first load. Also from the review: New keeps a dismissed warning dismissed, as before; export-scope.js uses warn-once.js; the header lists the hooks by concern; a test for the report's keys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With it in the link chunk, CI measured the link group just over its budget. Reading the link (decode, normalize, the check for other data) stays in link-open.js; opening the view is use-share-link.js's again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
TL;DR:
ReportinPivotReport.jsxwas one 1,270-line function. It now composes custom hooks and small components, one per concern. Props, events, markup, test ids and behaviour stay the same. The first load stays within its 181 KiB budget.Growth numbers (
node scripts/growth.js)PivotReport.jsxReportOther changes to the baseline:
--update.watchSizeat 75 lines.PivotReport.jsxare gone from the unused list:sizeOf,compactAt,zonesStart,COMPACT_HEIGHTandCOMPACT_HEIGHT_NARROW.Report's complexity stays at 34. It is the composition root, and its conditional render branches (a drawer, a drill-down, a filter, the import UI, the root's attributes) are the report's own.
New structure
PivotReport.jsxPivotReport(skeleton, deferred texts) andReport, which composes the hooks and parts belowuse-host-props.jsuse-report-size.jsuse-drawer.jsuse-zone-fold.jszones, the heightuse-shown-data.jsuseKeepDatakeeps a file over a new mountuse-import.jsuseImport) and the object it works on (useImportApi)use-report-labels.jsuse-pivot-result.jsuse-fields.jsuse-steps.jscommit(), Undo, Redo, Reset and their status notesuse-unused-notes.jsuse-view-loading.jsuse-share-link.jshashchange; the Share menu's contextlink-open.jspivotkit-core/linkin the link chunkuse-dismissed.jsstorageKeyuse-tips.jsuseActivity); the tips shown and their actionsuse-menus.jsuse-saved-views.jsuse-drill.jsuse-placing.jsuse-chart-state.jsresult-steps.jsreport-keys.jsreport-toolbar.jsxabove-result.jsxresult-area.jsxstatus-line.jsx,empty-state.jsxFieldSlot(fields.jsx),DragChip(zones.jsx)warn-once.js,measure.jsexport-scope.jsuses it too); performance measuresunusedNotesmoved tounused-keep.js, andlayerOpenanduseFormPrefixtodom.js. The hooks follow the repository'suse-<concern>.jsfile naming.First load and lazy chunks (
npm run size -w pivotkit-element, gzip, local zlib)CI measured main's initial at 179.0, so it should measure this PR at about 180.6.
How the first load got back under budget:
link-open.jstakes reading a link's view (decode, normalize, the check for other data) out of the first load, into the chunk thatloadLink()loads anyway. Measured gain: about 1 KiB.linkNow()andloadLink()return that module. It re-exportspivotkit-core/link.use-share-link.js. With it in the link chunk too, CI measured the link group just over its 7.5 KiB budget.Behaviour
runAfterSheetnow runs before the import UI'sapiref is refreshed.--workers=3.unusedNotes,report-keys.jsand the two copies of the data steps.What does not fit
NO_DATA_STEPSandwithoutFutureexist twice: indata-history.js(import chunk) and inuse-shown-data.js(first load). A module shared by both would be a file of its own in the first load. The duplication existed before as well.test/data-steps.test.jskeeps the two the same.Report's complexity stays at 34 (see above).latest.current.loadedis still null in that layout effect. This is unchanged from main and unverified. Issue to follow.Checked for the new state:
packages/pivotkit-react/AGENTS.md("Where things go", the deferred.js rule)PivotReport.jsxPivotReportindata-keep.js,share-actions.js,drill-table.js,toolbar-panels.jsx,names.js,notices.js,tips.js,dom.jsanduse-big-result.jsdocs/reference/react.md(COMPACT_HEIGHT)🤖 Generated with Claude Code