Skip to content

Conversation

@JeremS
Copy link
Collaborator

@JeremS JeremS commented Nov 28, 2025

A recent conversation on the Discord mentioned SSE event injection. The way to mitigate this is to split the text that will make the data part of SSE events on end of lines and prefix each line with "data: ". Currently that line splitting is done in each patch function (patch-elements, patch-elements-seq, patch-signals).

In this PR I centralized this line splitting in the one function every patch function depends on and I changed the use of clojure.string/split-lines with a custom function that makes use of String/.lines.

In short, I centralized the line splitting in one place to make sure its mandatory and I optimized the process a bit (especially for text with a lot of EOL).

Cheers,

Copy link
Contributor

@Ramblurr Ramblurr left a comment

Choose a reason for hiding this comment

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

This looks ok, good call using java.lang.String/lines as it'll handle cr / lf / cr lf.

However one quirk of lines() is that it will remove a trailing new line char at the end of the string:

given the input string: hello\nworld\n
What do we expect?

data: hello
data: world

or

data: hello
data: world
data: 

?

@JeremS
Copy link
Collaborator Author

JeremS commented Dec 14, 2025

I would say that trimming the lines isn't an issue and both version (with and without the blank line) will be handled the same by Datastar on the client side.

@JeremS JeremS merged commit d53a4d7 into starfederation:main Dec 14, 2025
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