Clean up Webpack ComponentWrapper
This commit is contained in:
parent
12c9c324a1
commit
886071af4d
|
@ -189,20 +189,16 @@ export function findComponent<T extends object = any>(filter: FilterFn, parse: (
|
||||||
|
|
||||||
if (IS_DEV && !isIndirect) webpackSearchHistory.push(["findComponent", [filter]]);
|
if (IS_DEV && !isIndirect) webpackSearchHistory.push(["findComponent", [filter]]);
|
||||||
|
|
||||||
let noMatchLogged = false;
|
let InnerComponent = null as null | React.ComponentType<T>;
|
||||||
const NoopComponent = (() => {
|
|
||||||
if (!noMatchLogged) {
|
let findFailedLogged = false;
|
||||||
noMatchLogged = true;
|
const WrapperComponent = (props: T) => {
|
||||||
|
if (InnerComponent === null && !findFailedLogged) {
|
||||||
|
findFailedLogged = true;
|
||||||
logger.error(`Webpack find matched no module. Filter: ${printFilter(filter)}`);
|
logger.error(`Webpack find matched no module. Filter: ${printFilter(filter)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return InnerComponent && <InnerComponent {...props} />;
|
||||||
}) as React.ComponentType<T>;
|
|
||||||
|
|
||||||
let InnerComponent = NoopComponent;
|
|
||||||
|
|
||||||
const WrapperComponent = (props: T) => {
|
|
||||||
return <InnerComponent {...props} />;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
WrapperComponent.$$vencordGetter = () => InnerComponent;
|
WrapperComponent.$$vencordGetter = () => InnerComponent;
|
||||||
|
@ -213,7 +209,7 @@ export function findComponent<T extends object = any>(filter: FilterFn, parse: (
|
||||||
Object.assign(InnerComponent, parsedComponent);
|
Object.assign(InnerComponent, parsedComponent);
|
||||||
}, { isIndirect: true });
|
}, { isIndirect: true });
|
||||||
|
|
||||||
if (InnerComponent !== NoopComponent) return InnerComponent;
|
if (InnerComponent !== null) return InnerComponent;
|
||||||
|
|
||||||
return WrapperComponent;
|
return WrapperComponent;
|
||||||
}
|
}
|
||||||
|
@ -236,20 +232,16 @@ export function findExportedComponent<T extends object = any>(...props: string[]
|
||||||
|
|
||||||
if (IS_DEV) webpackSearchHistory.push(["findExportedComponent", props]);
|
if (IS_DEV) webpackSearchHistory.push(["findExportedComponent", props]);
|
||||||
|
|
||||||
let noMatchLogged = false;
|
let InnerComponent = null as null | React.ComponentType<T>;
|
||||||
const NoopComponent = (() => {
|
|
||||||
if (!noMatchLogged) {
|
let findFailedLogged = false;
|
||||||
noMatchLogged = true;
|
const WrapperComponent = (props: T) => {
|
||||||
|
if (InnerComponent === null && !findFailedLogged) {
|
||||||
|
findFailedLogged = true;
|
||||||
logger.error(`Webpack find matched no module. Filter: ${printFilter(filter)}`);
|
logger.error(`Webpack find matched no module. Filter: ${printFilter(filter)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return InnerComponent && <InnerComponent {...props} />;
|
||||||
}) as React.ComponentType<T>;
|
|
||||||
|
|
||||||
let InnerComponent = NoopComponent;
|
|
||||||
|
|
||||||
const WrapperComponent = (props: T) => {
|
|
||||||
return <InnerComponent {...props} />;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
WrapperComponent.$$vencordGetter = () => InnerComponent;
|
WrapperComponent.$$vencordGetter = () => InnerComponent;
|
||||||
|
@ -260,7 +252,7 @@ export function findExportedComponent<T extends object = any>(...props: string[]
|
||||||
Object.assign(InnerComponent, parsedComponent);
|
Object.assign(InnerComponent, parsedComponent);
|
||||||
}, { isIndirect: true });
|
}, { isIndirect: true });
|
||||||
|
|
||||||
if (InnerComponent !== NoopComponent) return InnerComponent;
|
if (InnerComponent !== null) return InnerComponent;
|
||||||
|
|
||||||
return WrapperComponent as React.ComponentType<T>;
|
return WrapperComponent as React.ComponentType<T>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue