Skip to content

Commit

Permalink
fix(DialogCheckbox): don't access getters to prevent their side effec…
Browse files Browse the repository at this point in the history
…ts from breaking the component
  • Loading branch information
AAGaming00 committed Oct 4, 2024
1 parent 93c59d8 commit 241b22c
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/components/DialogCheckbox.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC, ReactNode } from 'react';

import { findModule } from '../webpack';
import { findModuleExport } from '../webpack';
import { DialogCommonProps } from './Dialog';
import { FooterLegendProps } from './FooterLegend';

Expand All @@ -18,22 +18,15 @@ export interface DialogCheckboxProps extends DialogCommonProps, FooterLegendProp
onClick?(evt: Event): void;
}

export const DialogCheckbox = Object.values(
findModule((m: any) => {
if (typeof m !== 'object') return false;
for (const prop in m) {
if (m[prop]?.prototype?.GetPanelElementProps) return true;
}
return false;
}),
).find(
(m: any) =>
m?.prototype?.SetChecked &&
m?.prototype?.Toggle &&
m?.prototype?.GetPanelElementProps &&
// beta || stable as of oct 2 2024
(m?.prototype?.render?.toString().includes('="DialogCheckbox"') || (
m.contextType &&
m.prototype?.render.toString().includes('fallback:')
))
// Do not access KeyDown, SetChecked, Toggle here as they are getters and accessing them outside of a render breaks them globally
export const DialogCheckbox = findModuleExport(e =>
e.prototype &&
"GetPanelElementProps" in e?.prototype &&
"SetChecked" in e?.prototype &&
"Toggle" in e?.prototype &&
// beta || stable as of oct 2 2024
(e?.prototype?.render?.toString().includes('="DialogCheckbox"') || (
e.contextType &&
e.prototype?.render?.toString().includes('fallback:')
))
) as FC<DialogCheckboxProps>;

0 comments on commit 241b22c

Please sign in to comment.