Skip to content

Commit

Permalink
fix(react): fallback on _reactInternals (#455)
Browse files Browse the repository at this point in the history
Co-authored-by: Sean Parmelee <sean.parmelee@care.com>
  • Loading branch information
Zidious and seanparmelee committed Feb 11, 2022
1 parent 95dda29 commit 13f9fd0
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions packages/react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ function logFailureMessage(
): void {
// this exists on axe but we don't export it as part of the typescript
// namespace, so just let me use it as I need
const message: string = ((axeCore as unknown) as AxeWithAudit)._audit.data.failureSummaries[
key
].failureMessage(node[key].map(check => check.message || ''));
const message: string = (
axeCore as unknown as AxeWithAudit
)._audit.data.failureSummaries[key].failureMessage(
node[key].map(check => check.message || '')
);

console.error(message);
}
Expand Down Expand Up @@ -208,30 +210,31 @@ function checkAndReport(node: Node, timeout: number): Promise<void> {
}
}
axeCore.configure({ allowedOrigins: ['<unsafe_all_origins>'] });
axeCore.run(n, { reporter: 'v2' }, function (
error: Error,
results: axeCore.AxeResults
) {
if (error) {
return reject(error);
}

results.violations = results.violations.filter(result => {
result.nodes = result.nodes.filter(node => {
const key: string = node.target.toString() + result.id;
const retVal = !cache[key];
cache[key] = key;
return disableDeduplicate || retVal;
axeCore.run(
n,
{ reporter: 'v2' },
function (error: Error, results: axeCore.AxeResults) {
if (error) {
return reject(error);
}

results.violations = results.violations.filter(result => {
result.nodes = result.nodes.filter(node => {
const key: string = node.target.toString() + result.id;
const retVal = !cache[key];
cache[key] = key;
return disableDeduplicate || retVal;
});
return !!result.nodes.length;
});
return !!result.nodes.length;
});

if (results.violations.length) {
logger(results);
}
if (results.violations.length) {
logger(results);
}

resolve();
});
resolve();
}
);
},
{
timeout: timeout
Expand Down Expand Up @@ -286,6 +289,8 @@ function addComponent(component: any): void {
const reactInstanceDebugID = reactInstance._debugID;
const reactFiberInstance = component._reactInternalFiber || {};
const reactFiberInstanceDebugID = reactFiberInstance._debugID;
const reactInternals = component._reactInternals || {};
const reactInternalsDebugID = reactInternals._debugID;

if (reactInstanceDebugID && !components[reactInstanceDebugID]) {
components[reactInstanceDebugID] = component;
Expand All @@ -296,6 +301,9 @@ function addComponent(component: any): void {
) {
components[reactFiberInstanceDebugID] = component;
componentAfterRender(component);
} else if (reactInternalsDebugID && !components[reactInternalsDebugID]) {
components[reactInternalsDebugID] = component;
componentAfterRender(component);
}
}

Expand Down

0 comments on commit 13f9fd0

Please sign in to comment.