Skip to content

Commit

Permalink
Merge pull request #51 from fsbolero/interactive-render-mode
Browse files Browse the repository at this point in the history
Interactive render mode
  • Loading branch information
Tarmil authored Jan 3, 2024
2 parents 4588137 + 13c2359 commit 2e252b8
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 8 deletions.
11 changes: 11 additions & 0 deletions .build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ let variantsToTest =
$"--html={htmlv}"
$"--hotreload={reloadv}"
]
if (hostv = "bolero") then
for renderk, renderv in [("IntServer", "InteractiveServer");("IntWasm", "InteractiveWebAssembly");("IntAuto", "InteractiveAuto");] do
$"{minik}.{renderk}.{hostk}.{htmlk}.{pwak}", [
"--server"
$"--minimal={miniv}"
$"--hostpage={hostv}"
$"--pwa={pwav}"
$"--html={htmlv}"
$"--hotreload={reloadv}"
$"--render={renderv}"
]
// Client
for htmlk, htmlv in [("Html", "true"); ("NoHtml", "false")] do
for minik, miniv in [("Minimal", "true"); ("Full", "false")] do
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
prerelease:
runs-on: ubuntu-latest
needs: build
if: ${{ github.ref == 'refs/heads/master' }}
if: ${{ github.ref == 'refs/heads/master' || contains(github.ref, 'releases') }}
steps:
- name: Download nupkg
uses: actions/download-artifact@v1
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 0.24

* Fix `--nightly` to use GitHub packages with `--githubUsername` and `--githubToken`.
* [#50](https://github.com/fsbolero/Template/issues/50) Add option `--render` to decide the render mode. Possible values are:
* `Server` for classic server-side mode.
* `WebAssembly` for classic client-side mode.
* `InteractiveServer` for server-side interactive render mode (see https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0).
* `InteractiveWebAssembly` for client-side interactive render mode.
* `InteractiveAuto` for automatic interactive render mode (client-side if available, otherwise server-side while downloading the client-side runtime in the background).

## 0.23

* [#41](https://github.com/fsbolero/Template/issues/41) Fix issue where, when creating a project containing a dash, the solution file uses an underscore in the project path.
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ You can use the following options to customize the project being created:

This is ignored if `server=false`.

* `--render`, `-r`:

Determines the render mode. Can be one of:

* `Server` for classic server-side mode.

* `WebAssembly` for classic client-side mode.

* `InteractiveServer` for server-side interactive render mode (see https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0).

* `InteractiveWebAssembly` for client-side interactive render mode.

* `InteractiveAuto` for automatic interactive render mode (client-side if available, otherwise server-side while downloading the client-side runtime in the background).

This is ignored if `server=false`. Moreover, the `Interactive*` render modes are only compatible with `hostpage=bolero`.

* `--html`, `-ht`:

If `true` (the default), use HTML templates.
Expand Down
4 changes: 4 additions & 0 deletions content/application/.template.config/dotnetcli.host.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"longName": "hostpage",
"shortName": "hp"
},
"render": {
"longName": "render",
"shortName": "r"
},
"pwa": {
"longName": "pwa",
"shortName": "pwa"
Expand Down
33 changes: 33 additions & 0 deletions content/application/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,39 @@
],
"defaultValue":"bolero"
},
"render": {
"type": "parameter",
"isRequired": false,
"description": "The type of rendering to use (ignored if server=false or hostpage!=bolero)",
"dataType": "choice",
"replaces": "RENDER_MODE",
"choices": [
{"choice":"InteractiveServer","description":"Use InteractiveServer render mode"},
{"choice":"InteractiveWebAssembly","description":"Use InteractiveWebAssembly render mode"},
{"choice":"InteractiveAuto","description":"Use InteractiveAuto render mode"},
{"choice":"Server","description":"Use classic server-side mode"},
{"choice":"WebAssembly","description":"Use classic client-side mode"}
],
"defaultValue": "WebAssembly"
},
"isInteractive": {
"type": "computed",
"dataType": "bool",
"value": "(hostpage == \"bolero\" && (render == \"InteractiveServer\" || render == \"InteractiveWebAssembly\" || render == \"InteractiveAuto\"))"
},
"renderServer": {
"type": "generated",
"generator": "switch",
"replaces": "RENDER_SERVER",
"parameters": {
"evaluator": "C++",
"datatype": "string",
"cases": [
{"condition": "(render == \"Server\")", "value": "true"},
{"condition": "(render != \"Server\")", "value": "false"}
]
}
},
"pwa": {
"type": "parameter",
"isRequired": false,
Expand Down
20 changes: 19 additions & 1 deletion content/application/src/Bolero.Template.1.Server/Index.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module Bolero.Template._1.Server.Index

//#if (isInteractive)
open Microsoft.AspNetCore.Components
open Microsoft.AspNetCore.Components.Web
//#endif
open Bolero
open Bolero.Html
open Bolero.Server.Html
Expand Down Expand Up @@ -38,10 +42,24 @@ let page = doctypeHtml {
}
}
//#endif
div { attr.id "main"; comp<Client.Main.MyApp> }
div {
attr.id "main"
//#if (isInteractive)
comp<Client.Main.MyApp> { attr.renderMode RenderMode.RENDER_MODE }
//#else
comp<Client.Main.MyApp>
//#endif
}
boleroScript
//#if (pwa)
script { rawHtml "navigator.serviceWorker.register('service-worker.js');" }
//#endif
}
}
//#if (isInteractive)

[<Route "/{*path}">]
type Page() =
inherit Bolero.Component()
override _.Render() = page
//#endif
26 changes: 21 additions & 5 deletions content/application/src/Bolero.Template.1.Server/Startup.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,28 @@ open Bolero.Templating.Server
let main args =
let builder = WebApplication.CreateBuilder(args)

//#if (hostpage == "razor")
//#if (isInteractive)
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents()
|> ignore
//#elseif (hostpage == "razor")
builder.Services.AddMvc().AddRazorRuntimeCompilation() |> ignore
//#else
builder.Services.AddMvc() |> ignore
//#endif
builder.Services.AddServerSideBlazor() |> ignore
//#if (!minimal)
builder.Services.AddAuthorization()
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie()
|> ignore
//#if (!minimal)
builder.Services.AddBoleroRemoting<BookService>() |> ignore
//#endif
//#if (hostpage != "html")
builder.Services.AddBoleroHost() |> ignore
//#if (isInteractive)
builder.Services.AddBoleroComponents() |> ignore
//#elseif (hostpage != "html")
builder.Services.AddBoleroHost(server = RENDER_SERVER) |> ignore
//#endif
//#if (hotreload_actual)
#if DEBUG
Expand All @@ -50,7 +57,11 @@ let main args =
.UseStaticFiles()
.UseRouting()
.UseAuthorization()
//#if (isInteractive)
.UseAntiforgery()
//#else
.UseBlazorFrameworkFiles()
//#endif
|> ignore

//#if (hotreload_actual)
Expand All @@ -59,7 +70,12 @@ let main args =
#endif
//#endif
app.MapBoleroRemoting() |> ignore
//#if (hostpage == "razor")
//#if (isInteractive)
app.MapRazorComponents<Index.Page>()
.AddInteractiveServerRenderMode()
.AddInteractiveWebAssemblyRenderMode()
.AddAdditionalAssemblies(typeof<Client.Main.MyApp>.Assembly)
//#elseif (hostpage == "razor")
app.MapBlazorHub() |> ignore
app.MapFallbackToPage("/_Host") |> ignore
//#elseif (hostpage == "bolero")
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "0.23",
"version": "0.24-alpha",
"gitCommitIdShortAutoMinimum": 7,
"nuGetPackageVersion": {
"semVer": 2.0
Expand Down

0 comments on commit 2e252b8

Please sign in to comment.