Currently in the Editor Widget, there should be, when it is in 'awaiting-feature-to-create' status and it receives a polygon (the polyline is closed in the sketchViewModel), and it generates a feature which can get received with esriwatchUtils.when(esriweditor.viewModel.featureFormViewModel, "feature", () => {...}.
If for example we test this feature geometry and it fails to pass, when we cancel the editor using esriweditor.cancelWorkflow() the feature is still in the view, as a GraphicsLayer (with another GraphicsLayer for boundingbox), which leaves "hanging" two internal (so they cannot be accessed using map.allLayers or mapview.allLayerViews usual methods) graphiclayers which can only be spotted if you run console.dir(map) or console.dir(view). These cannot be cleared or deleted and they are kept polluting the ui.
Example: we are awating for users to put building footprints, would not make sense to have country polygons.
esriwatchUtils.when(esriweditor.viewModel.featureFormViewModel, "feature", () => {
if (esriweditor.viewModel.state === 'awaiting-feature-to-create') {
// validation
// max_area
let num_area = esrigeometryEngine.geodesicArea(
esriweditor.viewModel.featureFormViewModel.feature.geometry, 'square-meters'
)
if (num_area > max_area) {
alert('Warning: Maximum area accepted for a building is ' + max_area.toString());
esriweditor.cancelWorkflow()
}
Fixing suggestion: esriweditor.cancelWorkflow() should delete these internal graphiclayers which were made by its associated esriweditor.viewModel.sketchViewModel, since the Editor has been canceled and is in ready state now, and these GraphicLayers should have been propagated the cancel, as they were propagated to be created from Editor widget of course.
here is the codepen (based on https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=widgets-editor-basic )
https://codepen.io/engfrancis/pen/RwpeXqX
Click Editor Add Feature > pick a polygon from templates > draw a polygon above 10.000 m2 it should not be allowed sending an alert and cancelling along. cheers.