Fix issues with adding widgets after removing widgets.

From #5268.