-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Can't use spaces directly in a class string #121
Comments
I encountered this error, too. I think these are errors from emscripten, via the A workaround is to compile with Rust's native WebAssembly features instead of emscripten. Try compiling like |
Unfortunately I need Emscripten to link against other native dependencies.
|
Just wondering if anyone had any more insights on this one? Not sure what to do next. I don't see any Emscripten errors, but this code just doesn't work. Not sure if it's possible to use wasm32-unknown-unknown and link against native libraries built via Emscripten, but I suspect it isn't. Thanks. |
I did a bit more digging, attempting to create a minimal example. I failed, but in ways that might be enlightening. I speculated that perhaps this was being triggered by the depth of the HTML tree, particularly since I need to update the recursion limit. So I created a tree deeper than the one in my app, but I can't trigger the failures. Likewise, I'm never prompted to up the recursion limit. So what this tells me is that the failure case here is tied to whatever prompts me to up the recursion limit. I am doing a scene-style match in my document body, similar to what happens in the CRM example. Could be that plus the deeper HTML tree. I aven't yet added that to this example. I'll try adding that to my minimal example next, but I thought I'd ask here for guidance. Here's what I have so far. Again, this doesn't trigger the bug, but it does seem to rule out deep HTML trees:
|
Here is the most minimal example I can produce. Note that, in my testing, this example fails with both wasm32-unknown-emscripten and wasm32-unknown-unknown. So that suggests to me this isn't an Emscripten/cargo-web bug. Would really appreciate some help with this one. :) Thanks! |
I've hit this too and have reduced it to spacebars in things which will get lowered by/into tokenlists, e.g. class names |
I've found the solution, at least for me Placing multiple class names into a class string is a syntax error, one has to write See macro code |
Oh, great catch, I wondered if that might be the problem but had no clue
how to go about changing the syntax. Thanks! Is that documented anywhere?
|
I don't know, @deniskolodin might give more information on this I just guesstimated based on the stacktrace and crawled though the source until i found the comment/solution |
I've found that in https://dom.spec.whatwg.org/#interface-domtokenlist:
When you try to use We can fix this footgun in two ways:
I will refocus the PR to fix this spacing problem. Thank you for the investigation tips 👍 |
I actually think this syntax:
should be much preferred to
We should simply suggest the first syntax if we encounter the second IMO (the second should remain an error but with a better message). I'm a little confused as to how it is even possible that both syntaxes pass the type checker? |
I'm fine with deviating the syntax in the macro *if* there's a
close-to-HTML alternative--including plain HTML as a string, pluggable
template engines, etc. Ultimately, I don't know if I'm going to build my
app entirely in Yew, or if I'll export JS functions and call them from a
more traditional front-end. But these odd syntax deviations make me
hesitate to commit to Yew at all, because if I ultimately *do* switch
then I'll need to do lots of work just to go back to HTML, to say
nothing about potentially transitioning to Vue or something else. I
wonder if breaking this project into smaller components might make
sense? Virtual DOM, Rust templating engine, etc. then make Yew a
higher-level integration.
|
@ndarilek that was just personal preference as a js newbie. Definitely open to other suggestions. I'm a bit confused about your concern though... isn't the deviation from "standard html" already significantly large that you can't simply copy/paste into a Vue.js app? Examples: Inline rust comments, inline rust code, etc? |
Sure, if you opt into those features. But say you have a large block of
HTML that is essentially just a layout. It's entirely possible that
large blob of HTML might only have a single escape to Rust code...but it
also needs parenthesized class names, commas before tag closes, etc. So
you have huge blocks of plain HTML that need to be modified before
pasting in.
I don't know. Elm abandons HTML entirely for its own language syntax. If
we're going to be inspired by Elm, why not ditch HTML entirely, instead
of holding onto this awkward thing that isn't quite HTML, isn't quite
Rust, and seems to have a bunch of haphazardly bolted-together ideas
from both?
```
div(class = nav) {
div(class = "brand whatever") {
nav {
...
}
}
}
```
I at least like the braces instead of closing tags, functional syntax,
etc. What we have now is close enough to HTML to make you think it's
compatible, but far enough to not match up.
|
I guess there are two points there:
I think there is definitely benefits for a macro here, at least until rust get's optional I guess a side-question would be to mimick jsx, which is much closer in spirit to the Edit: maybe change the |
Right. I guess a good summary of my issue is that the macro is called
`html!` but its syntax isn't at all HTML. IMO, it'd be better if `html!`
was pure HTML with Rust escape hatches or, failing that, `html!` could
be used for plain HTML snippets and something like `template!` could be
this sort of bolted-together syntax. Then maybe we could have
`mustache!`, `jsx!`, whatever.
And, to be clear since text doesn't convey tone, I'm not upset or trying
to be overly critical. This feels like a project that started as an
experiment, then picked up momentum when folks like me took notice, and
some of you actually contribute! :) I've just been significantly bitten
by thinking "Ah, this html! macro is mostly plain HTML with the ability
to run Rust code and use comments." Then I discover I need to insert
commas, or that classes can't contain spaces, and at the very least it
feels like the macro should have a different name so I don't think I can
paste in a mostly unmodified Bootstrap template and escape to Rust for
the body.
Maybe we should open a new issue for this?
|
I almost think your feature, were it to be added, would be a This is just my personal feeling. I am not overly confused that there is slightly special syntax within The major pain points so far for me:
That's about all I have. |
Fixed with #289 |
If in my render function, I have:
my code runs fine, without errors.
If I change to:
I get the following error:
Note that this change necessitates adding:
#![recursion_limit="128"]
to my crate. I'm wondering if that might be related? It doesn't seem to happen with less deeply-nested templates.
Workaround: use
<tag class=("class-1", "class-2"),>
syntax. See below for the details.The text was updated successfully, but these errors were encountered: