avoid console spam in production
Massimo Melina committed
Jan 8, 2024 at 12:23 UTC
acdf4fdbb7913b2201714d92794e70e5a7cad5dd
4 files changed
+15
-1
admin/src/api.ts
+1
@@ -80,6 +80,7 @@ export function useApiList<T=any, S=T>(cmd:string|Falsy, params: Dict={}, { map,
80
wantArray(data).forEach(msg => {
81
if (!Array.isArray(msg))
82
return console.debug('illegal list packet', msg)
83
+ console.debug('LIST', ...msg)
84
const [op, par] = msg
85
if (op === LIST.ready) {
86
apply.flush()
admin/src/index.ts
+5
-1
@@ -5,6 +5,10 @@ import { createRoot } from 'react-dom/client'
5
import './index.css'
6
import '@hfs/shared/min-crypto-polyfill'
7
import App from './App'
8
+import { disableConsoleDebug } from '@hfs/shared'
9
+
10
+//@ts-ignore
11
+if (import.meta.env.PROD) disableConsoleDebug()
12
13
createRoot(document.getElementById('root')!)
10
- .render( h(StrictMode, {}, h(App)) )
14
+ .render( h(StrictMode, {}, h(App)) )
frontend/src/index.ts
+4
@@ -5,6 +5,10 @@ import { createRoot } from 'react-dom/client'
5
import './index.scss'
6
import '@hfs/shared/min-crypto-polyfill'
7
import App from './App'
8
+import { disableConsoleDebug } from '@hfs/shared'
9
+
10
+//@ts-ignore
11
+if (import.meta.env.PROD) disableConsoleDebug()
12
13
createRoot(document.getElementById('root')!)
14
.render( h(StrictMode, {}, h(App)) )
shared/index.ts
+5
@@ -95,3 +95,8 @@ export function focusSelector(selector: string, root=document) {
95
return true
96
}
97
}
98
+
99
+export function disableConsoleDebug() {
100
+ const was = console.debug
101
+ console.debug = (...args) => (window as any).DEV && was(...args)
102
+}
\ No newline at end of file