Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow patching of react.createElement #897

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

intergalacticspacehighway
Copy link

Issue

Analytics libraries like datadog patch React.createElement to override onPress prop for tracking. Here

Although, not a huge fan of the approach taken here by the datadog library as alternate solutions exist. But I think react-native-css-interop should support such a usecase as the original React.createElement doesn't prevent patching.

Approach

RN CSS interop uses named import createInteropElement to replace createElement, this prevents patching, as babel transpiles such imports to read-only. The approach taken in this PR is to use namespace imports. e.g. createElement will become ReactNativeCSSInterop.createInteropElement. Such an import is not considered read-only and users can perform patching ReactNativeCSSInterop.createInteropElement = () => {}

Note

This PR is a partial solution to allow patching React.createElement. NativeWind's current tsc approach to build distribution packages generates below output. This output lacks ability to mutate createInteropElement as it only has a getter in Object.define, no writable. I think we should distribute packages with esnext module preset in tsconfig or use expo module scripts for distribution builds. Would love to know your thoughts on this.

Screenshot 2024-04-29 at 8 56 16 PM

Copy link

vercel bot commented Apr 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nativewind ✅ Ready (Inspect) Visit Preview Apr 29, 2024 4:19pm

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.

None yet

1 participant