Skip to content

Don't consider forceUpdates after unmounting an error? #1247

Closed
@markijbema

Description

@markijbema

I came across an issue with React.Backbone, which in my opinion is an issue with react (though it is possible to work around it, but by implementing what imho should be in React).

Let's say i have a backbone model (or some other event source), I listen on for changes. But changes tend to come together (adds on collections for instance), and I don't want to rerender, because I know it's very probable a new change will arrive. So I take the naive code, and add a debounce or a throttle (see for some background clayallsopp/react.backbone#9 ).

When I unmount the component, I of course unbind the event listeners. However, there is no easy way to remove the throttlled operations still in the air. So now the debounce comes to the end of it's time out, and triggers the throttled forceUpdate.

I wonder why React would consider a forceUpdate after unmount an exception/error. I think a warning might be warranted, but isn't a default behaviour of throwing away the call perfectly fine? Otherwise you're demanding of the users of components to either wrap forceUpdate in a safeForceUpdate which checks isMounted, or all bound events must be unbound synchronous (which I would guess isn't always possible).

If indeed everyone agrees I would be willing to make a PR, but it sounds like something which not everyone might agree on, so I'd be interested in background/opinions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions