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

html! seems to decapitalize case-sensitive SVG element tag. #3031

Closed
JmsPae opened this issue Dec 11, 2022 · 5 comments
Closed

html! seems to decapitalize case-sensitive SVG element tag. #3031

JmsPae opened this issue Dec 11, 2022 · 5 comments
Labels

Comments

@JmsPae
Copy link

JmsPae commented Dec 11, 2022

Problem

<g ref={self.group_ref.clone()} transform={format!("translate({} {})", props.geometry.x-(sx/2), props.geometry.y-(sy/2))}>
          
    <rect ref={self.svg_ref.clone()}  
        width={sx.to_string()} height={sy.to_string()} 
        rx=5
        style="fill:white; stroke:grey; stroke-width:1"></rect>

    <image href="static/person-40.png" height="40" width="40" x="5" y="5"></image>

    <foreignObject x="45" y="0" width="100" height="100">
        <div >
            {"Test!"}
        </div>
    </foreignObject>
    
</g> 

Results in a box with the image, but the foreignObject doesn't show. The html output in the inspector looks like so:
image

SVG tags are case-sensitive, explaining why this wouldn't work. However, after either 1. adding the foreignObject via groupref.set_inner_html() or 2. modifying the element in the browser, the text displays just fine.

I can imagine that either there's a bug/im messing something up or somewhere along the the way yew de-capitalizes the element tags, which does make a degree of sense but makes this particular instance really bothersome.

Environment:

  • Yew version: v0.20
  • Rust version: 1.65.0
@JmsPae JmsPae added the bug label Dec 11, 2022
@WorldSEnder
Copy link
Member

Since #2699, this is documented. Seeing it pop up from time and time again though, so we should perhaps change this to a different default and preserve the user-casing. The workaround in the linked issue should work though.

@JmsPae
Copy link
Author

JmsPae commented Dec 11, 2022

Since #2699, this is documented. Seeing it pop up from time and time again though, so we should perhaps change this to a different default and preserve the user-casing. The workaround in the linked issue should work though.

I see, thank you. That seems to have gotten the foreignObject tag to work, but I've seem to have come across another problem.

fn view(&self, _ctx: &Context<Self>) -> Html {
        let props = _ctx.props();
        
        let sx = 200;
        let sy = 50;

        html! {
            <g ref={self.group_ref.clone()} transform={format!("translate({} {})", props.geometry.x-(sx/2), props.geometry.y-(sy/2))}>
            
                <rect ref={self.svg_ref.clone()}  
                    width={sx.to_string()} height={sy.to_string()} 
                    rx=5
                    style="fill:white; stroke:grey; stroke-width:1"></rect>

                <image href="static/person-40.png" height="40" width="40" x="5" y="5"></image>


                <@{"foreignObject"} ref={self.text_ref.clone()} x="45" y="0" width="100" height="100"> // This now shows up properly in the inspector
                    <div>
                        {"Test!"} // Doesn't work.
                    </div>
                </@>
                
            </g>
        }
    }
    
    fn rendered(&mut self, _ctx: &Context<Self>, first_render: bool) {
        if (first_render) {
            let textelem = self.text_ref.cast::<Element>().unwrap();
            textelem.set_inner_html("<div>Test!</div>"); //_Now, it works._
        }
    } 

The div element and the contained text seem to not want to work unless I do the hack down in rendered. No clue what would cause this, I've also tried variables as well as the {"Test!"}.

@JmsPae JmsPae closed this as completed Dec 11, 2022
@JmsPae
Copy link
Author

JmsPae commented Dec 11, 2022

Closed due to the original problem being resolved, still having trouble.

@WorldSEnder
Copy link
Member

Can you open a specific issue about the new problem you are facing? I believe the handling of leaving the context of <svg> elements is wrong, and the <div> is erroneously created in the http://www.w3.org/2000/svg XML namespace, instead of the correct HTML one.

@JmsPae
Copy link
Author

JmsPae commented Dec 11, 2022

Can you open a specific issue about the new problem you are facing? I believe the handling of leaving the context of <svg> elements is wrong, and the <div> is erroneously created in the http://www.w3.org/2000/svg XML namespace, instead of the correct HTML one.

Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants