adobe / adobe/react-spectrum

Breakout from infinite loops in collections

Open
#8,886 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
15.9k
Forks
1.6k
Avg merge
3d 9m
Merged PRs (30d)
59

Description

### Provide a general summary of the feature here

There are currently a few ways to trigger an infinite loop using RAC, which are not evident and surprising. It would be good if collections had the means of bailing out if such an event is detected, as this can lead to bad DX and UX.

From my understanding, this can be fixed by just managing the IDs in a set and bailing early: https://github.com/adobe/react-spectrum/issues/8033#issuecomment-2957024766

An alternative (or supplementary) proposal is to track actual time or stack size. Something like (pseudo-code-ish):

``` ts
startTime = Infinity

function processCollection() {
// Start tracking time since thread is blocked by collection work
startTime = Date.now()

while (processingCollection) {
if (Date.now() > startTime + 10_000) // Timeout after 10 seconds
throw new Error("Collection update took to long, aborting!")

processNext()
}

// Clear timer once the thread is free
setImmidiate(() => {
startTime = Infinity;
})
}
```

What do you think?

### 🤔 Expected Behavior?

No component structure of react-aria-components should lead to an infinite loop.

### 😯 Current Behavior

There are currently multiple ways of triggered an infinite loop:

Duplicate IDs in collections:
- https://github.com/adobe/react-spectrum/issues/8882#issuecomment-3304530448
- https://github.com/adobe/react-spectrum/issues/8033

Nesting collections in ListBox (which isn't supported, but still!):
- github.com/adobe/react-spectrum/issues/8740

### 💁 Possible Solution

_No response_

### 🔦 Context

.

### 💻 Examples

_No response_

### 🧢 Your Company/Team

_No response_

### 🕷 Tracking Issue

_No response_

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.