When you want to display a TOC box in your sidebar using a text widget and the toc shortcode, and there are no headings to display, you effectively get an empty widget. An ugly affair sometimes… Here is what you can do about it.
An empty widget wouldn’t be a problem if the widget wouldn’t be displayed. On my theme, for example, empty widgets have zero height, so they are not visible. But on many themes an empty widget leaves you with an unattractive blank rectangle in the sidebar.1
One way to overcome the issue is to use, for example, “Widget Logic”. But if “emptiness” is the only thing to circumvent, then “Widget Logic” is probably overkill.
Obviously, the immediate solution is a text widget variant that is not rendered at all when empty.
And here it is: The Discrete Text Widget.