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 2 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.
*/
require("../../../tools/removeLogs");
Copy link
Contributor

Choose a reason for hiding this comment

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

You can't use alias? :)

Copy link
Contributor Author

@sshmaxime sshmaxime Sep 22, 2023

Choose a reason for hiding this comment

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

Sadly no, it doesn't work in test ... Idk why. Look at my second commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

if you do

Suggested change
require("../../../tools/removeLogs");
import "@/tools/removeLogs"

This don't works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok when doing that I had an error saying that the file wasn't a module so I just added module.exports = {} and it worked. Cool, thanks for the heads up @mcayuelas-ledger !


import Image from "next/image";
import styles from "./page.module.css";
import ThemeSelector from "@/components/ThemeSelector";
Expand Down
30 changes: 30 additions & 0 deletions tools/removeLogs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @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);
};
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