Auto unsubscribe on the element is detached
See original GitHub issueThanks for the library.
Let’s say I have the following example:
function App() {
const [show, setShow] = React.useState(true);
const [text, updateText] = useObservableState<string>(
text$ => text$.pipe(delay(1000), map(() => Math.random().toString()), finalize(() => console.log('done'))),
'Init'
)
return (
<section>
<button onClick={() => setShow((v) => !v)}>Toggle</button>
{show && <h1 onClick={updateText}>{text}</h1>}
</section>
)
}
When we toggle the element the subscription is still alive. The finalize isn’t invoked. How do we deal with this situation?
Thanks.
Btw, I also get a type error:
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Knockout computed observable is unsubscribed when ...
I'm using jQuery detach which preserves the knockout data on the elements, and then reattaching with attach .
Read more >Stores / Auto-subscriptions • Svelte Tutorial
Calling a subscribe method returns an unsubscribe function. You now declared unsubscribe , but it still needs to be called, for example through...
Read more >Solving The Element Is Detached From DOM Error In ...
A video of a page refreshing and breaking a Cypress test and several possible solutions. Many people complain about the dreaded "Element is...
Read more >6 Ways to Unsubscribe from Observables in Angular
In this post, I'll review the different ways you can unsubscribe from Observables in Angular apps. The Downside to Observable Subscription.
Read more >Detached SVG elements after a call to paper remove
You received this message because you are subscribed to the Google Groups "JointJS" group. To unsubscribe from this group and stop receiving emails...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Unfortunately as I had explained in the docs performing synchronous side effects is not safe in concurrent mode.
It might be okay if just a Behaviour Subject but users may create all kinds of observable pipelines. If you have for example an initial remote data fetching, this could be triggered multiple times if the subscription happens in render phase.
Ok, thanks. Last question:
What about a use case where I have a
BehaivorSubject
? In this case, I expect thatuseObservable
will take the initial value synchronously and use it instead of passing a “redundant” initial value and cause an additional re-render. What do you think?It’s common usage in state management libraries such as Akita.