Skip to content

Commit 7d225bc

Browse files
committed
Use React from NPM. Closes reactjs#197
Also switch from `React.renderToString` to `ReactDOMServer.renderToString` now that we actually have access to `ReactDOMServer`.
1 parent 118f304 commit 7d225bc

11 files changed

+100
-20740
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ src/React.Sample.*/ClearScript.V8
99
src/React.Sample.Webpack/build
1010
*.generated.js
1111
*.generated.js.map
12+
*.generated.min.js
1213
src/React.Sample.Mvc6/wwwroot/js/Sample.js
1314
*.lock.json
1415
src/.vs

build.proj

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ of patent rights can be found in the PATENTS file in the same directory.
108108
</Target>
109109

110110
<Target Name="Build" DependsOnTargets="RestorePackages;UpdateVersion">
111+
<Exec WorkingDirectory="src/React.Core" Command="gulp" />
111112
<MSBuild Projects="$(SolutionFile)" Targets="Rebuild" Properties="Configuration=Release;Platform=Any CPU;NoWarn=1607,7035" />
112113
</Target>
113114

src/React.Core/JavaScriptEngineFactory.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ protected virtual void InitialiseEngine(IJsEngine engine)
106106
engine.ExecuteResource("React.Resources.shims.js", thisAssembly);
107107
if (_config.LoadReact)
108108
{
109-
engine.ExecuteResource("React.Resources.react-with-addons.js", thisAssembly);
110-
engine.Execute("React = global.React");
111-
// Expose ReactDOM as some scripts may be using it. #yolo
112-
engine.Execute("ReactDOM = React.__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED");
109+
// TODO: Add option to choose whether to load dev vs prod version of React.
110+
engine.ExecuteResource("React.Resources.react.generated.js", thisAssembly);
113111
}
114112

115113
LoadUserScripts(engine);
@@ -162,9 +160,10 @@ private static void EnsureReactLoaded(IJsEngine engine)
162160
if (!result)
163161
{
164162
throw new ReactNotInitialisedException(
165-
"React has not been loaded correctly. Please expose your version of React as a global " +
166-
"variable named 'React', or enable the 'LoadReact' configuration option to " +
167-
"use the built-in version of React."
163+
"React has not been loaded correctly. Please expose your version of React as global " +
164+
"variables named 'React', 'ReactDOM' and 'ReactDOMServer', or enable the " +
165+
"'LoadReact' configuration option to use the built-in version of React. See " +
166+
"http://reactjs.net/guides/byo-react.html for more information."
168167
);
169168
}
170169
}

src/React.Core/React.Core.csproj

+6-3
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,18 @@
135135
<Compile Include="SimpleFileSystem.cs" />
136136
<None Include="React.Core.nutrans" />
137137
</ItemGroup>
138-
<ItemGroup>
139-
<EmbeddedResource Include="Resources\react-with-addons.js" />
140-
</ItemGroup>
141138
<ItemGroup>
142139
<EmbeddedResource Include="Resources\shims.js" />
143140
</ItemGroup>
144141
<ItemGroup>
145142
<EmbeddedResource Include="node_modules\babel-core\browser.js" />
146143
</ItemGroup>
144+
<ItemGroup>
145+
<Content Include="gulpfile.js" />
146+
<EmbeddedResource Include="Resources\react.generated.js" />
147+
<EmbeddedResource Include="Resources\react.generated.min.js" />
148+
<Content Include="Resources\react.js" />
149+
</ItemGroup>
147150
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
148151
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
149152
Other similar extension points exist, see Microsoft.Common.targets.

src/React.Core/ReactComponent.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public virtual string RenderHtml(bool renderContainerOnly = false, bool renderSe
9090
if (!renderContainerOnly)
9191
{
9292
var reactRenderCommand = renderServerOnly
93-
? string.Format("React.renderToStaticMarkup({0})", GetComponentInitialiser())
94-
: string.Format("React.renderToString({0})", GetComponentInitialiser());
93+
? string.Format("ReactDOMServer.renderToStaticMarkup({0})", GetComponentInitialiser())
94+
: string.Format("ReactDOMServer.renderToString({0})", GetComponentInitialiser());
9595
html = _environment.Execute<string>(reactRenderCommand);
9696
}
9797
return string.Format(

0 commit comments

Comments
 (0)