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

chore: update module resolution to bundler #1387

Merged
merged 6 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
},
"devDependencies": {
"@polkadot/dev": "^0.79.3",
"@types/jest": "^29.5.12",
"@types/node": "^20.10.5",
"i18next-scanner": "^4.4.0",
"jest": "^29.7.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we adding jest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compiler failing with : Cannot find name 'it'. Do you need to install type definitions for a test runner? Try npm i --save-dev @types/jestornpm i --save-dev @types/mocha. after i changed the node resolution

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is causing problems in others files with the defined custom global jest types referenced in @polkadot/dev-test.

"sinon-chrome": "^3.0.1"
},
"resolutions": {
Expand Down
98 changes: 42 additions & 56 deletions packages/extension-ui/src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,76 +1,62 @@
// Copyright 2019-2024 @polkadot/extension-ui authors & contributor
// SPDX-License-Identifier: Apache-2.0

import type { WithTranslation } from 'react-i18next';
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';

import React from 'react';
import { withTranslation } from 'react-i18next';
import Header from '../partials/Header';
import Button from './Button';
import ButtonArea from './ButtonArea';
import VerticalSpace from './VerticalSpace';

import Header from '../partials/Header.js';
import Button from './Button.js';
import ButtonArea from './ButtonArea.js';
import VerticalSpace from './VerticalSpace.js';

interface Props extends WithTranslation {
interface ErrorBoundaryProps {
children: React.ReactNode;
className?: string;
error?: Error | null;
trigger?: string;
}

interface State {
error: Error | null;
}

const translate = withTranslation();

// NOTE: This is the only way to do an error boundary, via extend
class ErrorBoundary extends React.Component<Props> {
public override state: State = { error: null };

public static getDerivedStateFromError (error: Error): Partial<State> {
return { error };
}
const ErrorBoundary: React.FC<ErrorBoundaryProps> = ({ children, error: propError, trigger }) => {
const { t } = useTranslation();
const [error, setError] = useState<Error | null>(null);

public override componentDidUpdate (prevProps: Props) {
const { error } = this.state;
const { trigger } = this.props;
useEffect(() => {
if (error !== null && trigger) {
setError(null);
}
}, [trigger]);

Check failure on line 27 in packages/extension-ui/src/components/ErrorBoundary.tsx

View workflow job for this annotation

GitHub Actions / pr (lint)

React Hook useEffect has a missing dependency: 'error'. Either include it or remove the dependency array

if (error !== null && (prevProps.trigger !== trigger)) {
this.setState({ error: null });
useEffect(() => {
if (propError) {
setError(propError);
}
}
}, [propError]);

#goHome = () => {
this.setState({ error: null });
const goHome = () => {
setError(null);
window.location.hash = '/';
};

public override render (): React.ReactNode {
const { children, t } = this.props;
const { error } = this.state;

return error
? (
<>
<Header text={t<string, Record<string, string>, string>('An error occurred')} />
<div>
{t('Something went wrong with the query and rendering of this component. {{message}}', {
replace: { message: error.message }
})}
</div>
<VerticalSpace />
<ButtonArea>
<Button
onClick={this.#goHome}
>
{t('Back to home')}
</Button>
</ButtonArea>
</>
)
: children;
if (error) {
return (
<>
<Header text={t('An error occurred')} />
<div>
{t('Something went wrong with the query and rendering of this component. {{message}}', {
replace: { message: error.message }
})}
</div>
<VerticalSpace />
<ButtonArea>
<Button onClick={goHome}>

Check failure on line 51 in packages/extension-ui/src/components/ErrorBoundary.tsx

View workflow job for this annotation

GitHub Actions / pr (lint)

JSX props should not use arrow functions
{t('Back to home')}
</Button>
</ButtonArea>
</>
);
}
}

export default translate(ErrorBoundary);
return <>{children}</>;
};

export default ErrorBoundary;
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"composite": true,
/* FIXME Dropzone is problematic with nodenext resolution */
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "Bundler",
"paths": {
"@polkadot/extension": ["extension/src/index.ts"],
"@polkadot/extension/*": ["extension/src/*.ts"],
Expand Down
Loading
Loading