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: fix svg for transform #6987

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/orange-needles-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rax-compat': patch
---

fix: fix svg
2 changes: 1 addition & 1 deletion packages/rax-compat/src/compat/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function createJSXElementFactory(factory: typeof ElementFactory) {
// Compat for props.
if (isRealDOM) {
// Only the dom needs to be transformed, not the components.
rest = transformProps(rest);
rest = transformProps(type, rest);

// Delete props on real dom that are not allowed in react.
delete rest.onAppear;
Expand Down
21 changes: 13 additions & 8 deletions packages/rax-compat/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
return key.indexOf('on') === 0;
}

function transformProps(props: ComponentProps<JSXElementConstructor<any>>): Record<string, any> {
function transformProps(type: string, props: ComponentProps<JSXElementConstructor<any>>): Record<string, any> {
const transformedProps: Record<string, any> = {};
Object.keys(props).forEach((propKey: string) => {
let key: string = propKey;
Expand All @@ -21,18 +21,23 @@
// etc...
if (isEventLikeProp(lowerCasedPropKey)) {
if (registrationNameToReactEvent.has(lowerCasedPropKey)) {
const reactEvent: string = registrationNameToReactEvent.get(lowerCasedPropKey);
const reactEvent: string = registrationNameToReactEvent.get(lowerCasedPropKey) || '';
if (reactEvent !== propKey) {
key = reactEvent;
}
}
// eslint-disable-next-line no-prototype-builtins
} else if (possibleStandardNames.hasOwnProperty(lowerCasedPropKey)) {
// Transform attribute names that make it works properly in React.
key = possibleStandardNames[lowerCasedPropKey];
} else {
// Handles component props from rax-components like resizeMode, this causes React to throw a warning.
key = lowerCasedPropKey;
}

const needTransform = (type !== 'svg');
if (needTransform) {
if (possibleStandardNames.hasOwnProperty(lowerCasedPropKey)) {

Check warning on line 34 in packages/rax-compat/src/props.ts

View workflow job for this annotation

GitHub Actions / build (16.x, ubuntu-latest)

Do not access Object.prototype method 'hasOwnProperty' from target object

Check warning on line 34 in packages/rax-compat/src/props.ts

View workflow job for this annotation

GitHub Actions / build (16.x, windows-latest)

Do not access Object.prototype method 'hasOwnProperty' from target object

Check warning on line 34 in packages/rax-compat/src/props.ts

View workflow job for this annotation

GitHub Actions / build (18.x, ubuntu-latest)

Do not access Object.prototype method 'hasOwnProperty' from target object

Check warning on line 34 in packages/rax-compat/src/props.ts

View workflow job for this annotation

GitHub Actions / build (18.x, windows-latest)

Do not access Object.prototype method 'hasOwnProperty' from target object
// Transform attribute names that make it works properly in React.
key = possibleStandardNames[lowerCasedPropKey];
} else {
// Handles component props from rax-components like resizeMode, this causes React to throw a warning.
key = lowerCasedPropKey;
}
}

transformedProps[key] = val;
Expand Down
Loading