Skip to content

Commit

Permalink
Merge branch 'releases/v0.23'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Nov 20, 2023
2 parents 1e98ed5 + 9a7481c commit faf7b05
Show file tree
Hide file tree
Showing 19 changed files with 434 additions and 420 deletions.
24 changes: 7 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,13 @@ jobs:
name: TestResults
path: tests/Unit/TestResults/*.trx

report:
needs: build
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest

steps:
- name: Download test results
uses: actions/download-artifact@v2
with:
name: TestResults

- name: Report tests
uses: dorny/test-reporter@v1
with:
name: Unit tests
path: TestResults/*.trx
reporter: dotnet-trx
- name: Report tests
if: ${{ ! (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) }}
uses: dorny/test-reporter@v1
with:
name: Unit tests
path: tests/Unit/TestResults/*.trx
reporter: dotnet-trx

prerelease:
runs-on: ubuntu-latest
Expand Down
29 changes: 17 additions & 12 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ group net8
source https://api.nuget.org/v3/index.json
storage: none
framework: net8.0
lowest_matching: true
strategy: min

nuget Elmish >= 4.0.1 < 5.0 lowest_matching: true
nuget Microsoft.AspNetCore.Components.WebAssembly >= 8.0.0-rc.2.23480.2
nuget Microsoft.JSInterop.WebAssembly >= 8.0.0-rc.2.23480.2
nuget Microsoft.AspNetCore.Components.Web >= 8.0.0-rc.2.23480.2
nuget Microsoft.Extensions.Http >= 8.0.0-rc.2.23479.6
nuget FSharp.Core >= 6.0 content: none
nuget Elmish >= 4.0.1 < 5.0
nuget Microsoft.AspNetCore.Components.WebAssembly >= 8.0.0
nuget Microsoft.JSInterop.WebAssembly >= 8.0.0
nuget Microsoft.AspNetCore.Components.Web >= 8.0.0
nuget Microsoft.Extensions.Http >= 8.0.0
nuget FSharp.SystemTextJson >= 0.19.13
nuget System.Text.Json >= 8.0.0-rc.2.23479.6
nuget System.Text.Json >= 8.0.0

group build
source https://api.nuget.org/v3/index.json
Expand Down Expand Up @@ -72,6 +75,8 @@ nuget Selenium.WebDriver.ChromeDriver
nuget Swashbuckle.AspNetCore
# nuget Selenium.WebDriver.GeckoDriver.Win64
nuget Unquote
nuget System.Text.Encodings.Web prerelease
nuget System.Text.Json prerelease

group tests-net7
source https://api.nuget.org/v3/index.json
Expand All @@ -90,9 +95,9 @@ source https://api.nuget.org/v3/index.json
storage: none
framework: net8.0

nuget Microsoft.AspNetCore.OpenApi ~> 8.0.0-rc.2.23480.2
nuget Microsoft.AspNetCore.Components.Authorization ~> 8.0-rc.2.23480.2
nuget Microsoft.AspNetCore.Components.WebAssembly ~> 8.0-rc.2.23480.2
nuget Microsoft.AspNetCore.Components.WebAssembly.Authentication ~> 8.0-rc.2.23480.2
nuget Microsoft.AspNetCore.Components.WebAssembly.DevServer ~> 8.0-rc.2.23480.2
nuget Microsoft.AspNetCore.Components.WebAssembly.Server ~> 8.0-rc.2.23480.2
nuget Microsoft.AspNetCore.OpenApi ~> 8.0.0
nuget Microsoft.AspNetCore.Components.Authorization ~> 8.0
nuget Microsoft.AspNetCore.Components.WebAssembly ~> 8.0
nuget Microsoft.AspNetCore.Components.WebAssembly.Authentication ~> 8.0
nuget Microsoft.AspNetCore.Components.WebAssembly.DevServer ~> 8.0
nuget Microsoft.AspNetCore.Components.WebAssembly.Server ~> 8.0
638 changes: 304 additions & 334 deletions paket.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/Bolero.Server/paket.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ dependencies
framework: net6.0
framework: net7.0
framework: net8.0
Microsoft.AspNetCore.Components.Web >= 8.0-rc.2.23480.2
Microsoft.AspNetCore.Components.WebAssembly >= 8.0-rc.2.23480.2
Microsoft.JSInterop.WebAssembly >= 8.0-rc.2.23480.2
Microsoft.AspNetCore.Components.Web >= 8.0
Microsoft.AspNetCore.Components.WebAssembly >= 8.0
Microsoft.JSInterop.WebAssembly >= 8.0
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<Paket>True</Paket>
<Link>paket-files/ProvidedTypes.fs</Link>
</Compile>
<Compile Include="..\Bolero\NodeTypes.fs" Link="NodeTypes.fs" />
<Compile Include="..\Bolero\Attr.fs" Link="Attr.fs" />
<Compile Include="..\Bolero\Node.fs" Link="Node.fs" />
<Compile Include="..\Bolero\Ref.fs" Link="Ref.fs" />
Expand Down
28 changes: 14 additions & 14 deletions src/Bolero.Templating.Provider/Parsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ let ParseAttribute (ownerNode: HtmlNode) (attr: HtmlAttribute) : Parsed =
| _ ->
WithVars parsed.Vars [Attr(name, Concat parsed.Expr)]

let rec ParseNode (node: HtmlNode) : Parsed =
let rec ParseNode (optimizeHtml: bool) (node: HtmlNode) : Parsed =
match node.NodeType with
| HtmlNodeType.Element ->
let name = node.Name
Expand All @@ -317,13 +317,9 @@ let rec ParseNode (node: HtmlNode) : Parsed =
|> Parsed.Concat
let children =
node.ChildNodes
|> Seq.map ParseNode
|> Seq.map (ParseNode optimizeHtml)
|> Parsed.Concat
if HasVars attrs || HasVars children then
(attrs, children)
||> Parsed.Map2 (fun attrs children ->
[Elt (name, attrs, children)])
else
if optimizeHtml && not (HasVars attrs || HasVars children) then
// Node has no vars, we can represent it as raw HTML for performance.
let rec removeComments (n: HtmlNode) =
if isNull n then () else
Expand All @@ -333,15 +329,19 @@ let rec ParseNode (node: HtmlNode) : Parsed =
| _ -> n.Remove()
removeComments nxt
NoVars [PlainHtml node.OuterHtml]
else
(attrs, children)
||> Parsed.Map2 (fun attrs children ->
[Elt (name, attrs, children)])
| HtmlNodeType.Text ->
// Using .InnerHtml and RawHtml to properly interpret HTML entities.
ParseText (node :?> HtmlTextNode).InnerHtml HoleType.Html
| _ ->
NoVars [] // Ignore comments

let ParseOneTemplate (nodes: HtmlNodeCollection) : Parsed =
let ParseOneTemplate (optimizeHtml: bool) (nodes: HtmlNodeCollection) : Parsed =
nodes
|> Seq.map ParseNode
|> Seq.map (ParseNode optimizeHtml)
|> Parsed.Concat

type ParsedTemplates =
Expand All @@ -351,7 +351,7 @@ type ParsedTemplates =
Nested: Map<string, Parsed>
}

let ParseDoc (filename: option<string>) (doc: HtmlDocument) : ParsedTemplates =
let ParseDoc (optimizeHtml: bool) (filename: option<string>) (doc: HtmlDocument) : ParsedTemplates =
let nested =
let templateNodes =
match doc.DocumentNode.SelectNodes("//template") with
Expand All @@ -366,12 +366,12 @@ let ParseDoc (filename: option<string>) (doc: HtmlDocument) : ParsedTemplates =
| null ->
failwith "Nested template must have an id" // at {n.Line}:{n.LinePosition}"
| id ->
let parsed = ParseOneTemplate n.ChildNodes
let parsed = ParseOneTemplate optimizeHtml n.ChildNodes
n.Remove()
(id, parsed)
)
|> Map.ofSeq
let main = ParseOneTemplate doc.DocumentNode.ChildNodes
let main = ParseOneTemplate optimizeHtml doc.DocumentNode.ChildNodes
{ Filename = filename; Main = main; Nested = nested }

/// Get the HTML document for the given type provider argument, either inline or from a file.
Expand All @@ -389,6 +389,6 @@ let GetDoc (fileOrContent: string) (rootFolder: string) : option<string> * HtmlD
Some (Path.GetRelativePath rootFolder fullPath), doc

/// Parse a type provider argument into a set of templates.
let ParseFileOrContent (fileOrContent: string) (rootFolder: string) : ParsedTemplates =
let ParseFileOrContent (fileOrContent: string) (rootFolder: string) (optimizeHtml: bool) : ParsedTemplates =
GetDoc fileOrContent rootFolder
||> ParseDoc
||> ParseDoc optimizeHtml
12 changes: 7 additions & 5 deletions src/Bolero.Templating.Provider/Provider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,20 @@ type Template (cfg: TypeProviderConfig) as this =

do try
let templateTy = ProvidedTypeDefinition(thisAssembly, rootNamespace, "Template", None, isErased = false)
let sp = ProvidedStaticParameter("pathOrHtml", typeof<string>)
sp.AddXmlDoc("The path to an HTML file, or an HTML string directly.")
templateTy.DefineStaticParameters([sp], fun typename pars ->
let pathOrHtmlParam = ProvidedStaticParameter("pathOrHtml", typeof<string>)
pathOrHtmlParam.AddXmlDoc("The path to an HTML file, or an HTML string directly.")
let optimizeHtmlParam = ProvidedStaticParameter("optimizePlainHtml", typeof<bool>, false)
optimizeHtmlParam.AddXmlDoc("Optimize the rendering of HTML segments that don't contain any holes. Warning: this is incompatible with the use of CSS scopes.")
templateTy.DefineStaticParameters([pathOrHtmlParam; optimizeHtmlParam], fun typename pars ->
match pars with
| [| :? string as pathOrHtml |] ->
| [| :? string as pathOrHtml; :? bool as optimizeHtml |] ->
let ty, _ =
cache.GetOrAdd(pathOrHtml, fun key ->
let asm = ProvidedAssembly()
let ty = ProvidedTypeDefinition(asm, rootNamespace, typename, Some typeof<TemplateNode>,
isErased = false,
hideObjectMethods = true)
let content = Parsing.ParseFileOrContent pathOrHtml cfg.ResolutionFolder
let content = Parsing.ParseFileOrContent pathOrHtml cfg.ResolutionFolder optimizeHtml
CodeGen.Populate ty content
asm.AddTypes([ty])
let fileWatcher = content.Filename |> Option.map (watchFileChanges key)
Expand Down
10 changes: 1 addition & 9 deletions src/Bolero/Attr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@

namespace Bolero

open Microsoft.AspNetCore.Components

/// <summary>
/// HTML attribute or Blazor component parameter.
/// Use <see cref="T:Bolero.Html.attr" /> or <see cref="M:Bolero.Html.op_EqualsGreater" /> to create attributes.
/// </summary>
/// <category>HTML</category>
type Attr = delegate of obj * Rendering.RenderTreeBuilder * int -> int

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Attr =

/// <summary>Create an HTML attribute or a component parameter.</summary>
Expand Down
5 changes: 3 additions & 2 deletions src/Bolero/Bolero.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
<!-- <DefineConstants>DEBUG_RENDERER;$(DefineConstants)</DefineConstants> -->
</PropertyGroup>
<ItemGroup>
<Compile Include="Attr.fs" />
<Compile Include="Node.fs" />
<Compile Include="NodeTypes.fs" />
<Compile Include="Router.fs" />
<Compile Include="ProgramRun.fs" />
<Compile Include="Components.fs" />
<Compile Include="Attr.fs" />
<Compile Include="Node.fs" />
<Compile Include="Virtualize.fs" />
<Compile Include="Ref.fs" />
<Compile Include="TemplatingInternals.fs" />
Expand Down
25 changes: 11 additions & 14 deletions src/Bolero/Components.fs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ and [<AbstractClass>]
inherit Component<'model>()

let mutable oldModel = None
let mutable view = Node.Empty()
let mutable view = Node(fun _ _ s -> s)
let mutable runProgramLoop = fun () -> ()
let mutable dispatch = ignore<'msg>
let mutable program = Unchecked.defaultof<Program<'model, 'msg>>
Expand Down Expand Up @@ -231,22 +231,19 @@ and [<AbstractClass>]
| None -> initModel, []

override this.OnAfterRenderAsync(firstRender) =
if firstRender then
runProgramLoop()
if router.IsSome then
this.NavigationInterception.EnableNavigationInterceptionAsync()
else
Task.CompletedTask
else
task {
if firstRender then
runProgramLoop()
if router.IsSome then
do! this.NavigationInterception.EnableNavigationInterceptionAsync()

match routeHash with
| None ->
Task.CompletedTask
| None -> ()
| Some h ->
routeHash <- None
task {
let! elt = this.JSRuntime.InvokeAsync<IJSObjectReference>("document.getElementById", h)
return! elt.InvokeVoidAsync("scrollIntoView")
}
let! elt = this.JSRuntime.InvokeAsync<IJSObjectReference>("document.getElementById", h)
return! elt.InvokeVoidAsync("scrollIntoView")
}

override this.Render() =
view
Expand Down
15 changes: 10 additions & 5 deletions src/Bolero/Node.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ open System
open FSharp.Reflection
open Microsoft.AspNetCore.Components

/// <summary>An HTML fragment.</summary>
/// <category>HTML</category>
type Node = delegate of obj * Rendering.RenderTreeBuilder * int -> int

/// <exclude />
[<Sealed; AbstractClass>]
type Matcher<'T> private () =
Expand All @@ -51,6 +47,7 @@ type Matcher<'T> private () =
let tagReader = FSharpValue.PreComputeUnionTagReader(typeof<'T>)
fun (x: 'T) -> tagReader (box x)

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Node =

/// <summary>Create an empty HTML fragment.</summary>
Expand All @@ -65,7 +62,15 @@ module Node =
/// <seealso cref="M:Bolero.Html.elt" />
let inline Elt name (attrs: seq<Attr>) (children: seq<Node>) = Node(fun comp tb i ->
tb.OpenElement(i, name)
let mutable i = i + 1

match comp with
| :? Component as c ->
match c.CssScope with
| null -> ()
| s -> tb.AddAttribute(i + 1, s)
| _ -> ()

let mutable i = i + 2
for attr in attrs do
i <- attr.Invoke(comp, tb, i)
for node in children do
Expand Down
20 changes: 20 additions & 0 deletions src/Bolero/NodeTypes.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Bolero

open Microsoft.AspNetCore.Components.Rendering

/// <summary>
/// HTML attribute or Blazor component parameter.
/// Use <see cref="T:Bolero.Html.attr" /> or <see cref="M:Bolero.Html.op_EqualsGreater" /> to create attributes.
/// </summary>
/// <category>HTML</category>
type Attr = delegate of obj * RenderTreeBuilder * int -> int

/// <summary>An HTML fragment.</summary>
/// <category>HTML</category>
type Node = delegate of obj * RenderTreeBuilder * int -> int

#if IS_DESIGNTIME
type Component() =
inherit Microsoft.AspNetCore.Components.ComponentBase()
member _.CssScope = ""
#endif
4 changes: 3 additions & 1 deletion src/Bolero/Router.fs
Original file line number Diff line number Diff line change
Expand Up @@ -974,4 +974,6 @@ type RouterExtensions =
/// <returns>An <c>href</c> attribute pointing to the given endpoint.</returns>
[<Extension>]
static member HRef(this: Router<'ep, _, _>, endpoint: 'ep, [<Optional>] hash: string) : Attr =
Attr.Make "href" (this.Link(endpoint, hash))
Attr(fun _ tb i ->
tb.AddAttribute(i, "href", this.Link(endpoint, hash))
i + 1)
6 changes: 4 additions & 2 deletions src/Bolero/paket.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ files
bin/Release/typeproviders/fsharp41/netstandard2.0/Microsoft.AspNetCore.Components.Web.dll ==> typeproviders/fsharp41/netstandard2.0
../Bolero.Html/bin/Release/net6.0/Bolero.Html.dll ==> lib/net6.0
../Bolero.Html/bin/Release/net6.0/Bolero.Html.xml ==> lib/net6.0
../Bolero.Html/bin/Release/net8.0/Bolero.Html.dll ==> lib/net8.0
../Bolero.Html/bin/Release/net8.0/Bolero.Html.xml ==> lib/net8.0
Bolero.targets ==> build
roots.xml ==> build
excludeddependencies
Expand All @@ -27,5 +29,5 @@ dependencies
Microsoft.JSInterop.WebAssembly ~> 7.0
Microsoft.AspNetCore.Components.WebAssembly ~> 7.0
framework: net8.0
Microsoft.JSInterop.WebAssembly >= 8.0-rc.2.23480.2
Microsoft.AspNetCore.Components.WebAssembly >= 8.0-rc.2.23480.2
Microsoft.JSInterop.WebAssembly >= 8.0
Microsoft.AspNetCore.Components.WebAssembly >= 8.0
1 change: 1 addition & 0 deletions src/tpdummy/Microsoft.AspNetCore.Components/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type RenderTreeBuilder =
member _.OpenComponent(_: int, _: Type) : unit = raise (NotImplementedException())
member _.CloseComponent() : unit = raise (NotImplementedException())
member _.AddAttribute(_: int, _: string, _: obj) : unit = raise (NotImplementedException())
member _.AddAttribute(_: int, _: string) : unit = raise (NotImplementedException())
member _.AddContent(_: int, _: string) : unit = raise (NotImplementedException())
member _.AddMarkupContent(_: int, _: string) : unit = raise (NotImplementedException())
member _.OpenRegion(_: int) : unit = raise (NotImplementedException())
Expand Down
3 changes: 2 additions & 1 deletion tests/Remoting.Server/paket.references
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
group tests
FSharp.Core
Swashbuckle.AspNetCore
FSharp.SystemTextJson.Swagger

group tests-net8
Microsoft.AspNetCore.OpenApi
Microsoft.AspNetCore.Components
Microsoft.AspNetCore.Components.WebAssembly
Microsoft.AspNetCore.Components.WebAssembly.Server
FSharp.SystemTextJson.Swagger
System.Text.Encodings.Web
3 changes: 2 additions & 1 deletion tests/Server/Startup.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ type Startup() =
member this.ConfigureServices(services: IServiceCollection) =
services.AddMvc() |> ignore
services.AddServerSideBlazor() |> ignore
services.AddBoleroHost(server = false) |> ignore
services.AddBoleroHost(prerendered = true) |> ignore
services.AddLogging() |> ignore

member this.Configure(app: IApplicationBuilder) =
app
Expand Down
Loading

0 comments on commit faf7b05

Please sign in to comment.