forcedotcom / forcedotcom/state-management

state managers obtained via fromContext cause issues when passed to ephemeral components

Open
#10 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
8
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Passing a state manager obtained using `fromContext` to another component that is disconnected from the DOM before the original component causes the original component to stop receiving updates when the state manager changes.

Consider a scenario like the following:

1. Component X uses `fromContext` to obtain a reference to a state manager instance.
2. Component X creates a modal and passes the state manager instance as an `@api` property to the component Y in the modal.
3. The user interacts with the modal and closes it.

Closing the modal causes component Y to be disconnected from the DOM, and (incorrectly) terminates component X's subscription to changes in the state manager instance. Subsequent changes to the state manager instance will not trigger re-renders of component X.

Note that this behavior is specific to state manager instances obtained using `fromContext`. References to state manager instances obtained via other means should not have this issue.

As a temporary workaround, components should pass the value of the state manager instance to the ephemeral component rather than a reference to the state manager instance itself. That is instead of doing:

```

```

do:

```

```

Both components will be reactive to changes in the state manager's value and the subscription will not be impacted when the ephemeral component is disconnected.

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.