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(GlobalLoader): render in StrictMode #3582

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions packages/react-ui/components/GlobalLoader/GlobalLoader.tsx
SchwJ marked this conversation as resolved.
Show resolved Hide resolved
SchwJ marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type DefaultProps = Required<
>
>;

let currentGlobalLoader: GlobalLoader;
let currentGlobalLoader: GlobalLoader | null;

/**
* Глобальный лоадер `GlobalLoader` — это универсальный индикатор обмена данными с сервером.
Expand Down Expand Up @@ -132,6 +132,10 @@ export class GlobalLoader extends React.Component<GlobalLoaderProps, GlobalLoade
}
}

componentWillUnmount(): void {
currentGlobalLoader = null;
}

componentDidUpdate(prevProps: Readonly<GlobalLoaderProps>) {
const { expectedResponseTime, rejected, active } = this.getProps();
if (expectedResponseTime !== prevProps.expectedResponseTime) {
Expand Down Expand Up @@ -183,9 +187,9 @@ export class GlobalLoader extends React.Component<GlobalLoaderProps, GlobalLoade
* @public
*/
public static start = (expectedResponseTime?: number) => {
currentGlobalLoader.setActive();
currentGlobalLoader?.setActive();
if (typeof expectedResponseTime === 'number') {
currentGlobalLoader.updateExpectedResponseTime(expectedResponseTime);
currentGlobalLoader?.updateExpectedResponseTime(expectedResponseTime);
}
};

Expand All @@ -196,7 +200,7 @@ export class GlobalLoader extends React.Component<GlobalLoaderProps, GlobalLoade
* @public
*/
public static done = () => {
currentGlobalLoader.setDone();
currentGlobalLoader?.setDone();
};

/**
Expand All @@ -206,7 +210,7 @@ export class GlobalLoader extends React.Component<GlobalLoaderProps, GlobalLoade
* @public
*/
public static reject = () => {
currentGlobalLoader.setReject(true);
currentGlobalLoader?.setReject(true);
};

/**
Expand All @@ -216,7 +220,7 @@ export class GlobalLoader extends React.Component<GlobalLoaderProps, GlobalLoade
* @public
*/
public static accept = () => {
currentGlobalLoader.setReject(false);
currentGlobalLoader?.setReject(false);
};

public setActive = () => {
Expand Down