Repository navigation
DEV-3554: Fix the hyperformula-ui issues found in the Handsontable formula builder review - #1839
Conversation
…e editor The idle formula bar tokenized without resolving named expressions, so a named expression did not take a reference color slot there while it did in the cell editor, and every later reference was shown in a different color. The idle view now runs the same named-expression annotation as the editor and re-renders when a named expression is added or removed.
Unsubscribing from a destroyed HyperFormula instance throws, and the first throw in FormulaBuilder.destroy() skipped the rest of the teardown, leaving the popup portal, the live region and the injected stylesheet in the page. The named-expression unsubscribe now tolerates a destroyed engine, and every teardown step runs even when one throws; the first error is rethrown at the end.
The quoted sheet-name pattern was retried at every position of a run of apostrophes that no '! closes, so a long run took quadratic time on every tokenize (about 600 ms for 40,000 characters). The closing quote of every possible quoted sheet name is now found in one right-to-left pass per tokenize, with the same matches as the pattern it replaces.
The error value in a cell used the monospace formula font while the error popup title used the UI font, so the same #NAME? appeared in two fonts side by side. Both now read the new --hfe-error-font-family custom property, which defaults to --hfe-font-family, the host's font.
The stylesheet set color-scheme: light dark on every package element through a class-attribute substring selector, so light-dark() followed the operating system instead of the host theme: a dark grid on a light system showed light popups, a host could undo it only element by element, and the selector was tested against every element of the page. It is now set once per root (the editor, the formula bar, the popup portal and a hosted popup), with no specificity, so a host theme class on a root overrides it and the rest inherits.
A cell's error message was associated with the cell only while the error popup was open, through aria-errormessage, which some screen readers ignore, so a screen-reader user landing on the cell heard nothing. markCell() now also sets the message as the cell's aria-description, and removes it again when the error clears.
The address box checked only the grid bounds and reported success even when the host could not select the cell, for example a filtered-out row or a hidden column, so it showed the typed address while the selection stayed put. IGridAdapter.setActiveCell() and setSelection() may now return false; the address box then reverts, announces the invalid address and does not scroll. Adapters that return nothing keep working as before.
A popups.*.container or formulaBarContainer selector that matched nothing made the FormulaBuilder constructor throw. A host that rebuilds the builder from an event handler may pass a container its framework has just unmounted, and the throw left it without a builder. The constructor now logs a warning once per selector and uses the default placement: a floating popup, or no formula bar. The attach methods still throw on a missing container.
Ctrl/Cmd+Enter was bound to inserting a newline, and the adapter had no way to commit to the whole selection, so a spreadsheet host could not offer the usual fill-selection shortcut. Ctrl/Cmd+Enter now calls the new optional IGridAdapter.commitFill(value), or the onCommitFill option, when the host provides one, and inserts a newline otherwise. Alt+Enter always inserts a newline.
Most default reference colors fell below 4.5:1 against the editor background in light or dark mode (orange and green were near 2:1 on white), so reference text and highlight borders failed WCAG 1.4.3 and 1.4.11 unless the host restated the whole palette. The colors that failed are darkened in light mode or lightened in dark mode, keeping their hue, and the README documents --hfe-ref-1 to --hfe-ref-8 as the way to override them.
The popup portal, the live region and the stylesheet always went into the global document's body and head, and focus checks read the global document.activeElement. Inside a shadow root the editor's ARIA references pointed across the boundary and resolved to nothing; in an iframe the popups landed in the parent page without its styles; and focus checks were wrong in both. FormulaBuilder now takes rootDocument and portalParent options, creates its elements and resolves selectors in that document, appends the portal and live region to the portal parent, injects the styles into a shadow root when the portal parent is in one, and reads focus through open shadow roots.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
hyperformula-docs | 8839a57 | Commit Preview URL Branch Preview URL |
Oct 26 2026, 08:06 AM |
Performance comparison of head (8839a57) vs base (d143456) |
Haxikowy
left a comment
There was a problem hiding this comment.
Findings with no line in the diff:
adapter/domRangePicker.ts:159-162,386bindsmousemove/mouseup/scrollto the globaldocumentand callsdocument.elementFromPoint, so drag-to-extend a range ref does not work in a shadow root (the hit is the retargeted host) or an iframe. Either use the root's document there or list it next to the window listeners under out of scope.- DEFINITION-OF-DONE.md:78 asks for one change per pull request, and :84 for no new public option on its own; this one carries 11 fixes and adds
rootDocument,portalParent,onCommitFill,commitFilland--hfe-error-font-family. Please split it along the existing commits, or record the maintainers' agreement in the description. - DEFINITION-OF-DONE.md:105-111 counts a changed default and removed documented behavior as breaking: the ref colors, the error cell font, the
color-schemescope and the constructor no longer throwing. Tick the box or say why not, and give CHANGELOG.md:17 the "what to do instead" line. - CHANGELOG has no Added entry for
FormulaBarCell.refresh(),tokenPostProcess,StyleRoot,inject(root)/release(root)orLiveRegiontaking aShadowRoot. SPEC.md's types list lacksStyleRoot, and KEYBOARD-SHORTCUTS.md's behavior table has no Alt+Enter row. - The three out-of-scope items need follow-up task IDs (DEFINITION-OF-DONE.md:86), and the red FOSSA check needs a line in the description (:39); it is unrelated, and the same failure is on #1835-#1838.
|
On the findings in the review body:
|
A pick made with the caret inside an existing cell or range reference was gated by the character before the caret alone. After the colon of a range that character is a ref opener, so the pick was spliced into the token (=SUM(C1:A1:B2C2)); anywhere else in the reference it was no pick position at all, so the click committed the formula. RefController.refTokenAtCaret() finds the CELL_REF or RANGE_REF token the caret sits in, at either end included, the way F4 already does. A pick replaces that token, and a Ctrl/Cmd pick appends after it; isRefSelectionActive() reports the caret as a pick position there, so the grid keeps the click. The F4 handler reuses the helper.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1a3d539. Configure here.
getRefPreviewColor() left out only the picker's own pending reference when it assigned a drag its color, so a drag made with the caret inside a typed reference previewed the next free slot while the commit reused the slot of the reference it replaced. RefController.replacedRefRange() answers for both: the pending reference, or the cell or range reference the caret sits in.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1839 +/- ##
========================================
Coverage 97.28% 97.28%
========================================
Files 207 207
Lines 16218 16218
Branches 3556 3588 +32
========================================
Hits 15777 15777
Misses 433 433
Partials 8 8 🚀 New features to boost your workflow:
|

Context
The PR fixes the
hyperformula-uiissues found while reviewing the Handsontable formula builder (handsontable/handsontable#13172).hyperformula-ui/.undo(),redo(),changeNamedExpression(),removeSheet()valuesUpdated,sheetRemovedand everysetValuedestroy()throws after the host destroyed the engine, leaking DOM and stylesrootDocumentandportalParentoptions; listeners (scroll in a shadow root included), hit tests and focus checks follow the element's own documentsetActiveCell/setSelectionmay returnfalse; announced as "Cannot select B7", not as invalid'tokenizes in quadratic timesheetIdmakes every keystroke throw--hfe-error-font-family, falling back to--hfe-font-familywhere the error rendersadapter.commitFilloronCommitFill; Alt+Enter inserts a newlinecolor-schemeset on every element through[class*=hfe-]phrasesoption, English defaults inDEFAULT_PHRASESHow did you test your changes?
Every fix has a test that fails without it.
npm run build:uinpm run typecheck(afternpm run bundle-all)npm run lintnpm run test:uinpm run test:e2eformula-builderspecs, axe scanChecked in Chromium on the Handsontable demo against 0.3.5: error-title font,
color-schemewith the OS in the other scheme, Ctrl/Cmd+Enter fill, undo of a named expression, a reference drag in a shadow root, the error popup in an iframe.Compatibility with Excel and Google Sheets
Not applicable. The change is in the formula editor UI and cannot affect calculation results.
Public API changes
All in
hyperformula-ui:FormulaBuilderOptions:rootDocument,portalParent.FormulaEditorOptions(andFormulaBuilderOptions):onCommitFill(value),phrases;FormulaEditor.phrases.IGridAdapter: optionalcommitFill(value);setActiveCellandsetSelectionreturnboolean | void.HyperFormulaLike:on/offforsheetRemoved.Phrases(includescellUnavailable),DEFAULT_PHRASES,StyleRoot,AddressBoxNavigation.FormulaBarCellOptions.tokenPostProcessandphrases,FormulaBarCell.refresh(),FormulaBarAddressBoxOptions.phrasesandonUnavailableTarget; its navigation callbacks may return"unavailable".StyleInjector.inject(root?)/release(root?);LiveRegionaccepts aShadowRoot.--hfe-error-font-family; new--hfe-ref-1..8defaults.Not breaking, though some defaults change (reference colors, the error cell's font, the
color-schemescope, no constructor throw). The package is 0.x and no released consumer depends on these defaults. The changelog says how to keep each old default.Out of scope and follow-ups
None. Keeping all fixes in one PR was agreed by the PR author. The popups staying over frozen panes is recorded as the intended behavior in
dev-docs/SPEC.md.The License Compliance (FOSSA) check also fails on #1838 and #1841; it is not related to this change.
Types of changes
Related issues
Checklist
dev-docs/pages this change affects – or none needed it.Note
Medium Risk
Touches core editing, adapter contracts, and DOM/event wiring across iframes and shadow roots; behavior changes (fill commit, ref picking, destroy) affect all grid hosts but are additive or bug fixes with documented API extensions.
Overview
hyperformula-ui gains host-aware embedding (
rootDocument,portalParent), i18n (phrases/DEFAULT_PHRASES), and several editor/adapter fixes aimed at Handsontable integration.Embedding & DOM: Popups, live region, and styles can target an iframe document or shadow root;
DomRangePicker,ErrorPopup, and editor scroll/resize listeners use the element's window/document,composedPath()for hits, anddeepActiveElementinstead of globaldocument. Style injection is ref-counted perStyleRoot. Missing constructor container selectors warn and fall back;attach*still throws.Editing behavior: Grid picks replace the whole cell/range reference under the caret; Ctrl/Cmd+Enter commits via optional
commitFill/onCommitFill(Alt+Enter for newline). Address box honorssetActiveCell/setSelectionreturningfalsewith"unavailable"announcements. Named-expression coloring stays in sync (cache invalidation on more HF events, bar idle view usestokenPostProcess+refresh()).destroy()runs all teardown steps viarunAlleven if HF is already gone.Theming & perf: Reference colors and error font (
--hfe-error-font-family) updated; package no longer forcescolor-scheme. Lexer uses linearbuildQuotedSheetEndsfor quoted sheet names; missingsheetIdno longer throws on every keystroke.Reviewed by Cursor Bugbot for commit 8839a57. Bugbot is set up for automated code reviews on this repo. Configure here.