jsakamoto / BlazingStory

The clone of "Storybook" for Blazor, a frontend workshop for building UI components and pages in isolation.
https://jsakamoto.github.io/BlazingStory/
Mozilla Public License 2.0
319 stars 15 forks source link

Blazor Server version of BlazingStory? #17

Closed ErikApption closed 7 months ago

ErikApption commented 1 year ago

We have several projects that have some coupling with server-side libraries (yes I know it is an architecture crime) and integrating BlazingStory has been more difficult than expected. Any plans to create a server-side version of BlazingStory? As alternative, we are considering setting up Story Book with a blazor server but was wondering if anyone has figured other solutions.

jsakamoto commented 1 year ago

@ErikApption Thank you for your feedback! I'm considering supporting Blazor Server, but I've not achieved that because I don't have enough time to implement everything! (This is one of my hobby projects 😅) Anyway, I'll challenge myself to add support for Blazor Server by the end of this year.

By the way, there are some limitations, but the Blazing Story can work on the Blazor Server app with some instructions even now.

  1. Create a new Blazor Server app.
  2. Add the BlazingStory preview NuGet package to the Blazor Server project.
  3. Add a HttpClient as a DI service at the Program.cs of the Blazor Server project, like this:
    var serverUrl = builder.Configuration[WebHostDefaults.ServerUrlsKey]?.Split(';').FirstOrDefault() ?? "http://localhost:5000";
    builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(serverUrl) });
  4. Rewrite all of the render-mode attribute settings of the <component> tag helpers in the Pages/_Host.cshtml file from the ServerPrerendered to the Server.
  5. Duplicate the Pages/_Host.cshtml file with a new name Pages/_IFrame.cshtml.
  6. Comment out the line <link rel="stylesheet" href="{Project Name}.styles.css" /> in the Pages/_Host.cshtml file.
  7. Rewrite the @page "/" directive to @page "/iframe.html" in the Pages/_IFrame.cshtml file.

I attached the whole of the sample code below.

The current limitations I've noticed are the following list.

I hope the above information will be helpful for you for a while.

yjmrobert commented 1 year ago

@jsakamoto this is fantastic!

I'd love to help out with this, what were your thoughts on next steps?

jsakamoto commented 9 months ago

@yjmrobert, I'm really sorry to respond late to this issue. I was doing other priority stuff. However, I may be able to start implementing Blazor Server support on Blazing Story. So, I updated the project item below today.

https://github.com/users/jsakamoto/projects/1/views/1?filterQuery=server&pane=issue&itemId=23125917

Currently, I am still trying to decide what I should ask for your help, but if I come up with any ideas, I'll contact you. Thank you for your contributions!

jsakamoto commented 7 months ago

@ErikApption @yjmrobert Blazing Story now officially supports the Blazor Server deployment model.

Please check out the latest preview version, preview 32.

yjmrobert commented 7 months ago

@jsakamoto that's awesome! You should set up the sponsor stuff 😉