FormidableLabs / FormidableLabs/react-live

Address remaining React hooks lint warnings in LiveProvider and Editor

Aperta
#417 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
4.6k
Fork
260
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Five oxlint warnings remain, set to `warn` in `.oxlintrc.json`.

### `LiveProvider` effect deps

```js
useEffect(() => {
transpileAsync(code).catch(onError);
}, [code, scope, noInline, transformCode]);
```

**Do not apply the suggested fix as-is.** The linter calls `scope`, `noInline`, and `transformCode` unnecessary because they are not in the effect body. They are used by `transpileAsync`, which closes over them. Removing them stops re-transpiling when `scope` or `transformCode` changes.

Real bug the linter misses: `transpileAsync` also closes over `enableTypeScript`, which is not in the deps, so toggling it at runtime does not re-transpile.

Fix: make `transpileAsync` a `useCallback` with deps `scope`, `noInline`, `transformCode`, `enableTypeScript`, and depend on it. Changes when transpilation runs, notably for an inline `scope={{ ... }}`.

### `jsx-no-constructed-context-values`

New context object every render re-renders all consumers. Needs `useCallback` on `onError`/`onChange` as well as `useMemo`, and `onChange` depends on `transpileAsync` — so entangled with the above.

### `set-state-in-effect` in `Editor`

`useEffect(() => setCode(props.code), [props.code])` syncs state from props. Both standard fixes change the controlled/uncontrolled contract of a contentEditable editor.

### Order

1. Add tests that changing `scope`, `noInline`, `transformCode`, and `enableTypeScript` re-transpiles. Only `code` is covered today. The `enableTypeScript` one should fail, confirming the bug above.
2. Fix the stale closure.
3. `useCallback`/`useMemo` refactor.
4. `Editor` prop sync, separately.

Worth holding until #415 is understood.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start with the LiveProvider tests that currently cover only code changes, then inspect the LiveProvider and Editor entry points alongside .oxlintrc.json. Add coverage for changes to scope, noInline, transformCode, and enableTypeScript, then address the remaining warnings while preserving the contentEditable controlled/uncontrolled contract; consider #415 first.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
react, typescript
Ambito
frontend, testing
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.