uiwjs / uiwjs/react-codemirror

useCodeMirror: Updates to the onChange prop are ignored

Open
#373 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.3k
Forks
161
PR merge metrics
No merged PRs in 30d

Description

I strongly recommend to revert 387a0c5b11991841cd40c880bc95cb389de87022 because it has introduced a bug.

It doesn't call the correct onChange, if props.onChange gets changed by the parent component.

But why?

onChange is never updated (current behaviour)

const handleChange = useCallback((value: string, vu: ViewUpdate) => onChange && onChange(value, vu), []);

The handler is updated when onChange updates (correct behaviour)

This has the same behaviour as just calling onCall directly – besides the check for it being falsy.

const handleChange = useCallback((value: string, vu: ViewUpdate) => onChange && onChange(value, vu), [onChange]);

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start at the useCodeMirror implementation and inspect how the onChange callback is created. Reproduce the case where a parent supplies a new onChange prop, then verify that changes invoke the latest callback rather than the original one.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.