Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react): fallback on _reactInternals #455

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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