Bug: node.setFormat and selection.formatText leave empty style and class attributes
- Dominant language
- TypeScript
- Stars
- 23.9k
- Forks
- 2.2k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 61
Description
Lexical version: v0.12.4
# Bug 1
## Steps to reproduce
1. Enter the text ‘abc’ in the editor:
```html
abc
```
2. Select the text ‘abc’ in the editor.
3. Set and delete the `text-align` CSS property of the `p` element:
```javascript
const selection = $getSelection();
const spanNode = selection.anchor.getNode();
const pNode = $getNearestBlockElementAncestorOrThrow(spanNode);
pNode.setFormat('center');
pNode.setFormat('');
```
## The current behavior
The `style` attribute of the `p` element is empty:
```html
abc
```
## The expected behavior
The `style` attribute of the `p` element should not be present:
```html
abc
```
# Bug 2
## Steps to reproduce
1. Enter the text ‘abc’ in the editor:
```html
abc
```
2. Select the text ‘abc’ in the editor.
3. Set and delete the `text-decoration` CSS property of the `span` element:
```javascript
const selection = $getSelection();
selection.formatText('underline');
selection.formatText('underline');
```
## The current behavior
The `class` attribute of the `span` element is empty:
```html
abc
```
## The expected behavior
The `class` attribute of the `span` element should not be present:
```html
abc
```
Contributor guide
Research direction
Reproduce both cases using node.setFormat and selection.formatText, starting with the selection and block-node entry points shown in the report. Trace how cleared formatting is serialized, then add regression coverage for the missing style and class attributes. Done means both attributes are omitted rather than emitted empty.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100