Invite-Only Early Access — Think Throo GitHub App is currently invite-only. Request access here.
2025May

EMPTY_OBJ in Inferno.Js source code.

In this article, we review a variable, EMPTY_OBJECT, in Inferno.js source code. I am making an attempt to understand the internals of Inferno.js and in doing so, I came across this variable shown in the below code.

I use documentation as my starting point to set a direction to my research in studying a new, oss codebase. With that said, I found the below code snippet in Getting Started.

import { render } from 'inferno';
 
const message = "Hello world";
 
render(
  <MyComponent message={ message } />,
  document.getElementById("app")
);

I was going to study the create-inferno-app CLI but I feel like I have done enough research on this as I studied the internals of Shadcn CLI.

Coming back to render method, to locate this method in the codebase, Inferno codebase is a monorepo and is managed using lerna. You can confirm this by checking out lerna.json.

Locating the render method

You can search for the inferno package name in the packages folder. Most of the time, folder names inside packages folder match their package.json name.

{
  "name": "inferno",
  "version": "9.0.3",
  "license": "MIT",
  "type": "module",

In the inferno/src/DOM/rendering.ts, you will find the render method.

export function render(
  input: VNode | InfernoNode,
  parentDOM: ParentDOM,
  callback: (() => void) | null = null,
  context: ContextObject = EMPTY_OBJ,
): void {
  renderInternal(input, parentDOM, callback, context);
}

Finally, this is where you will see EMPTY_OBJ used. It is used as a fallback value, in case the context is not passed. Can you guess what EMPTY_OBJ value is?

// We need EMPTY_OBJ defined in one place.
// It's used for comparison, so we can't inline it into shared
export const EMPTY_OBJ = {};

Yeah, that’s right, it is assigned with {} with a comment explaining why it is needed in one place.

About me:

Hey, my name is Ramu Narasinga. Email: ramu.narasinga@gmail.com

Tired of AI-generated code that works but nobody understands?

I spent 3+ years studying OSS codebases and wrote 350+ articles on what makes them production-grade. I built an open source tool that reviews your PR against your existing codebase patterns.

Your codebase. Your patterns. Enforced.

Get started for free —thinkthroo.com

References

  1. https://github.com/infernojs/inferno/blob/master/packages/inferno/src/DOM/rendering.ts#L23

  2. https://github.com/infernojs/inferno/blob/master/packages/inferno/src/DOM/utils/common.ts#L13

  3. https://lerna.js.org/

  4. https://github.com/infernojs/inferno/blob/master/lerna.json