Fix widget-layer connection for late-added layers#511
Conversation
|
Claude finished @TimPurdum's task —— View job PR Review Analysis CompleteTodo List:
Review SummaryAfter thoroughly analyzing the 6 changed files, I found several issues that should be addressed: Thread Safety Issue in MapView.csLine 283: Direct await InvokeAsync(StateHasChanged);This is inconsistent with the other thread-safe changes in the same file. Widget.cs - Potential Race ConditionLines 457-470: The _ = Task.Run(async () => await UpdateWidget());This approach doesn't handle exceptions and could create timing issues. Consider: if (needsUpdate)
{
_ = InvokeAsync(async () => await UpdateWidget());
}MapComponent.cs - Missing Null CheckLine 894: var parent = Parent;
ProJsModule ??= parent?.ProJsModule;Version Increment LogicDirectory.Build.props: Version changed from Test File - Thread SafetyTestRunnerBase.cs Line 161: Missing await InvokeAsync(StateHasChanged);Overall AssessmentThe race condition fix is well-designed and addresses the core issue effectively. The virtual |
Summary
LayerIdfail to connect when the layer is added to the map after the widget rendersOnParametersSetoverride toMapComponentto propagateLayer,View,LayerId, and JS module references from parent componentsLayerIdandUpdateGeoBlazorReferencesvirtual so widgets like SketchWidget can override themMapView.OnAfterRenderAsyncto detect widgets with a matchingLayerIdwhen a new layer is added, and re-invokeUpdateGeoBlazorReferencesto establish the connectionWidget.UpdateGeoBlazorReferencesoverride that triggersUpdateWidget()when a new layer is assigned, ensuring the JS-side widget is updatedStateHasChanged()calls withInvokeAsync(StateHasChanged)inMapViewfor thread safetyJsComponentReferenceandCoreJsModuleinLayerandWidgetupdate methodsHow this supports Pro SketchWidget changes
The Pro
SketchWidgetallows users to specify aGraphicsLayerby reference, byGraphicsLayerId, or via the baseLayer/LayerIdparameters. When a layer is added programmatically after the map renders (a common pattern), the widget previously had no way to discover its layer had become available.These Core changes provide the infrastructure for that scenario:
MapViewdetects late-added layers and notifies widgets whoseLayerIdmatchesWidget.UpdateGeoBlazorReferencestriggers a JS-sideupdateComponentcall when a new layer is assignedLayerIdlets SketchWidget override it to sync withGraphicsLayerIdOnParametersSetpropagation ensures layer references flow down the component tree without requiring explicit wiringThe Pro SketchWidget overrides
UpdateGeoBlazorReferencesto syncGraphicsLayerfrom the incoming layer, then relies on the baseWidgetimplementation to push the update to JavaScript.Test plan
GraphicsLayeris set as a direct child parameterGraphicsLayerIdis set and the layer is added before the widget rendersLayerIdis set and the layer is added after the widget renders (the race condition fix)StateHasChanged→InvokeAsync(StateHasChanged)change)🤖 Generated with Claude Code