adobe / adobe/spectrum-web-components

[Bug]: Layout thrashing in ColorArea component

Open
#5,541 1 comment 0 reactions 0 assignees View on GitHub
bug Component:Color area SEV missing Status:WIP
Dominant language
TypeScript
Stars
1.5k
Forks
262
Avg merge
3d 10h
Merged PRs (30d)
68

Description

### Code of conduct

- [x] I agree to follow this project's code of conduct.

### Impacted component(s)

ColorArea

### Expected behavior

ColorArea should not leak memory

### Actual behavior

There are style recalculations happening in `render` method accessing `getboundingClientRect` during render.

### Screenshots

![Image](https://github.com/user-attachments/assets/73bce776-af85-489d-88b5-8e9107b02eea)

### What browsers are you seeing the problem in?

Chrome, Firefox, Safari

### How can we reproduce this issue?

1. Go to https://opensource.adobe.com/spectrum-web-components/components/color-area/#standard
2. Open Memory profiling in Chrome
3. Take a snapshot of heap memory usage
4. Check image below
5. See memory leaks

### Sample code or abstract reproduction which illustrates the problem

```ts
protected override render(): TemplateResult {
const { width = 0, height = 0 } = this.boundingClientRect || {};
// ...
style=${`transform: translate(${
(this.isLTR ? this.x : 1 - this.x) * width
}px, ${height - this.y * height}px);`}
```

```ts
this.observer = new (window as unknown as WithSWCResizeObserver).ResizeObserver(
(entries: SWCResizeObserverEntry[]) => {
for (const entry of entries) {
this.boundingClientRect = entry.contentRect;
}
this.requestUpdate(); // This triggers a full re-render
}
);
```

### Severity

None

### Logs taken while reproducing problem

_No response_

### Would you like to track this issue in Jira?

- [ ] Yes, please tell me the ticket number!

Contributor guide

Open the contributing guide

Research direction

Start with the ColorArea component's render method and the ResizeObserver callback shown in the issue. Reproduce the behavior at the standard ColorArea example and inspect memory and layout profiling in Chrome. The work is done when the reported memory leak and style recalculations caused during rendering no longer occur across the listed browsers.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.