I need the ability to perform file cleanup when a client-side web part is deleted from the page. How can I listen for the delete event?

1 Answer 1


You should override the Dispose() method on BaseClientSideWebPart. Make sure you call the base implementation as well.

protected dispose(): void
  // Do something interesting
  Log.warn("HelloWorld", "Cleaning up my stuff", this.context.serviceScope);

  // call the base class.

Note however, there there is a currently a bug where this code doesn't necessarily get called. That will be fixed.

  • Thanks, Pat. I'm still wrapping my head around Typescript so what you're saying makes sense in theory but could you provide sample code that demonstrates how to write this? Sep 23, 2016 at 21:03
  • Thank you, I logged on here to report the bug you mentioned and found your code sample as well. Looking forward to the fix! Sep 29, 2016 at 17:06
  • 1
    This now works using Drop 5 of SPFx. Oct 18, 2016 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.