Skip to content
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

Added client-only fallback for RenderAsync method #35

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Forte.Web.React/Forte.Web.React.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Packable>true</Packable>
<VersionPrefix>1.0.1.0</VersionPrefix>
<Version>1.0.1.0</Version>
<VersionPrefix>1.0.2.0</VersionPrefix>
<Version>1.0.2.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
23 changes: 15 additions & 8 deletions Forte.Web.React/React/ReactService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
{
component.Path,
component.JsonContainerId,
props,

Check warning on line 74 in Forte.Web.React/React/ReactService.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<object>.Add(object item)'.

Check warning on line 74 in Forte.Web.React/React/ReactService.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<object>.Add(object item)'.

Check warning on line 74 in Forte.Web.React/React/ReactService.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<object>.Add(object item)'.

Check warning on line 74 in Forte.Web.React/React/ReactService.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<object>.Add(object item)'.
_config.ScriptUrls,
_config.NameOfObjectToSaveProps,
};
Expand Down Expand Up @@ -118,16 +118,15 @@
return WrapRenderedStringComponent(result, component);
}

public async Task RenderAsync(TextWriter writer, string componentName, object? props = null,
RenderOptions? options = null)
public async Task RenderAsync(TextWriter writer, string componentName, object? props = null, RenderOptions? options = null)
{
options ??= new RenderOptions();
var component = new Component(componentName, props, options.ServerOnly ? RenderingMode.Server : RenderingMode.ClientAndServer);
var component = new Component(componentName, props, options.RenderingMode);
Components.Add(component);

await writer.WriteAsync($"<div id=\"{component.ContainerId}\">").ConfigureAwait(false);

if (_config.IsServerSideDisabled)
if (_config.IsServerSideDisabled || component.RenderingMode == RenderingMode.Client)
{
await writer.WriteAsync("</div>").ConfigureAwait(false);
return;
Expand All @@ -136,7 +135,7 @@
var streamingOptions = new
{
options.EnableStreaming,
options.ServerOnly,
ServerOnly = component.RenderingMode == RenderingMode.Server,
IdentifierPrefix = _config.UseIdentifierPrefix ? component.ContainerId : null,
};

Expand Down Expand Up @@ -257,12 +256,20 @@

public class RenderOptions
{
public RenderOptions(bool serverOnly = false, bool enableStreaming = true)
public RenderOptions() : this(RenderingMode.ClientAndServer, true)
{
ServerOnly = serverOnly;
}

public RenderOptions(bool serverOnly, bool enableStreaming = true) : this(serverOnly ? RenderingMode.Server : RenderingMode.ClientAndServer, enableStreaming)
{
}

public RenderOptions(RenderingMode renderingMode, bool enableStreaming = true)
{
RenderingMode = renderingMode;
EnableStreaming = enableStreaming;
}

public bool ServerOnly { get; }
public RenderingMode RenderingMode { get; }
public bool EnableStreaming { get; }
}