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

Allow overriding xmlns #268

Merged
merged 5 commits into from
Nov 7, 2023
Merged

Allow overriding xmlns #268

merged 5 commits into from
Nov 7, 2023

Conversation

canadaduane
Copy link
Contributor

@canadaduane canadaduane commented Nov 3, 2023

A foreignObject element within an svg tag should not lose its SVG_NAMESPACE, because it is still an SVG element.

In addition, children of a foreignObject element should be allowed to specify their xmlns, since it is likely they will be of some other namespace than the foreignObject, e.g. a child div would need to be xhtml.

This PR allows such child elements to specify their xmlns, when needed.

A foreignObject within an svg tag should not lose its SVG_NAMESPACE,
because it is still an SVG element.

In addition, children of a foreignObject element should be allowed to
specify their xmlns, since it is likely they will be some other NS than
the foreignObject, e.g. xhtml.

This PR allows elements to specify their xmlns, when needed.
canadaduane added a commit to canadaduane/mindspace that referenced this pull request Nov 4, 2023
Note: requires tweaking crank.js to accept xmlns:

bikeshaving/crank#268
@brainkim
Copy link
Member

brainkim commented Nov 7, 2023

Thank you for being proactive with this PR! I will review it ASAP and I apologize about any blockers.

Copy link
Member

@brainkim brainkim left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Some general thoughts:

  • I’m not overly familiar with the way the xmlns attribute is meant to work, and there is no corresponding MDN page. I’m curious about the use-case / difficulties you’re running into.
  • The natural place for tests would be test/svg.tsx
  • If there are broader implications for how xmlns attribute should work outside of foreignObject there might be some additional work that we have to do in the create() method? Maybe not?

src/dom.ts Outdated Show resolved Hide resolved
src/dom.ts Outdated Show resolved Hide resolved
src/dom.ts Show resolved Hide resolved
src/dom.ts Outdated
xmlns = undefined;
break;
case "svg":
xmlns = SVG_NAMESPACE;
break;
}

return xmlns;
return props?.xmlns ?? xmlns;
Copy link
Member

Choose a reason for hiding this comment

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

The optional chain operator ?. is unnecessary because props will always be defined. And as a stylistic thing, I’d prefer a boolean short-circuit over a nullish coalescing operator ?? insofar as the codebase doesn’t use it yet.

@canadaduane
Copy link
Contributor Author

Ok, updated based on your comments @brainkim. Thanks for the feedback & for considering this change.

Copy link
Member

@brainkim brainkim left a comment

Choose a reason for hiding this comment

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

Ahhh, I’m getting a better sense of the problem. My assumption when throwing together <foreignObject> support was that the element took an xmlns attribute <foreignObject xmlns="whatever">, and its children would all be under one namespace or another. But normal behavior is to assume the children are SVG.

So there doesn’t need to be special casing for the foreignObject element, and we can rely on the xmlns prop.

TODO (for me):

@brainkim
Copy link
Member

brainkim commented Nov 7, 2023

F- IT, I’LL FIX THE LINT ERROR ON MAIN

@brainkim brainkim merged commit 896d10c into bikeshaving:master Nov 7, 2023
1 check failed
@brainkim
Copy link
Member

brainkim commented Nov 7, 2023

Shipped in 0.5.6

@canadaduane
Copy link
Contributor Author

Thanks!

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.

2 participants