Skip to content

Commit

Permalink
Rework development mode related inferno warnings #1573 #1582 (#1666)
Browse files Browse the repository at this point in the history
* adds checking of variable `SKIP_INFERNO_WARNINGS` to skip warnings
  in non-production mode

* `SKIP_INFERNO_WARNINGS` can be also declared globally for browser
  functionality, or just defined on the process.env in case of node

* FYI: JEST related warning skip about development mode was removed
  with 2ed75dc when fixing #1582, only the skipping of
  minified code warning was in place
  • Loading branch information
p1100i authored Feb 4, 2024
1 parent 35ce542 commit e33158f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions packages/inferno/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2326,4 +2326,6 @@ declare global {
semantics: Inferno.DetailedHTMLProps<Inferno.HTMLAttributes<MathMLElement>, MathMLElement>;
}
}

var SKIP_INFERNO_WARNINGS: string;
}
39 changes: 21 additions & 18 deletions packages/inferno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,30 @@ import { createRef, forwardRef, mountRef } from './core/refs';
export * from './core/types';

if (process.env.NODE_ENV !== 'production') {
// Checks if Inferno is running in jest testing environment.
const testingEnv =
typeof process === 'object' && process.env?.JEST_WORKER_ID !== undefined;
const skipWarnings =
typeof SKIP_INFERNO_WARNINGS !== 'undefined' ||
(typeof process === 'object' &&
(process.env?.SKIP_INFERNO_WARNINGS !== undefined ||
process.env?.JEST_WORKER_ID !== undefined));

// This message informs developers that they are using development mode (can happen
// in production because of bundling mistakes) and, therefore, Inferno is slower
// than in production mode. Skipping the notification for testing mode to keep testing
// console clear.
if (!skipWarnings) {
// This message informs developers that they are using development mode
// (can happen in production because of bundling mistakes) and, therefore,
// Inferno is slower than in production mode.
console.log('Inferno is in development mode.');

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const testFunc = function testFn() {};
console.log('Inferno is in development mode.');
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const testFunc = function testFn() {};

// eslint-disable-next-line
if (!testingEnv && !((testFunc as Function).name || testFunc.toString()).includes('testFn')) {
warning(
"It looks like you're using a minified copy of the development build " +
'of Inferno. When deploying Inferno apps to production, make sure to use ' +
'the production build which skips development warnings and is faster. ' +
'See http://infernojs.org for more details.',
);
// eslint-disable-next-line
if (!((testFunc as Function).name || testFunc.toString()).includes('testFn')) {
warning(
"It looks like you're using a minified copy of the development build " +
'of Inferno. When deploying Inferno apps to production, make sure to use ' +
'the production build which skips development warnings and is faster. ' +
'See http://infernojs.org for more details.',
);
}
}
}

Expand Down

0 comments on commit e33158f

Please sign in to comment.