Commit Graph

334 Commits

Author SHA1 Message Date
Steve Sanderson e71db85149 Handle overlapping events (#1655)
* Add failing unit test to demonstrate overlapping events bug

* Handle overlapping events

* Make RemoteRenderer.UpdateDisplay's return task not complete until client sends explict ACK

* CR: Rename UpdateDisplay to UpdateDisplayAsync

* CR: Fix namespace

* CR: Catch synchronous SendAsync exceptions (if they can happen)
2018-11-13 12:08:08 +00:00
Steve Sanderson 811ef19f57 In E2E tests, allow for slower execution on Travis/AppVeyor 2018-11-13 12:00:24 +00:00
Steve Sanderson dc1ad1943d Capture RenderBatch bytes synchronously. Fixes #1223 2018-11-13 11:34:02 +00:00
Adrian Wright 5e0aa0c0fa Fix typos 2018-11-09 10:17:10 -08:00
Steve Sanderson 0857483a42 Use prebuilt Mono binaries. Remove asm.js fallback (Mono doesn't distribute asm.js builds). 2018-11-07 12:01:50 +00:00
Steve Sanderson f0638877fa Rename "Fixed" to "IsFixed" 2018-10-18 09:57:41 +01:00
Steve Sanderson 7530ad9a26 E2E tests for cascading parameters generally 2018-10-18 09:57:41 +01:00
Steve Sanderson 18df30568c Support "Fixed" mode for <CascadingValue> 2018-10-18 09:57:41 +01:00
Steve Sanderson 4a6f471d12 Add Cascading flag to Parameter (#1564)
... so that components that pass through an arbitrary set of parameters can choose to filter out cascading ones if they want.
2018-10-18 09:37:46 +01:00
Lukas Bickel fb6427a46a escape quotes in event handler attribute content 2018-10-17 14:18:22 -07:00
Steve Sanderson 211ad636fd Cascading parameters (#1545)
* Add Provider component

* Implement discovery and matching rules for tree parameters

* Remove artificial component hierarchy unit tests now they are redundant

* Refactor: Have RenderTreeFrame point to the ComponentState instead of IComponent

... so we can more quickly find associated tree param state without having to do lookups based on the componentId.

Also rename AssignComponentId to AttachAndInitComponent to be more descriptive.

* Refactor: Add shared code path for updating parameters so there's only one place to attach tree parameters

Now framework code should no longer call IComponent.SetParameters directly, except if it knows it's definitely dealing with a root component.

* Refactor: Simplify Parameter by making it hold the name/value directly

This will be necessary for tree parameters, which don't correspond to any RenderTreeFrame

* Refactor: Wrap ParameterEnumerator logic in extra level of iterator so we can also add one for iterating tree params

* Extend ParameterEnumerator to list tree parameters too

* Include tree parameters in SetParameters calls

* Refactor: Move parameter change detection logic into separate utility class

... so we include https://github.com/dotnet/jsinterop/pull/3

* Refactor: Move tree parameter tests from RendererTest.cs their own file

* Have Provider re-render consumers when value changes. Unit tests in next
commit.

* Components that accept tree parameters need to snapshot their direct params for later replay

* Empty commit to reawaken CI

* CR: Make name matching case-insensitive

* Refactor: Rename Provider/TreeParameter to
CascadingValue/CascadingParameter

* Add dedicated [CascadingParameter] attribute. Remove FromTree flag.

* CR: CascadingParameterState cleanups

* CR: Extra unit test

* CR: arguments/parameters

* CR: Enumerator improvements

* Fix test
2018-10-15 11:11:46 +01:00
Steve Sanderson fa2b61773a In ComponentState, track parent ComponentState. Be explicit that Renderer only lets you attach root components. 2018-10-12 09:49:28 +01:00
Ryan Nowak 6f383a0f0f Adds support for 'Context' parameters on components (#1470)
Adds support for 'Context' parameters on components

This change allows you to set the parameter name of a parameterized child content by using the `Context` attribute on the component. The `Context` attribute will be defined (and shown by completion) when the component has one or more declared parameterized (`RenderFragment<>`) child content parameters.

This is nice for cases where you are using implicit child content:

```
<ol>
  <Repeater Items="People" Context="person">
    <li>@person.FirstName</li>
  </Repeater>
</ol>
```

 or, when you have multiple child content elements and want them all to have the same parameter name:

 ```
<MyComponent Items="People" Context="person">
    <ChildContent1><div>@person.FirstName</div></ChildContent1>
    <ChildContent2><div>@person.LastName</div></ChildContent2>
</Repeater>
```

The parameter name can be overridden by using the `Context` parameter on the child content element:

 ```
<MyComponent Items="People" Context="person">
    <ChildContent1 Context="item"><div>@item.FirstName</div></ChildContent1>
    <ChildContent2><div>@person.LastName</div></ChildContent2>
</Repeater>
```

If the component defines a `Context` parameter already then we won't synthesize one - your component's parameter will work exactly as it did before this feature.
2018-09-24 12:22:16 -07:00
KristianJakubik 067d245f94 Fix negative route params. Fixes #1437 2018-09-24 17:55:21 +01:00
Ryan Nowak 5459107832 Fix #1298 (#1309)
* Fix #1298

This change lifts our Razor dependencies to 2.1.1. This is needed
because by default ASP.NET Core projects will depend on 2.1.1 - which
results in a conflict trying to use the Blazor compiler. The Blazor
compiler will load the 2.1.0 msbuild tasks, which then break loading the
2.1.1 tasks.

Since this is happening in the MSBuild process, we can't really write
any code to sort this out. We have to make sure the versions match.

In general the guidance for ASP.NET Core is that projects will **compile
against** 2.1.1 so this won't be a problem in the future unless a user
project specifically lifts ASP.NET Core to a higher version. If that's
the case they will also have to live `Microsoft.AspNetCore.Razor.Design`
to match.
2018-09-21 13:29:40 -07:00
Ryan Nowak 4f51d90157 Fix #1399 - crash on start-end syntax for void element
We weren't correctly recovering when a void element is written as a
start-end pair. This change cleans up some of the plumbing around
end-tag handling and adds recognition for this case.

Added a new bespoke diagnostic for the void element case.
2018-09-21 12:54:44 -07:00
Ryan Nowak 100382bf71 Add Type Inference for Generic-Typed Components
This change allows you to use generic-typed components without
explicitly specify type arguments.

**Before:**
```
<Grid Items="@MyItems" TItem="Person">
...
</Grid>
```

**After:**
```
<Grid Items="@MyItems">
...
</Grid>
```

Where possible, the type of the component will be inferred based on the
values passed to component parameters. This won't work like magic, you
have to specify parameters that provide type arguments for all of the
component's type parameters.

This is a best effort system, and it's largely based on the limitations
and behaviours of generic type inference in C#. We think it will work
well with most Blazor features and for most reasonable components. You
should not forget it's easy to specify type arguments, because you may
still have to in some cases.

In particular you may notice issues if you are trying to use a generic
typed component where all of the parameters are delegates or templates.
Type inference for delegates/lambdas in C# is based on the context. Any
time you combine generics and delegates it's easy to get into a scenario
where the compiler won't infer the correct type, or will give up.

----
The type inference feature works by generating a 'thunk' method in
*caller* that can act as a site for type inference (C# does not support
inference on constructors).

For our grid example above, the non-inferenced code will look something
like:
```
builder.OpenComponent<Grid<Person>>(0);
builder.AddAttribute(1, "Items", MyItems);
builder.CloseComponent();
```

Note that we can only write the type `Grid<Person>` because you wrote
`Person` in your code. What you type in the `TItem` attribute value gets
inserted into the generated code such that it fills in the generic type
parameter.

On the other hand, if you want is to infer the type, we have to do some
compiler magic. That looks like:
```
__Blazor.(long generated name).TypeInference.CreateGrid_0();
...

// elsewhere in the file
internal static class TypeInference
{
    public static void CreateGrid_0<TItem>(RenderTreeBuilder builder,
    int seq, int __seq0, global::System.Collections.Generic.List<TItem>
    __arg0)
        {
	        builder.OpenComponent<Grid<TItem>>(seq);
		        builder.AddAttribute(__seq0, "Items", __arg0);
			        builder.CloseComponent();
				    }
				    }
				    ```

				    This allows us to rely on the C#
				    compiler for itype inference.
2018-09-20 12:19:26 -07:00
Steve Sanderson b2f73492f5 Fix method wiping (#1448)
* Fix wiping assemblies that contain references to others in same directory

* Fix generated IL for reporting calls to wiped methods

* Add E2E test for method wiping
2018-09-20 10:20:37 +01:00
Ryan Nowak 354752cf16 Add support for generic-typed components (#1417)
* Add the ability to discover generic types/properties

* Add @typeparam directive

Adds the ability to declare a generic-typed component using Razor.

* Add a 'type parameter' property to generic components

* Adds the ability to consume generic-typed components
2018-09-16 14:01:15 -07:00
Steve Sanderson 6ff3674b16 Refactor server-side blazor startup to allow Azure SignalR. Fixes #1227 (#1396)
* Move startup action config into AddServerSideBlazor, so that UseServerSideBlazor is reduced to trivial shorthand that can become optional

* Make BlazorHub public so developers can use it with UseAzureSignalR

* Move BlazorHub to Microsoft.AspNetCore.Blazor.Server namespace for easier consumption

* Add notes

* Have E2E tests validate that devs don't have to call UseServerSideBlazor

* Add forgotten tweak

* CR: Document that BlazorHub methods are not intended for application use.

* CR: Rename extension method to UseSignalRWithBlazorHub

* CR: TryAdd
2018-09-11 09:55:27 +01:00
Ryan Nowak d4cbb86f46 Add Support for Templated Components (#1404)
* Test namespace cleanup

* Add recognication for RenderFragment in tag helpers

* Remove dead code from node writers

* refactor type check

* Continue to treat child content as a delegate in codegen

* Add extension to enumerate child content

* Reorganize code generation tests

These were growing a bit disorganized, and weren't really result in good
code reuse.

* fix test base class

* Add some child-content tests

* Add an explicit node for ChildContent

Adds a strongly typed node to represent a 'ChildContent' and what it
contains. This allows us to simplify the code generation path,
detect/processes more issues in IR passes, and will be essential for
supporting multiple child content.

* Ignore ChildContent in components when it's just whitespace

* Add diagnostic for duplicate child content

* Add support for explicit child content elements

Precursor to support for multiple child content items

* Add support for multiple child-content elements

* Change delegate signature for RenderFragment<T>

* Clean up Tag Helper constants

* Allow RenderFragment<T> as a child content

* Allow renaming the template parameter

* Improve error message for invalid child content

* Add diagnostic for repeated child content parameter names
2018-09-10 18:59:51 -07:00
cores-system 223a2fed97 Don't intercept clicks for links that open in external frames #1352 (#1354) 2018-09-03 10:31:37 +01:00
Ryan Nowak c97cb8c18b Add support for Razor templates
Adds support for Razor templates and RenderFragment<T>.

Razor templates are a little-known Razor feature that looks like:
```
@<tag>....<tag>
```

It's so little known that it's not even covered in our docs, but it's
been around for many many years. This features hasn't been implemented
until now for Blazor, and this feature brings it back as a build
building block for templated components (more to come).

In Blazor land a template like:
```
@{ RenderFragment<Person> template = @<div>@item.Name</div>; }
```

complies to code like:
```
RenderFragment<Person> template = (__builder, item) =>
{
    __builder.OpenElement(...);
    ...
    __builder.CloseElement(...);
}
```

Since the declaration always has a generic type parameter inside, it
needs to be in a context where the type is known.. ie: not with `var`.

See tests for ways to consume templates.

NOTE: There are the following caveats for templates
- Templates require a single root element.
- Templates don't work in the `@functions { }` block

These limitations are baked into the core of Razor and will take a while
for us to address (v3.0).
2018-08-31 19:10:42 -07:00
Steve Sanderson cf59ed94ad Consume jsinterop from submodule (#1351)
* Remove JSInterop files from this repo

* Add jsinterop submodule

* In Blazor.sln, reference jsinterop projects from submodule

* Update other references to jsinterop

* Fix TypeScript warning

* Include submodules in test/pack

* Update to newer jsinterop to fix JS pack issue

* Update to newer jsinterop to obtain strong naming

* Allow jsinterop submodule to inherit Directory.Build.props/targets

* Get latest jsinterop

* For AppVeyor builds, restore git submodules (happens automatically elsewhere)

* Update README.md with instructions to restore submodules
2018-08-29 11:10:35 +01:00
Steve Sanderson 520d47316f Increase default WaitAssert timeout to 2 seconds 2018-08-23 11:58:46 +01:00
Steve Sanderson 1089eecbfc In RenderBatchWriter, deduplicate strings only when safe to do so (#1340)
We allow deduplication of HTML element and attribute names, plus whitespace text nodes / attribute values.
2018-08-22 14:52:35 +01:00
Nate McMaster 3a2606a636 Strong name Blazor assemblies (#1344) 2018-08-21 15:37:05 -07:00
Steve Sanderson 52813ddf63 Eliminate temporary MemoryStream buffers used during RenderBatch serialization (#1329)
* Eliminate temporary MemoryStream buffers used during RenderBatch serialization. Fixes #1132

* CR: Fix namespace
2018-08-21 14:08:39 +01:00
Daniel Roth 7a763fc4f6 Scan only declared methods for JS interop (#1320)
* Scan only declared methods for JS interop

* Add DotNetDispatcher test for JS invokable method on base class
2018-08-17 12:35:24 +01:00
Steve Sanderson d3bc28de55 E2E benchmarks (#1307) 2018-08-14 13:21:19 +01:00
Ryan Nowak fd5426943f Merge sibling nodes during markup block rewrite
This change adds the ability to merge sibling nodes when possible during
markup block rewriting. We retain that invariant that each markup block
is a valid chunk of markup containing properly nested tags.

We still haven't done any work to remove whitespace yet, so most of the
cases where this comes into play right now will merge an element with
its surrounding whitespace.
2018-08-13 11:17:11 -07:00
Ryan Nowak a05cb42845 Reenable markup blocks (#1286)
* Reenable HtmlBlock unit tests

* Add E2E tests for HTML Block cases

* Remove harded GenerateBaselines=true

* Fix #1193

This commit addresses the root cause of #1193. When we merge HTML
text nodes into HTML blocks we need to re-encode any HTML entities that
were encoded eariler.

I did a bit of a deep dive on how HTML encoding is handled in Blazor and
I think this is the best strategy. I think it's valuable that the
BrowserRenderer uses document.createTextNode, which will always encode
the text - this handles dynamic content. We want to keep this in place
to avoid HTML injection attacks.

* Fix #1265 Reenable MarkupBlock

* test cleanup
2018-08-10 16:29:39 -07:00
Steve Sanderson 70a4bf7521 E2E test async robustness tweaks following recent failures 2018-08-09 10:27:40 +01:00
Nate McMaster 78045b2177 Automate authenticode code-signing using Roslyn sign tool
* Change project layout to prepare for upcoming Arcade changes
* Add signtool config file to configure OPC, NuGet, and Authenticode signing
* Fix a bug when BaseIntermediateOutputPath is set to an absolute path
2018-08-08 08:52:46 -07:00
Nate McMaster 22a3fbf861 Use $(TargetDir) instead of $(ProjectDir)$(OutputPath) 2018-08-06 16:48:36 -07:00
Steve Sanderson 16d005e00c Fix returning arrays in async JS interop calls. Fixes #1205 2018-07-27 10:11:45 -07:00
Steve Sanderson 4b861929be Temporarily disable HtmlBlockPass for 0.5.1. Will be re-enabled later. 2018-07-27 10:11:31 -07:00
Steve Sanderson 4e892e74da Fix handling nonvoid elements in markup blocks (#1190)
* Fix empty nonvoid elements in markup blocks. Fixes #1186

* Also update another test
2018-07-25 09:53:52 -07:00
Steve Sanderson 4aaeac1e51 preventDefault for form onsubmit handlers. Fixes #951 2018-07-24 08:11:02 -07:00
Ryan Nowak 8b3f26b962 Fix #1169 ignore DOCTYPE
This change will cause the compiler to ignore <!DOCTYPE ...>
declarations in Blazor components. We don't think there's much useful
Blazor can do with doctype, since we don't generate textual output for
the browser the parse. The sanest thing to do for now is just to skip
over it.
2018-07-23 17:42:47 -07:00
Steve Sanderson d2f74249b1 Fix updating attributes on SVG elements. Fixes #934 and #1114 2018-07-23 16:03:18 -07:00
Ryan Nowak 8f072a0711 Add HTML Block rewriting (#1146)
* Add HTML Block rewriter

* Baseline updates

* test gaps

* Update some unit tests to represent same behavior as before

* Define Markup frame type. Tests for rendering markup frames into render tree.

* Support markup frames during diffing (retain, insert, update, delete)

* Support markup blocks on WebAssembly

* Support rendering markup frames with server-side execution too

* Support markup blocks with multiple top-level nodes. Support updating markup dynamically.

* Define MarkupString type as a way to insert dynamic markup without needing custom RenderFragment code

* Remove comment

* CR: Better null value handling
2018-07-23 18:18:07 +01:00
Steve Sanderson 41fcf65c05 Run E2E tests for server execution as well as WebAssembly. Fixes several
server-execution bugs uncovered by the E2E tests.
2018-07-19 18:57:17 +01:00
Steve Sanderson 154289ed3d Allow passing DotNetObjectRef to JS in interop calls, and invoking
instance methods on it
2018-07-19 18:57:17 +01:00
Ryan Nowak 9778b2054a Add blazor.server.js (#1116)
Adds a server-side flavored blazor script.
2018-07-13 18:01:05 -07:00
Steve Sanderson ad7e98be04 Make index.html static again (#1123)
* Add build command for generating the new boot JSON file

* Remove build command for generating index.html

* Update build targets to generate blazor.boot.json

* Change SPA fallback routing to look for index.html in regular wwwroot. Will need to update setup for published apps later.

* Stop autorebuild when index.html changes, since we no longer 'build' that file

* Update Boot.WebAssembly.ts logic to use boot JSON info on startup

* Restore support for loading CSS/JS from Blazor library projects

* Use new startup script tag in all samples and templates

* Fix MonoSanity sample - it must now be an exe because we use that as the trigger to generate the boot json (not the presence of index.html any more)

* Fix SPA fallback routing for published apps

Because in a previous commit, I changed it to look for index.html inside "wwwroot" instead of "dist" (because we no longer build it). But "wwwroot" doesn't exist for published apps, because static file servers wouldn't understand it.

* CR: Fix path normalization
2018-07-13 09:49:34 +01:00
Steve Sanderson 767a2373c8 Eliminate ElementRef's static incrementing ID for remote rendering cases
... because it's important not to disclose cross-user state, such as the number of IDs that have been assigned. Plus we don't want to run out of unique IDs, which we could if it's limited by the range of an 'int'.
2018-07-10 09:52:19 +01:00
Ryan Nowak ee62bd8d45 Add startup for client/mono Blazor
This change adds a host builder, and the startup pattern for client-side
Blazor apps running in mono/wasm. This will help us align better with
server side Blazor.
2018-07-09 11:13:26 -07:00
Steve Sanderson 5bccac05fc Refactoring to prepare for remote rendering.
- Prepare for building multiple entrypoint variants of the .js library
- Use async interop more consistently for rendering and event handling
- Add binary serializer for RenderBatch with tests
2018-07-09 11:04:14 +01:00
Steve Sanderson cafb56569d Initial debugger support 2018-07-06 11:56:21 +01:00