yewstack / yewstack/yew

Allow fragment to be created dynamically with the empty string

Open
#2,174 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-yew-macro feature-request
Dominant language
Rust
Stars
32.8k
Forks
1.5k
Avg merge
5h 34m
Merged PRs (30d)
2

Description

Problem
Intuitively, <@{tag_name}> </@> should create a fragment when tag_name is the empty string. Or at least, when tag_name is an empty string literal, the html! macro should panic at compile-time, which is consistent behavior with existing code (unexpected string literal input as a dynamic tag name panics at compile time):

https://github.com/yewstack/yew/blob/991abab7e1e7b6a27dba8ed6a0ceeabaf36b6a81/packages/yew-macro/tests/html_macro_test.rs#L12-L30

Steps To Reproduce

// main.rs
use yew::{prelude::*};

#[function_component(MyComponent)]
fn my_component() -> Html {
    html! {
        <@{""}/>
    }
}

fn main() {
    yew::start_app::<MyComponent>();
}

Then run trunk serve with the template index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>New Title</title>
</head>

</html>

This passes compilation and panics at runtime on app start.
from the developer console in the browser:
image

Environment:

  • Yew version: [master]

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/yew-macro/tests/html_macro_test.rs, especially the existing dynamic-tag cases linked in the issue, and reproduce the example using an empty string tag. Trace how the html! macro handles that input and add coverage showing the chosen consistent behavior: fragment creation or compile-time panic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.