Skip to content

WellsLayer: Update loop when using useAbscissaTransform #2698

Description

@Anders2303

When making a Storybook entry for #2696 , I ran into a corner-case where WellsLayer got stuck in an update loop when using the useAbscissaTransform() hook to set up a section-view of the wells-layer:

Relevant code
import volveWellsJson from "../../../../../../example-data/volve_wells.json";
import { useAbscissaTransform } from "../../layers/wells/hooks/useAbscissaTransform";

// ...

const derivedData = /* memoized data derived from volveWellsJson  */
const { transform } = useAbscissaTransform();

const unfoldedWells: Partial<WellsLayerProps> = {
        "@@type": "WellsLayer",
        id: "unfolded-wells",
        data: derivedData,
        section: transform,
        ZIncreasingDownwards: false,
};

const views = React.useMemo<ViewsType>(
        () => ({
            layout: [2, 2] as [number, number],
            viewports: [
                {
                    id: "viewport1",
                    layerIds: ["volve-wells"],
                    viewType: OrbitView,

                    zoom: -1.4790996911498648,
                },
                {
                    id: "viewport2",
                    layerIds: ["volve-wells"],
                    viewType: OrthographicView,
                    zoom: -1.4790996911498648,
                },
                {
                    id: "viewport3",
                    target: [3000, -1500],
                    viewType: SectionView,
                    zoom: -3.5,
                    layerIds: ["unfolded-wells"],
                },
            ],
        }),
        []
    );

// ... the rest is basic subsurface-viewer component stuff

Not a 100% sure exactly what is causing it to loop, but this specific setup causes the wells-layer to get stuck in an update, where !isEqual(props.data, oldProps.data) in WellsLayer::updateState() equates to true. Notably, it will not happen if I define the layer as a class (new WellsLayer((*section-props), instead of a @@type-object. It also only happens when I use the transformer hook. If I just do section: true the loop does not happen...

Digging a little deeper, one specific difference between props.data and oldProps.data is that the old data has changed the well head geometry to have an XYZ coordinate, whereas the original data has an XY coordinate.
This extra coordinate gets added by this line, which mutates the data.

WellsLayer {
  // ...
  private recomputeDataState() {
     let transformedData = data;
     
     // ... 
     
     // Create a state for the section projection of the data, which by default is
     // identical to the original transformed data.
     let sectionData = transformedData;

     // Mutate data to remove duplicates
     checkWells(transformedData);
     
     // ...
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    CeeSolTask owned by Ceetron SolutionsbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions