Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

feat: controllable highlight state for embedding hosts

Closed
#4,401 3 comments 0 reactions 1 assignee View on GitHub

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
Domain
api, frontend

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

  • HighlightProvider accepts optional value / onChange.
  • In controlled mode, render from value; dispatch runs the existing reducer against a latest-state ref and calls onChange(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 useHighlight unmount cleanup (HIDE then UNSET_PERMANENT) do not drop updates.
  • The internal highlights record can stay derived from highlighted and remain private.
  • Wire highlight / onHighlightChange from NMRiumProps through InnerNMRium into HighlightProvider.
  • Export NMRiumHighlightState (and HighlightEventSource if 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

  1. Is the controlled-prop shape preferred over an imperative NMRiumRefAPI.highlight(ids) / clearHighlight() method?
  2. Any concern about onHighlightChange firing 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cheminfo/nmrium

All issues in cheminfo/nmrium

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.