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

📝 [Proposal]: We need partial render! #3297

Open
3 tasks done
vmpartner opened this issue Jan 29, 2025 · 2 comments
Open
3 tasks done

📝 [Proposal]: We need partial render! #3297

vmpartner opened this issue Jan 29, 2025 · 2 comments

Comments

@vmpartner
Copy link

Feature Proposal Description

We have amazing gofiber + htmx + sse. We can send partial template on each update via SSE
Example how it can be reached now:

app.Get("/", func (c fiber.Ctx) error {
  return c.SendStreamWriter(func(w *bufio.Writer) {
   for {
    data := getLiveData()
    buf := new(bytes.Buffer)
    c.App().Config().Views.Render(buf, "my-live-partial-template", data) // hack for partial render
    w.WriteString(buf)
    time.Sleep(5*time.Second)
   }
  })
})

I propose that we can add method RenderToWriter(w *bufio.Writer, templateName string, data fiber.Map, layoutName string)

app.Get("/", func (c fiber.Ctx) error {
  return c.SendStreamWriter(func(w *bufio.Writer) {
   for {
    data := getLiveData()
    c.RenderToWriter(w, "my-live-partial-template", data)
    time.Sleep(5*time.Second)
   }
  })
})

Alignment with Express API


HTTP RFC Standards Compliance


API Stability


Feature Examples

app.Get("/", func (c fiber.Ctx) error {
  return c.SendStreamWriter(func(w *bufio.Writer) {
   for {
    data := getLiveData()
    c.RenderToWriter(w, "my-live-partial-template", data)
    time.Sleep(5*time.Second)
   }
  })
})

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have searched for existing issues that describe my proposal before opening this one.
  • I understand that a proposal that does not meet these guidelines may be closed without explanation.
Copy link

welcome bot commented Jan 29, 2025

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@grivera64
Copy link
Member

grivera64 commented Jan 29, 2025

+1 This sounds like a great idea. Due to the way SSE and c.SendStreamWriter() works, this might require two separate endpoints to work but seems do-able. Do you have a full working example using c.SendStreamWriter() on hand?

A problem we could potentially have with this is that a fiber.Ctx isn't considered safe to use from inside of c.SendStreamWriter() (not sure if this is mentioned in the docs). Reading could potentially be fine, but writing will cause issues from my experience working on the SendStreamWriter feature. If we were to add this method to the fiber.Ctx interface, then it may give a false impression that other Ctx methods would work here too (including ones that write to the response).

If possible, we may want to add this functionality to a different interface to avoid that confusion.

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

No branches or pull requests

2 participants