Bug 1541666 - ensure that actors are alive when calling async API to the server. r=gl

Differential Revision: https://phabricator.services.mozilla.com/D26459

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Yura Zenevich 2019-04-10 00:58:44 +00:00
parent a2e55d282e
commit 46a0026fa6
5 changed files with 53 additions and 30 deletions

View File

@ -108,13 +108,14 @@ class AccessibilityRow extends Component {
}
updateAndScrollIntoViewIfNeeded() {
const { dispatch, member, supports } = this.props;
if (gToolbox) {
dispatch(updateDetails(gToolbox.walker, member.object, supports));
const { dispatch, member: { object }, supports } = this.props;
if (!gToolbox || !object.actorID) {
return;
}
dispatch(updateDetails(gToolbox.walker, object, supports));
this.scrollIntoView();
window.emit(EVENTS.NEW_ACCESSIBLE_FRONT_SELECTED, member.object);
window.emit(EVENTS.NEW_ACCESSIBLE_FRONT_SELECTED, object);
}
flashValue() {

View File

@ -139,9 +139,11 @@ class Accessible extends Component {
update() {
const { dispatch, accessible, supports } = this.props;
if (gToolbox) {
dispatch(updateDetails(gToolbox.walker, accessible, supports));
if (!gToolbox || !accessible.actorID) {
return;
}
dispatch(updateDetails(gToolbox.walker, accessible, supports));
}
setExpanded(item, isExpanded) {

View File

@ -26,7 +26,7 @@ class Provider {
* @returns {Array} arraof of accessible children.
*/
getChildren(accessible) {
if (!accessible || !accessible.actor || accessible.childCount === 0) {
if (!accessible || !accessible.actorID || accessible.childCount === 0) {
return [];
}

View File

@ -3,7 +3,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { FETCH_CHILDREN, RESET, SELECT, HIGHLIGHT } = require("../constants");
const {
FETCH_CHILDREN,
HIGHLIGHT,
RESET,
SELECT,
} = require("../constants");
/**
* Initial state definition
@ -29,6 +34,10 @@ function accessibles(state = getInitialState(), action) {
}
}
function getActorID(accessible) {
return accessible.actorID || accessible._form.actor;
}
/**
* If accessible is cached recursively remove all its children and remove itself
* from cache.
@ -37,7 +46,8 @@ function accessibles(state = getInitialState(), action) {
* @param {Object} accessible Accessible object to remove from cache.
*/
function cleanupChild(cache, accessible) {
const cached = cache.get(accessible.actorID);
const actorID = getActorID(accessible);
const cached = cache.get(actorID);
if (!cached) {
return;
}
@ -46,7 +56,7 @@ function cleanupChild(cache, accessible) {
cleanupChild(cache, child);
}
cache.delete(accessible.actorID);
cache.delete(actorID);
}
/**
@ -58,7 +68,7 @@ function cleanupChild(cache, accessible) {
* @param {Object} accessible Accessible object to test for staleness.
*/
function staleChildren(cache, accessible) {
const cached = cache.get(accessible.actorID);
const cached = cache.get(getActorID(accessible));
if (!cached) {
return false;
}
@ -67,7 +77,7 @@ function staleChildren(cache, accessible) {
}
function updateChildrenCache(cache, accessible, children) {
const { actorID } = accessible;
const actorID = getActorID(accessible);
if (cache.has(actorID)) {
const cached = cache.get(actorID);
@ -88,6 +98,13 @@ function updateChildrenCache(cache, accessible, children) {
return cache;
}
function updateAncestry(cache, ancestry) {
ancestry.forEach(({ accessible, children }) =>
updateChildrenCache(cache, accessible, children));
return cache;
}
/**
* Handles fetching of accessible children.
* @param {Map} cache Previous state maintaining a cache of previously
@ -96,29 +113,29 @@ function updateChildrenCache(cache, accessible, children) {
* @return {Object} updated state
*/
function onReceiveChildren(cache, action) {
const { accessible, response: children, error } = action;
if (error) {
console.warn("Error fetching children", accessible, error);
return cache;
const { error, accessible, response: children } = action;
if (!error) {
return updateChildrenCache(new Map(cache), accessible, children);
}
return updateChildrenCache(new Map(cache), accessible, children);
}
function onReceiveAncestry(cache, action) {
const { accessible: acc, response: ancestry, error } = action;
if (error) {
console.warn("Error fetching ancestry", acc, error);
if (accessible.actorID) {
console.warn(`Error fetching children: `, accessible, error);
return cache;
}
const newCache = new Map(cache);
ancestry.forEach(({ accessible, children }) =>
updateChildrenCache(newCache, accessible, children));
cleanupChild(newCache, accessible);
return newCache;
}
function onReceiveAncestry(cache, action) {
const { error, response: ancestry } = action;
if (error) {
console.warn(`Error fetching ancestry: `, error);
return cache;
}
return updateAncestry(new Map(cache), ancestry);
}
exports.accessibles = accessibles;

View File

@ -35,8 +35,11 @@ function details(state = getInitialState(), action) {
function onUpdateDetails(state, action) {
const { accessible, response, error } = action;
if (error) {
console.warn("Error fetching DOMNode for accessible", accessible, error);
return state;
if (accessible.actorID) {
console.warn(`Error fetching accessible details: `, accessible, error);
}
return getInitialState();
}
const [ DOMNode, relationObjects, audit ] = response;