Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Remove logs from UI library #21

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
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
5 changes: 5 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { server } from "@/tools-test/mocks/server";
import { mockUseUserId, mockUseUserIdData } from "@/tools-test/mocks/userId.mock";
import { mockUseWalletInfo, mockUseWalletInfoData } from "@/tools-test/mocks/walletInfo.mock";

/**
* @dev temporary removing some logs.
*/
require("./tools/removeLogs");

Copy link
Member

Choose a reason for hiding this comment

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

We should not mix require and import. You can use an import here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
global.ArrayBuffer = ArrayBuffer;
Expand Down
5 changes: 5 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const nextConfig = {

module.exports = nextConfig;

/**
* @dev temporary removing some logs in server.
*/
require("./tools/removeLogs");

// Injected content via Sentry wizard below

// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down
5 changes: 5 additions & 0 deletions src/app/[locale]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"use client";

/**
* @dev temporary removing some logs in client.
*/
import("@/tools/removeLogs");

Comment on lines +3 to +7
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 that we should parse errors only for tests. I'm not convinced doing that at runtime for the client.

Copy link
Member

Choose a reason for hiding this comment

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

Even for the server

import Image from "next/image";
import styles from "./page.module.css";
import ThemeSelector from "@/components/ThemeSelector";
Expand Down
32 changes: 32 additions & 0 deletions tools/removeLogs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @dev We are removing error and warning logs from `@ledgerhq/react-ui`.
*/
const originalError = console.error;
const originalWarn = console.warn;

const EXCLUDED_ERRORS = [
"If you accidentally passed it from a parent component, remove it from the DOM element.",
"You provided a `checked` prop to a form field without an `onChange` handler.",
];

const EXCLUDED_WARNINGS = [
" is being sent through to the DOM, which will likely trigger a React console error.",
];

console.error = (...args) => {
const error = args.join();
if (EXCLUDED_ERRORS.some((excluded) => error.includes(excluded))) {
return;
}
originalError.call(console, ...args);
};

console.warn = (...args) => {
const warning = args.join();
if (EXCLUDED_WARNINGS.some((excluded) => warning.includes(excluded))) {
return;
}
originalWarn.call(console, ...args);
};

module.exports = {};
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@/components/*": ["./src/components/*"],
"@/styles/*": ["./src/styles/*"],
"@/redux/*": ["./src/redux/*"],
"@/tools/*": ["./tools/*"],
"@/tools-test/*": ["./tools/test/*"],
"@/hooks/*": ["./src/hooks/*"]
}
Expand Down