ray-template/docs/table-pro-review.md

14 KiB
Raw Permalink Blame History

TablePro code review · 2026-11-05

Baseline: d15966cf. Scope: RTablePro, TablePanel, useTablePro, search controls and state, column settings, CSV/printing, styles, public types, and application/documentation examples. The findings below describe the baseline; remediation results are recorded at the end.

P1 means address before further expansion; P2 means a concrete functional or usage limitation; P3 can be handled alongside related work. “Reproduced” below means local Vitest tests reproduced the existing behavior. Other findings are inferred from source.

P1

  1. Data from the previous query scope remains actionable after switching scopes (reproduced). TablePro.tsx starts a query when request, params, or pagination changes, but replaces result only on success. Load scope=a, then switch to a failing scope=b: the table, total, getCurrentPageData(), and export still use A. Preserving results during a same-scope refresh matches the documentation; retaining another scope's results can mislead bulk operations when scope represents an account, tenant, or order. Bind successful results to a query snapshot. At minimum, clear results or disable operations when the business scope or data source changes, while separately preserving old data for same-scope failures.

P2

  1. Search submission and instance page changes do not take effect with controlled local pagination (reproduced). TablePro.tsx writes only its internal page. Rendering prefers external pagination.page, while callbacks run only for paginator actions. With pagination.page=2, submitting search still passes 2 to DataTable. Unify controlled updates for user clicks, search resets, and instance operations. Distinguish request mode, manually managed remote mode, and local mode in the documentation.
  2. Changing search rules without changing field type retains the old applied rules (reproduced). search.ts determines field retention only from type and multiple. TablePro.tsx treats value compatibility as permission to keep the snapshot. Changing a field's matches from always true to always false still leaves old rows visible. Updates to getValue, transform, or visible can also retain old conditions. Separate value compatibility from query-semantic changes; rebuild predicate/params for the latter.
  3. Exceptions in search visibility or matching callbacks bypass the error boundary. useTableSearch.ts normalizes before commit. A throwing visible callback rejects the submit Promise (reproduced), and the template does not handle the rejection. TablePro.tsx also executes getValue/matches in a computed value used by rendering; those exceptions bypass search-error as well. Decide whether callback exceptions are developer errors or recoverable errors. If recoverable, report them and retain the last valid result both during submission and predicate execution.
  4. Local column-value lookup differs from Naive UI and export behavior. search.ts uses row[key]; CSV and printing use lodash get. With nested data and key: 'customer.name', search cannot find the displayed value; the field currently needs an explicit getValue. Share default lookup semantics while retaining explicit getValue precedence.
  5. Row context-menu callbacks do not receive the triggering row. TablePanel.tsx has row and index but stores only coordinates. Menu selection emits only key/option, making row-level editing or deletion unsafe. There is no keyboard equivalent. Include row context in the callback and clear it on close, or explicitly define the feature as a table-level menu.
  6. Custom print regions lose host styles and some live control state. printing.ts clones DOM into a separate iframe containing only print styles. Regions dependent on application CSS, asynchronous fonts, canvas pixels, or non-clonable state can differ from the screen. The documented dedicated style option needs explicit limits. Verify reports and cleanup after print cancellation in Chrome/Safari.

P3

  1. Local search can reduce allocations and repeated computation. search.ts lowercases search text for every row and uses nested linear searches for multi-select arrays. Dependencies rescan all fields for each changed dependency. Precompute lowercase queries and Sets; add reverse dependency indexes for large field counts if needed. Virtual scrolling limits DOM work, not filtering costs. No large-dataset benchmark was run.
  2. Pagination width causes unnecessary updates, and locale dictionaries are repeatedly shallow-copied. The ResizeObserver in TablePanel.tsx feeds continuously changing width into rendering; pagination mode only needs to change when crossing 600px. locale.ts clones the entire dictionary before every translation, even when host translation succeeds. Prebuild fixed dictionaries and prefer host translations. Performance impact was not quantified.
  3. Public prop forwarding boundaries are difficult to verify. props.ts inherits the full Naive UI set, then splits it in both TablePro and TablePanel. New wrapper fields or Naive UI upgrades can expose inapplicable options. Clarify wrapper-controlled fields and add contract cases for controlled pagination, controlled columns, and slots. Name internal C.tsx and Props.tsx by responsibility to improve discovery.
  4. Column ordering is drag-only, and visibility reset differs from layout reset. C.tsx supports pointer dragging and keyboard checkbox selection but not keyboard ordering. “Show all” clears only hidden state; order and fixed-column patches remain. For complete reset and keyboard operation, add explicit move-up/down actions and a separate layout reset. Persisting visibility alone matches the current documentation.

Designs to preserve

Validate total and data shape before accepting a successful request. Forward AbortSignal to callers and use it to reject stale results. Keep search drafts separate from applied snapshots and version asynchronous validation. Column visibility must not mutate props directly. Retain CSV formula-prefix protection and default printing through textContent and an isolated iframe.

Four paths marked “reproduced” were independently verified with Vue Test Utils / Vitest. Reproduction tests and output were saved locally as .harness-local/table-pro-review-repro.local.spec.ts and .harness-local/table-pro-review-repro.log; known defects were not encoded as permanent repository expectations. Real performance, native print dialogs, and screen readers were outside runtime verification scope.

Remediation batches

Batch Items Result
1 1 Bind successful results to the request function, applied filters, and pagination. Scope changes invalidate immediately. Page changes retain only same-scope totals. Request failures clear rows and totals, show an empty state, and notify through the host toast. Block data access, underlying-instance access, CSV, and printing when results do not match.
2 2–5 Pagination and search resets share controlled callbacks. Compatible fields use current rules. Callback failures are reported consistently while preserving applied conditions. Field lookup matches Naive UI, printing, and CSV.
2 6–7 Row menus return row/index, support keyboards, and close when data changes. Custom printing copies page styles, root theme, ordinary form state, and copyable canvases, with bounded resource waits. Style inheritance can be disabled.
3 8–9 Precompute lowercase queries, sets, and reverse dependencies. Change pagination mode only when container width crosses its threshold. Reuse fixed fallback locale dictionaries.
3 10–11 Centralize Naive UI and wrapper forwarding boundaries and name column/appearance settings components. Add keyboard ordering buttons and separate visibility/layout resets.

Regressions: queries, pagination, and row menus, search, printing and export, and column settings. See the TablePro contract for controlled tables and custom printing. Callers own data scope in manually managed remote mode. See delivery records for native print-dialog and page-performance verification limits.

Follow-up: TablePanel reuses Naive UI card surfaces, borders, radii, and padding layers; bare removes the card appearance. Table density, striping, and borders are computed rather than mirrored from props. Remaining watchers handle refetching, search-configuration synchronization, error reporting, print cancellation, and row-menu closure.