seasketch / azores-nearshore-reports

0 stars 1 forks source link

Switching back and forth on subregions causes null ReportResult data #12

Closed avmey closed 1 year ago

avmey commented 1 year ago

Switching from one subregion to another and then back to the first one will inconsistently throw an error or crash the report.

TypeError: e.metrics is undefined. Geomorphology.tsx:59

This error is sometimes not thrown, and it can also be thrown by any of the reports, at the first point of attempt to use the data variable of type ReportResult passed from the lambda. Unsure whether this is an issue with the reports trying to update the UI components before the cached result can be fully loaded. Seems to occur more frequently when a subregion is selected which has no overlap with the sketch, and then the subregion is switched back to a previously used subregion.

twelch commented 1 year ago

Yes, switching as it relates to network requests is not a heavily tested area, specifically lambda request aborting. Code has always been there to handle it, but the code path was probably never really exercised because the seasketch user would just load reports once, then maybe close them, and load them again (new iframe). Fixing the server-side report caching, might also be bringing back some code execution paths that haven't been used in a couple years.

useEffect in the useFunction hook contains the following:

    // Upon teardown any outstanding requests should be aborted. This useEffect
    // cleanup function will run whenever geometryUri, sketchProperties,
    // functionTitle or extraParams are changed, or if the component is being
    // unmounted
    return () => {
      abortController.abort();
    };

I'd be curious to watch you reproduce. I wonder if you have to switch away from and back to the first region, before the first region results come back from the lambda call (whether cached server-side or not). In theory the first lambda request should abort on switch, and would be good to confirm that happens, and then what both caches are set to in that case.

Let's be clear which cache is meant going forward (browser in-memory report cache in useFunction hook, or dynamodb report cache). I could see either being a culprit here.

What does the report result look like in this case that's coming back to the ResultsCard? Is it really a null as you mention, or undefined? And is a lambda request actually returning null for the data value in its payload, or just the local report cache?

twelch commented 1 year ago

@avmey please try out @seasketch/geoprocessing@3.0.1-alpha.20 and see if the issue is resolved. Should be nothing to do on your part but install, build, and re-deploy.

avmey commented 1 year ago

@seasketch/geoprocessing@3.0.1-alpha.20 resolves this issue