Repository navigation
add support for Blazor #1052
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
Merged
Merged
add support for Blazor #1052
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
04ac6e0
feat(Compilers): add Blazor support
hatemhosny 8249f7a
reuse blazor-wasm for C#
hatemhosny 73b5a41
fix(blazor): add translations, fix runtime retry and sort language info
pullfrog[bot] 8705d98
edit blazor docs
hatemhosny 36160ed
edit docs
hatemhosny 9503f3f
edit docs
hatemhosny 1291437
edit docs
hatemhosny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # Blazor (Wasm) | ||
|
|
||
| [Blazor](https://dotnet.microsoft.com/en-us/apps/aspnet/web-apps/blazor) is a framework for building interactive web UIs with C# and Razor, running on .NET WebAssembly. | ||
|
|
||
| In LiveCodes, Razor components are compiled in the browser by the real Razor compiler and Roslyn, and rendered by Blazor WebAssembly. Nothing is sent to a server: the compiler, the .NET runtime and the reference assemblies all run in the page. | ||
|
|
||
| ## Usage | ||
|
|
||
| Demo: | ||
|
|
||
|
|
||
| import LiveCodes from '../../src/components/LiveCodes.tsx'; | ||
| export const blazorConfig = { | ||
| activeEditor: 'script', | ||
| script: { | ||
| language: 'blazor-wasm', | ||
| content: `<h1>Counter</h1>\n | ||
| <p>Current count: <strong>@count</strong></p>\n | ||
| <button class="btn btn-primary" @onclick="IncrementCount">Click me</button>\n | ||
| @code { | ||
| private int count = 0;\n | ||
| private void IncrementCount() => count++; | ||
| }`, | ||
| }, | ||
| style: { | ||
| language: 'css', | ||
| content: `.btn { | ||
| font: inherit; | ||
| padding: 0.4em 1.1em; | ||
| cursor: pointer; | ||
| }`, | ||
| }, | ||
| mode: 'simple', | ||
| editor: 'auto', | ||
| }; | ||
|
|
||
| <LiveCodes config={blazorConfig}></LiveCodes> | ||
|
|
||
|
|
||
| ### Communication with JavaScript | ||
|
|
||
| The component runs in the context of the result page. A few helpers are available in the browser global `livecodes.blazorWasm` object: | ||
|
|
||
| - `livecodes.blazorWasm.loaded`: A promise that resolves when the .NET WebAssembly runtime has loaded. The Roslyn and Razor compiler payloads are fetched lazily on the first render, so other helpers should be used after this promise resolves. | ||
| - `livecodes.blazorWasm.render`: A function that compiles and renders Razor markup. It takes a string of Razor markup as input and returns a promise that resolves with an object containing the `output`, `error`, and `exitCode` properties. | ||
| - `livecodes.blazorWasm.runner`: The underlying [`@live-codes/blazor-wasm`](https://www.npmjs.com/package/@live-codes/blazor-wasm) runner, which also exposes `renderProject` (multi-file projects), `render`, `navigateTo` (for `@page` routing) and `payloads`. | ||
| - `livecodes.blazorWasm.routes`: The routes declared by `@page` directives in the rendered component. | ||
| - `livecodes.blazorWasm.navigateTo`: A function that drives the host's client-side navigation, for `@page` routing. | ||
|
|
||
|
|
||
| ## Language Info | ||
|
|
||
| ### Name | ||
|
|
||
| `blazor-wasm` | ||
|
|
||
| ### Aliases / Extensions | ||
|
|
||
| `razor`, `blazor`, `razor-wasm`, `wasm.razor` | ||
|
|
||
| ### Editor | ||
|
|
||
| `script` | ||
|
|
||
| ## Compiler | ||
|
|
||
| The real Razor compiler and Roslyn, compiled to WebAssembly, together with the .NET WebAssembly runtime and the Blazor WebAssembly host — loaded at run time from the [`@live-codes/blazor-wasm`](https://www.npmjs.com/package/@live-codes/blazor-wasm) package. | ||
|
|
||
| ### Version | ||
|
|
||
| .NET 10 | ||
|
|
||
| ## Limitations | ||
|
|
||
| ### Blazor components only | ||
|
|
||
| Only **Blazor components** (`.razor`) are supported, not Razor Pages or MVC views. MVC-only directives such as `@model`, `@section` and tag helpers neither compile nor run. Use the Blazor equivalents: | ||
|
|
||
| | Razor Pages / MVC | Blazor equivalent | | ||
| | ------------------------------------- | ------------------------------------------------------------------------- | | ||
| | `@model T` | `[Parameter] public T Model { get; set; }` | | ||
| | `@section Name { ... }` | a layout component that renders `@Body` (or a `RenderFragment` parameter) | | ||
| | tag helpers (`@addTagHelper`, `asp-`) | Blazor components and plain HTML with `@onclick` / `@bind` | | ||
| | `@functions { ... }` | `@code { ... }` | | ||
| | `@inherits RazorPage<T>` | `@inherits ComponentBase` (components already derive from `ComponentBase`) | | ||
|
|
||
| `@inject` works, but only for services the host already registers (`NavigationManager`, `IJSRuntime`, ...). `Program.cs` is not editable, so custom services cannot be registered. Razor Pages need the MVC view engine (`ViewContext`, tag-helper activation, sections, model binding, `HttpContext`), which a Blazor WebAssembly host does not include — even compiling a `.cshtml` file would fail at run time. | ||
|
|
||
| ### Other limitations | ||
|
|
||
| - The first Razor compile takes a few seconds while the Razor generator warms up. Warm renders are fast. | ||
| - The runtime and the reference assemblies are downloaded on the first run, so the first compile is a large download. | ||
| - `wwwroot/` files are served as data URLs, so `url(...)` inside CSS and `fetch()` do not resolve; only `src`/`href`/`poster` attributes are rewritten. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```html | ||
| <h1>Hello, Blazor!</h1> | ||
|
|
||
| <button @onclick="Increment">You clicked @count times</button> | ||
|
|
||
| @code { | ||
| private int count; | ||
|
|
||
| private void Increment() => count++; | ||
| } | ||
| ``` | ||
|
|
||
| ## Starter Template | ||
|
|
||
| https://livecodes.io/?template=blazor-wasm | ||
|
|
||
| ## Links | ||
|
|
||
| - [Blazor](https://dotnet.microsoft.com/en-us/apps/aspnet/web-apps/blazor) | ||
| - [Blazor components](https://learn.microsoft.com/en-us/aspnet/core/blazor/components/) | ||
| - [Razor syntax reference](https://learn.microsoft.com/en-us/aspnet/core/mvc/views/razor) | ||
| - [@live-codes/blazor-wasm](https://www.npmjs.com/package/@live-codes/blazor-wasm) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: live-codes/livecodes
Length of output: 6995
🏁 Script executed:
Repository: live-codes/livecodes
Length of output: 2505
Give both Blazor tests a 360-second timeout.
The configured test timeout is 60 seconds, so
test.slow()raises each test’s total limit to 180 seconds. That limit can end the test before the heading assertion’s 280-second timeout expires. A 360-second test timeout allows up to 80 seconds for setup and the remaining checks.Suggested fix
Apply this change in both Blazor tests.
📝 Committable suggestion
📍 Affects 1 file
e2e/specs/starter.spec.ts#L566-L566(this comment)e2e/specs/starter.spec.ts#L1338-L1338🤖 Prompt for AI Agents