feat: controllable highlight state for embedding hosts
Maintainers usually reply within 1 day
@hamed-musallam is already working on this.
Since Oct 5, 2026.
- #4402 by @vcnainala — closed without merging
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- react, typescript
Research direction
Start with HighlightProvider, useHighlight, and the NMRium/InnerNMRium prop flow described in the issue. Trace the existing reducer and dispatch behavior, then verify that controlled and uncontrolled modes preserve current behavior, expose the proposed state types, and report every highlight change through onHighlightChange.
Written by the indexing model from the issue text.
Description
Summary
NMRium's highlight state is currently private to HighlightProvider / useHighlight. Embedding hosts (for example via nmrium-react-wrapper) sometimes need to drive that state from outside NMRium — typically across a cross-origin iframe with postMessage.
Proposed API
export interface NMRiumHighlightState {
highlighted: string[];
highlightedPermanently: string[];
sourceData: HighlightEventSource | null;
}
interface NMRiumProps {
// ...existing
/** When provided, highlight state is controlled by the host. */
highlight?: NMRiumHighlightState;
/** Called for every highlight change, including internal hover/click. */
onHighlightChange?: (state: NMRiumHighlightState) => void;
}
Leaving highlight out keeps today's behaviour unchanged (uncontrolled).
Implementation sketch
HighlightProvideraccepts optionalvalue/onChange.- In controlled mode, render from
value;dispatchruns the existing reducer against a latest-state ref and callsonChange(next)instead of updating internal state. - Keep that ref in sync with each reduced value (not only with props), so consecutive dispatches such as the
useHighlightunmount cleanup (HIDEthenUNSET_PERMANENT) do not drop updates. - The internal
highlightsrecord can stay derived fromhighlightedand remain private. - Wire
highlight/onHighlightChangefromNMRiumPropsthroughInnerNMRiumintoHighlightProvider. - Export
NMRiumHighlightState(andHighlightEventSourceif not already public).
Out of scope (separate discussion)
NMRium regenerates peak ids on load, so imported ids from a host never match. Hosts currently fall back to matching by nucleus + ppm. Keeping imported peak ids stable would let hosts highlight by id; that can be a follow-up.
Questions for the team
- Is the controlled-prop shape preferred over an imperative
NMRiumRefAPI.highlight(ids)/clearHighlight()method? - Any concern about
onHighlightChangefiring on every hover (performance for large spectra / embedding hosts)?
- Dominant language
- TypeScript
- Stars
- 81
- Forks
- 35
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 21
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cheminfo/nmrium
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Multiple assignment edition issuePossibly taken @hamed-musallam claimed this 5 days ago. Open
cheminfo/nmrium#4400 · 1 assignee ·
Maintainers usually reply within 1 day
-
reedit of simulated spectra ?Possibly taken @hamed-musallam claimed this 9 days ago. Open
cheminfo/nmrium#4396 · 1 assignee ·
Maintainers usually reply within 1 day
-
Autolink from 2DPossibly taken @hamed-musallam claimed this 12 days ago. Open
cheminfo/nmrium#4393 · 1 assignee ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
kind/chore priority/must
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sidereal-io/sidereal#380 ·
Maintainers usually reply within 1 day
-
Mend: dependency security vulnerability
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
opfab/operatorfabric-core#10653 ·
Maintainers usually reply within 1 day
-
backend bug size:sm
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
chrisbenincasa/tunarr#2237 ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 Half a day Newbie friendliness 69/100
Lam30ne/regulate-app#39 ·