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

Please make the streaming consumer easier to work with #249

Open
reubenfirmin opened this issue Dec 5, 2023 · 2 comments
Open

Please make the streaming consumer easier to work with #249

reubenfirmin opened this issue Dec 5, 2023 · 2 comments

Comments

@reubenfirmin
Copy link

reubenfirmin commented Dec 5, 2023

When creating custom components, it's very easy to get attributes and tag properties in the wrong order, which leads you to run into:

java.lang.IllegalStateException: You can't change tag attribute because it was already passed to the downstream
	at kotlinx.html.consumers.DelayedConsumer.onTagAttributeChange(delayed-consumer.kt:16)

This can be avoided by reordering code, but it's ultimately an implementation detail of the library. Please provide either an update to the streaming consumer so that it isn't sensitive to attribute vs content order, or provide an alternate consumer allowing creation of html fragments which is non-streaming.

@reubenfirmin
Copy link
Author

As another example (and I think indicative of this being a design problem), the DSL has:

@HtmlTagMarker
inline fun <T, C : TagConsumer<T>> C.div(classes : String? = null, crossinline block : DIV.() -> Unit = {}) : T = DIV(attributesMapOf("class", classes), this).visitAndFinalize(this, block)

and

@HtmlTagMarker
inline fun FlowContent.div(classes : String? = null, crossinline block : DIV.() -> Unit = {}) : Unit = DIV(attributesMapOf("class", classes), consumer).visit(block)

The latter can be used almost anywhere. The only place that I know the former can be used is strung from the appendHTML() function. The problem with this is that replacing an element (e.g. via htmx) can sometimes result in awkward workarounds to avoid the hierarchy changing, because most custom components are written only with FlowContent in mind.

@reubenfirmin
Copy link
Author

Another example:

This blows up with the above exception:
2024-03-14_13-26

This works fine:
2024-03-14_13-29

So it looks like a simple change in receiver triggers the flush of the tag.

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

No branches or pull requests

1 participant