Open
Conversation
Add component injection
3 tasks
Brskt
reviewed
Jan 25, 2026
| }); | ||
|
|
||
| /** | ||
| * Intercept a React Componoent Render based on its `ElementType` |
Contributor
There was a problem hiding this comment.
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 |
Contributor
There was a problem hiding this comment.
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); | ||
| }; |
Contributor
There was a problem hiding this comment.
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);
};
Owner
Author
There was a problem hiding this comment.
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
Contributor
|
no way my code getting pr'd?! w |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds ability for intercepting and modifying react Render calls. Better way to modify components and elements than dom manipulation