facebook / facebook/lexical

Feature: Implement lint rule to eliminate accidental nested updates

Open
#7,040 1 comment 0 reactions 0 assignees View on GitHub
enhancement lint
Dominant language
TypeScript
Stars
23.9k
Forks
2.2k
Avg merge
1d 14h
Merged PRs (30d)
55

Description

## Description

Nested updates are never a good idea, so if we find a `$function` (or a `registerCommand`) that has an embedded `editor.update` we should rewrite it to remove the `editor.update`. As a companion to this we could add a `$defer` or something like that which could be used to provide explicit nested update semantics but I doubt we'll actually find any use case for it.

## Impact

Bugs will be avoided, code will be easier to test when the effects of updates happen in a sensible order. Nobody really wants to reason about code that looks like this:

```
editor.dispatchCommand(COMMAND_A, undefined);
editor.update(() => $b());
editor.dispatchCommand(COMMAND_C, undefined);
```

that will either execute in A, B, C or A, C, B 🙃 order depending on the context of whether this is called inside of an `editor.update` (or command listener) or not.

RE #7039 #7037 for recent examples

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.