Skip to content

Conversation

@Inrixia
Copy link
Owner

@Inrixia Inrixia commented Jan 25, 2026

Adds ability for intercepting and modifying react Render calls. Better way to modify components and elements than dom manipulation

});

/**
* Intercept a React Componoent Render based on its `ElementType`
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "Componoent" → "Component"

* **WARNING!** `cb` is called on every render for `ElementType`, only use this if you know what you are doing. This is performance critical code.
* @param elementType The React HTMLElementType to intercept
* @param cb Called when render is intercepted with props, if returning false element is not rendered
* @param unloads Set of unload functions to add this to, can be nullish but only if you know what your doing
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: "your doing" → "you're doing"

Comment on lines +34 to +41
jsxRuntime.jsx = function (type, props, key) {
if (typeof type === "string") return interceptJSX(false, type, props, key)!;
return renderJSX(type, props, key);
};
jsxRuntime.jsxs = function (type, props, key) {
if (typeof type === "string") return interceptJSX(true, type, props, key)!;
return renderJSXS(type, props, key);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

When type is a string but no interceptor is registered for that element type, interceptJSX returns undefined. The ! non-null assertion hides this, but the element won't be rendered at all.

Should it fallback to renderJSX/renderJSXS when interceptJSX returns undefined?

jsxRuntime.jsx = function (type, props, key) {
      if (typeof type === "string") {
            const result = interceptJSX(false, type, props, key);
            if (result !== undefined) return result;
      }
      return renderJSX(type, props, key);
};

Copy link
Owner Author

Choose a reason for hiding this comment

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

Returning undefined cancels the render, or renders nothing. But jsx doesn't like undefined as a return type.

Using ! was easy. Maybe I'll try ?? null if it doesn't complain

@vMohammad24
Copy link
Contributor

no way my code getting pr'd?! w

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants