Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1b8e74d

Browse files
committedJan 21, 2018
Merge remote-tracking branch 'origin/master' into nonce-attribute
2 parents 415c4eb + e5cb5d8 commit 1b8e74d

33 files changed

+13517
-3204
lines changed
 

‎.editorconfig

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# editorconfig.org
2-
root = true
3-
4-
[*]
5-
charset = utf-8
6-
end_of_line = crlf
7-
indent_size = 4
8-
indent_style = tab
9-
insert_final_newline = true
10-
11-
[*.json]
12-
indent_size = 2
13-
indent_style = space
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 4
8+
indent_style = tab
9+
insert_final_newline = true
10+
11+
[*.json]
12+
indent_size = 2
13+
indent_style = space

‎.gitattributes

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text eol=lf
2+
*.png binary
3+
*.exe binary
4+
*.dll binary
5+

‎src/React.AspNet/HtmlHelperExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private static IReactEnvironment Environment
5252
/// <param name="htmlTag">HTML tag to wrap the component in. Defaults to &lt;div&gt;</param>
5353
/// <param name="containerId">ID to use for the container HTML tag. Defaults to an auto-generated ID</param>
5454
/// <param name="clientOnly">Skip rendering server-side and only output client-side initialisation code. Defaults to <c>false</c></param>
55-
/// <param name="serverOnly">Skip rendering React specific data-attributes during server side rendering. Defaults to <c>false</c></param>
55+
/// <param name="serverOnly">Skip rendering React specific data-attributes, container and client-side initialisation during server side rendering. Defaults to <c>false</c></param>
5656
/// <param name="containerClass">HTML class(es) to set on the container tag</param>
5757
/// <param name="exceptionHandler">A custom exception handler that will be called if a component throws during a render. Args: (Exception ex, string componentName, string containerId)</param>
5858
/// <returns>The component's HTML</returns>
@@ -70,7 +70,7 @@ public static IHtmlString React<T>(
7070
{
7171
try
7272
{
73-
var reactComponent = Environment.CreateComponent(componentName, props, containerId, clientOnly);
73+
var reactComponent = Environment.CreateComponent(componentName, props, containerId, clientOnly, serverOnly);
7474
if (!string.IsNullOrEmpty(htmlTag))
7575
{
7676
reactComponent.ContainerTag = htmlTag;

‎src/React.Core/Babel.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ string filename
353353
var contents = _fileSystem.ReadAsString(filename);
354354
if (CacheIsValid(contents, outputPath))
355355
return outputPath;
356-
356+
357357
var result = TransformWithHeader(filename, contents, null);
358358

359359
var sourceMapPath = GetSourceMapOutputPath(filename);
@@ -363,14 +363,14 @@ string filename
363363
return outputPath;
364364
}
365365

366-
/// <summary>
367-
/// Checks whether an input file (given as inputFileContents) should be transpiled
368-
/// by calculating the hash and comparing it to the hash value stored
369-
/// in the file given by outputPath. If the outputPath file does not
370-
/// exist the input file should always be transpiled.
371-
/// </summary>
372-
/// <param name="inputFileContents">The contents of the input file.</param>
373-
/// <param name="outputPath">The output path of the (possibly previously) generated file.</param>
366+
/// <summary>
367+
/// Checks whether an input file (given as inputFileContents) should be transpiled
368+
/// by calculating the hash and comparing it to the hash value stored
369+
/// in the file given by outputPath. If the outputPath file does not
370+
/// exist the input file should always be transpiled.
371+
/// </summary>
372+
/// <param name="inputFileContents">The contents of the input file.</param>
373+
/// <param name="outputPath">The output path of the (possibly previously) generated file.</param>
374374
/// <returns>Returns false if the file should be transpiled, true otherwise.</returns>
375375
public virtual bool CacheIsValid(string inputFileContents, string outputPath)
376376
{

‎src/React.Core/IReactComponent.cs

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public interface IReactComponent
4141
/// </summary>
4242
string ContainerClass { get; set; }
4343

44+
/// <summary>
45+
/// Get or sets if this components only should be rendered server side
46+
/// </summary>
47+
bool ServerOnly { get; set; }
48+
4449
/// <summary>
4550
/// Renders the HTML for this component. This will execute the component server-side and
4651
/// return the rendered HTML.

‎src/React.Core/IReactEnvironment.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ public interface IReactEnvironment
8080
/// <param name="props">Props to use</param>
8181
/// <param name="containerId">ID to use for the container HTML tag. Defaults to an auto-generated ID</param>
8282
/// <param name="clientOnly">True if server-side rendering will be bypassed. Defaults to false.</param>
83+
/// <param name="serverOnly">True if this component only should be rendered server-side. Defaults to false.</param>
8384
/// <returns>The component</returns>
84-
IReactComponent CreateComponent<T>(string componentName, T props, string containerId = null, bool clientOnly = false);
85+
IReactComponent CreateComponent<T>(string componentName, T props, string containerId = null, bool clientOnly = false, bool serverOnly = false);
8586

8687
/// <summary>
8788
/// Adds the provided <see cref="IReactComponent"/> to the list of components to render client side.

‎src/React.Core/React.Core.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
2020
</PropertyGroup>
2121

22-
<ItemGroup>
23-
<Compile Remove="node_modules\**" />
24-
<EmbeddedResource Remove="node_modules\**" />
25-
<None Remove="node_modules\**" />
22+
<ItemGroup>
23+
<Compile Remove="node_modules\**" />
24+
<EmbeddedResource Remove="node_modules\**" />
25+
<None Remove="node_modules\**" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

‎src/React.Core/ReactComponent.cs

+10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public class ReactComponent : IReactComponent
6868
/// </summary>
6969
public string ContainerClass { get; set; }
7070

71+
/// <summary>
72+
/// Get or sets if this components only should be rendered server side
73+
/// </summary>
74+
public bool ServerOnly { get; set; }
75+
7176
/// <summary>
7277
/// Gets or sets the props for this component
7378
/// </summary>
@@ -130,6 +135,11 @@ public virtual string RenderHtml(bool renderContainerOnly = false, bool renderSe
130135
? string.Format("ReactDOMServer.renderToStaticMarkup({0})", GetComponentInitialiser())
131136
: string.Format("ReactDOMServer.renderToString({0})", GetComponentInitialiser());
132137
html = _environment.Execute<string>(reactRenderCommand);
138+
139+
if (renderServerOnly)
140+
{
141+
return html;
142+
}
133143
}
134144
catch (JsRuntimeException ex)
135145
{

‎src/React.Core/ReactEnvironment.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
using System.Text;
1515
using System.Threading;
1616
using JavaScriptEngineSwitcher.Core;
17-
using JavaScriptEngineSwitcher.Core.Helpers;
1817
using JSPool;
19-
using Newtonsoft.Json;
2018
using React.Exceptions;
2119
using React.TinyIoC;
2220

@@ -287,8 +285,9 @@ public virtual bool HasVariable(string name)
287285
/// <param name="props">Props to use</param>
288286
/// <param name="containerId">ID to use for the container HTML tag. Defaults to an auto-generated ID</param>
289287
/// <param name="clientOnly">True if server-side rendering will be bypassed. Defaults to false.</param>
288+
/// <param name="serverOnly">True if this component only should be rendered server-side. Defaults to false.</param>
290289
/// <returns>The component</returns>
291-
public virtual IReactComponent CreateComponent<T>(string componentName, T props, string containerId = null, bool clientOnly = false)
290+
public virtual IReactComponent CreateComponent<T>(string componentName, T props, string containerId = null, bool clientOnly = false, bool serverOnly = false)
292291
{
293292
if (!clientOnly)
294293
{
@@ -297,7 +296,8 @@ public virtual IReactComponent CreateComponent<T>(string componentName, T props,
297296

298297
var component = new ReactComponent(this, _config, componentName, containerId)
299298
{
300-
Props = props
299+
Props = props,
300+
ServerOnly = serverOnly
301301
};
302302
_components.Add(component);
303303
return component;
@@ -339,8 +339,11 @@ public virtual string GetInitJavaScript(bool clientOnly = false)
339339

340340
foreach (var component in _components)
341341
{
342-
fullScript.Append(component.RenderJavaScript());
343-
fullScript.AppendLine(";");
342+
if (!component.ServerOnly)
343+
{
344+
fullScript.Append(component.RenderJavaScript());
345+
fullScript.AppendLine(";");
346+
}
344347
}
345348

346349
return fullScript.ToString();

0 commit comments

Comments
 (0)
Please sign in to comment.