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

Hermes bytecode compilation fails in release mode when app is included in a separate wapproj project #12708

Closed
WilliamWelsh opened this issue Feb 9, 2024 · 18 comments
Labels
Milestone

Comments

@WilliamWelsh
Copy link

WilliamWelsh commented Feb 9, 2024

Problem Description

Continued from #12258

I made this into a new issue since my old one started out with a different issue.

I have a packaged solution, where my React Native Windows app is the startup, with a .NET Framework background process that is run via full trust. I've boiled it down to just setting up a packaged project causes the error.

If I make a new project, Hermes in release runs fine. Once I add to a packaged project, it fails to run.

If UseHermes is disabled, it runs fine.

When searching for similar error messages (on other react native projects), they all fixed it by doing something regarding ram bundle

Here is the output below from doing the steps under "Steps To Reproduce"

Build started at 10:22 AM...
1>------ Build started: Project: test, Configuration: Release x64 ------
1>  Running [npx react-native bundle --platform windows --entry-file index.js --bundle-output C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle --assets-dest C:\Users\william.welsh\Downloads\test\windows\test\Bundle --dev false --reset-cache --sourcemap-output C:\Users\william.welsh\Downloads\test\windows\test\bin\x64\Release\sourcemaps\react\index.windows.bundle.packager.map --minify false] to build bundle file.
1>EXEC : warning : the transform cache was reset.
1>                  Welcome to Metro v0.80.5
1>                Fast - Scalable - Integrated
1>  
1>  
1>  info Writing bundle output to:, C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle
1>  info Writing sourcemap output to:, C:\Users\william.welsh\Downloads\test\windows\test\bin\x64\Release\sourcemaps\react\index.windows.bundle.packager.map
1>  info Done writing bundle output
1>  info Done writing sourcemap output
1>  info Copying 1 asset files
1>  info Done copying assets
1>  Running [C:\Users\william.welsh\.nuget\packages\microsoft.javascript.hermes\0.1.18\tools\native\release\x86\hermes.exe -emit-binary -out C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle.hbc C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle -O -output-source-map] to precompile bundle file.
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(2634,18): warning G2BA5DD72: the variable "DebuggerInternal" was not declared in function "__shouldPauseOnThrow"
1>            typeof DebuggerInternal !== 'undefined' &&
1>                   ^~~~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(6308,7): warning GB72B04CF: the variable "setTimeout" was not declared in function "logCapturedError"
1>        setTimeout(function () {
1>        ^~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(4277,108): warning G6B002900: the variable "nativeFabricUIManager" was not declared in function "onChange"
1>        (fromOrTo = fromOrTo && fromOrTo.stateNode) && fromOrTo.canonical._internalInstanceHandle ? (from && nativeFabricUIManager.setIsJSResponder(from.stateNode.node, false, blockNativeResponder || false), to && nativeFabricUIManager.setIsJSResponder(to.stateNode.node, true, blockNativeResponder || false)) : null !== to ? _$$_REQUIRE(_dependencyMap[2]).UIManager.setJSResponder(to.stateNode.canonical._nativeTag, blockNativeResponder) : _$$_REQUIRE(_dependencyMap[2]).UIManager.clearJSResponder();
1>                                                                                                             ^~~~~~~~~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(4889,21): warning G71EC756D: the variable "clearTimeout" was not declared in anonymous function " 115#"
1>      cancelTimeout = clearTimeout;
1>                      ^~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(8639,30): warning GE03A48E9: the variable "__REACT_DEVTOOLS_GLOBAL_HOOK__" was not declared in anonymous function " 115#"
1>    if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1>                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(11008,5): warning G77E22827: the variable "setImmediate" was not declared in function "handleResolved"
1>      setImmediate(function () {
1>      ^~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15154,12): warning GB21C39AA: the variable "fetch" was not declared in anonymous function " 347#"
1>      fetch: fetch,
1>             ^~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15155,14): warning G977A4F98: the variable "Headers" was not declared in anonymous function " 347#"
1>      Headers: Headers,
1>               ^~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15156,14): warning GA9DF0D4B: the variable "Request" was not declared in anonymous function " 347#"
1>      Request: Request,
1>               ^~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15157,15): warning GBA394B55: the variable "Response" was not declared in anonymous function " 347#"
1>      Response: Response
1>                ^~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15314,24): warning G7B5B9C2F: the variable "FileReader" was not declared in function "readBlobAsArrayBuffer"
1>        var reader = new FileReader();
1>                         ^~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15365,36): warning G2EA34993: the variable "Blob" was not declared in anonymous function " 358#"
1>          } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
1>                                     ^~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15367,40): warning G1B27C27E: the variable "FormData" was not declared in anonymous function " 358#"
1>          } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
1>                                         ^~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15369,44): warning G057317F1: the variable "URLSearchParams" was not declared in anonymous function " 358#"
1>          } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
1>                                             ^~~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15488,26): warning G76EBB7FD: the variable "AbortController" was not declared in anonymous function " 364#"
1>            var ctrl = new AbortController();
1>                           ^~~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15622,23): warning G6D8B000F: the variable "XMLHttpRequest" was not declared in anonymous function " 368#"
1>          var xhr = new XMLHttpRequest();
1>                        ^~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15167,71): warning GA1281092: the variable "self" was not declared in anonymous function " 350#"
1>      var g = typeof globalThis !== 'undefined' && globalThis || typeof self !== 'undefined' && self ||
1>                                                                        ^~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(25917,27): warning G37EDA9A9: the variable "performance" was not declared in anonymous function " 672#"
1>    if ("object" === typeof performance && "function" === typeof performance.now) {
1>                            ^~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(25940,26): warning G08945F78: the variable "navigator" was not declared in anonymous function " 672#"
1>    "undefined" !== typeof navigator && undefined !== navigator.scheduling && undefined !== navigator.scheduling.isInputPending ? navigator.scheduling.isInputPending.bind(navigator.scheduling) : null;
1>                           ^~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(26050,37): warning G121C250D: the variable "MessageChannel" was not declared in anonymous function " 672#"
1>    };else if ("undefined" !== typeof MessageChannel) {
1>                                      ^~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(26065,34): warning G7AAC3233: the variable "nativeRuntimeScheduler" was not declared in anonymous function " 672#"
1>    var Y = "undefined" !== typeof nativeRuntimeScheduler ? nativeRuntimeScheduler.unstable_UserBlockingPriority : 2,
1>                                   ^~~~~~~~~~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(42362,34): warning GA4D07A9C: the variable "requestAnimationFrame" was not declared in function "start 9#"
1>            this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this));
1>                                   ^~~~~~~~~~~~~~~~~~~~~
1>  - Checking auto-linked files...
1>  √ Checking auto-linked files...
1>  Success: No auto-linking changes necessary. (13ms)
1>  - Running x64 node on a x64 machine
1>  i Running x64 node on a x64 machine
1>  - Running codegen-windows...
1>  
1>  i No codegenConfig specified in package.json - Skipping codegen-windows
1>  Success: No codegen-windows changes necessary. (1ms)
1>  Microsoft.ReactNative.Managed.CodeGen -> C:\Users\william.welsh\Downloads\test\node_modules\react-native-windows\target\x64\Release\Microsoft.ReactNative.Managed.CodeGen\Microsoft.ReactNative.Managed.CodeGen.dll
1>  Microsoft.ReactNative.Managed.CodeGen -> C:\Users\william.welsh\Downloads\test\node_modules\react-native-windows\target\x64\Release\Microsoft.ReactNative.Managed.CodeGen\publish\
1>  Parsing source files [90 milliseconds]
1>  Loading references [18 milliseconds]
1>  Compiling [816 milliseconds]
1>  Finding types [6 milliseconds]
1>  Generating code [22 milliseconds]
1>  test -> C:\Users\william.welsh\Downloads\test\windows\test\bin\x64\Release\test.exe
1>  Determining projects to restore...
1>  All projects are up-to-date for restore.
1>  Determining projects to restore...
1>  Applying temporary patches to folly.
1>  Determining projects to restore...
1>  Determining projects to restore...
1>  All projects are up-to-date for restore.
1>  Determining projects to restore...
1>  Determining projects to restore...
1>  Determining projects to restore...
1>  Applying temporary patches to fmt.
1>  Determining projects to restore...
1>  Processing application code
1>  Computing application closure and generating interop code
1>    Loading 50 modules...
1>    Generating code...
1>    Interop code generated.
1>  Compiling interop code
1>  Generating System.Reflection.DispatchProxy proxy code.
1>  Cleaning up unreferenced code
1>  Generating native code
1>  Generating fixups for native code
2>------ Build started: Project: Package, Configuration: Release x64 ------
2>Running [C:\Users\william.welsh\.nuget\packages\microsoft.javascript.hermes\0.1.18\tools\native\release\x86\hermes.exe -emit-binary -out C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle.hbc C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle -O -output-source-map] to precompile bundle file.
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,1): error G56F8712A: Invalid UTF-8 continuation byte
2>∩┐╜�∩┐╜�∩┐╜���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,1): error GCF657EDE: unrecognized Unicode character \ufffd
2>∩┐╜�∩┐╜�∩┐╜���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,2): error G2A165EF7: unrecognized Unicode character \u1f
2>∩┐╜�∩┐╜�∩┐╜���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,3): error G4B4867E8: Invalid UTF-8 lead byte 0xbc
2>∩┐╜�∩┐╜�∩┐╜���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,3): error GCF657EDE: unrecognized Unicode character \ufffd
2>∩┐╜�∩┐╜�∩┐╜���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,4): error GFCD67ACB: unrecognized Unicode character \u3
2>∩┐╜�∩┐╜�∩┐╜���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,5): error G56F8712A: Invalid UTF-8 continuation byte
2>∩┐╜�∩┐╜�∩┐╜���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,5): error GCF657EDE: unrecognized Unicode character \ufffd
2>∩┐╜�∩┐╜�∩┐╜���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,6): error GFCD67ACB: unrecognized Unicode character \u3
2>∩┐╜�∩┐╜�∩┐╜���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,7): error G2A165EBE: unrecognized Unicode character \u19
2>∩┐╜�∩┐╜�∩┐╜���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,8): error G2A165EF7: unrecognized Unicode character \u1f
2>∩┐╜�∩┐╜�∩┐╜���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,9): error G5BE2CDEF: invalid expression
2>∩┐╜�∩┐╜�∩┐╜���^
2>C:\Users\william.welsh\Downloads\test\node_modules\react-native-windows\PropertySheets\Bundle.Common.targets(22,5): error MSB3073: The command "C:\Users\william.welsh\.nuget\packages\microsoft.javascript.hermes\0.1.18\tools\native\release\x86\hermes.exe -emit-binary -out "C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle.hbc" "C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle" -O -output-source-map" exited with code 2.
2>Done building project "test.csproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 6 up-to-date, 0 skipped ==========
========== Build completed at 10:23 AM and took 52.666 seconds ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
========== Deploy completed at 10:23 AM and took 52.666 seconds ==========

Steps To Reproduce

Initialize RN project

  1. npx react-native@latest init test

Initialize RN Windows
2. cd test
3. npx react-native-windows-init --overwrite --language cs

Get it running
4. npx react-native run-windows

Try out Release mode
5. npx react-native run-windows --release

Running in x64 release runs perfectly. UseHermes is true by default now.

Set up packaged project
6. Open solution in Visual Studio
7. Add a new project - Windows Application Packaging Project (C# UWP)
8. Add the test project as a reference in the new packaging project
9. Try to run in release (setting packaged app to startup project and clicking play)
10. Fail

Expected Results

The app should run.

CLI version

12.3.2

Environment

System:
  OS: Windows 11 10.0.22631
  CPU: (20) x64 Intel(R) Core(TM) i9-10850K CPU @ 3.60GHz
  Memory: 17.89 GB / 31.87 GB
Binaries:
  Node:
    version: 20.10.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 1.22.19
    path: ~\AppData\Roaming\npm\yarn.CMD
  npm:
    version: 10.2.3
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
    AllowAllTrustedApps: Enabled
    Versions:
      - 10.0.14393.0
      - 10.0.17134.0
      - 10.0.17763.0
      - 10.0.18362.0
      - 10.0.19041.0
      - 10.0.22000.0
      - 10.0.22621.0
IDEs:
  Android Studio: Not Found
  Visual Studio:
    - 15.9.33529.398 (Visual Studio Enterprise 2017)
    - 17.5.33530.505 (Visual Studio Community 2022)
    - 17.8.34511.84 (Visual Studio Professional 2022)
    - 16.11.33529.622 (Visual Studio Community 2019)
Languages:
  Java:
    version: 17.0.8.1
    path: C:\Program Files\Eclipse Adoptium\jdk-17.0.8.101-hotspot\bin\javac.EXE
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.4
    wanted: 0.73.4
  react-native-windows:
    installed: 0.73.4
    wanted: 0.73.4
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Target Platform Version

None

Target Device(s)

Desktop

Visual Studio Version

Visual Studio 2022

Build Configuration

ReleaseBundle

Snack, code example, screenshot, or link to a repository

https://github.com/WilliamWelsh/react-native-windows-hermes-fail

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Triage 🔍 New issue that needs to be reviewed by the issue management team (label applied by bot) label Feb 9, 2024
@chrisglein
Copy link
Member

Can I back up one step and ask why you're adding an additional packaging project when the new project template started you out with a UWP app that's already packaged? I'm not understanding the scenario. Would it be possible to add your background task to the UWP project created for you?

Thanks for sharing the steps. Can you share a min repo of the steps you executed so we can get detail on these steps in particular:

  1. Add a new project - Windows Application Packaging Project (C# UWP)
  2. Add the test project as a reference in the new packaging project

Hermes in particular has a different version for UWP apps vs. Win32 apps, and if we end up with the wrong version it could cause problems (maybe like what you're seeing here).

@chrisglein chrisglein added Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) and removed Needs: Triage 🔍 New issue that needs to be reviewed by the issue management team (label applied by bot) labels Feb 12, 2024
@WilliamWelsh
Copy link
Author

WilliamWelsh commented Feb 16, 2024

Can I back up one step and ask why you're adding an additional packaging project when the new project template started you out with a UWP app that's already packaged? I'm not understanding the scenario. Would it be possible to add your background task to the UWP project created for you?

In the new, packaging project, I can add my .NET Framework background process under "Dependencies" just fine, and have UWP run via full trust. If I try to add that same project under "References" in the uwp app it says it's unable to (am I supposed to add it a different way?)

Thanks for sharing the steps. Can you share a min repo of the steps you executed so we can get detail on these steps in particular:

  1. Add a new project - Windows Application Packaging Project (C# UWP)
  2. Add the test project as a reference in the new packaging project

Hermes in particular has a different version for UWP apps vs. Win32 apps, and if we end up with the wrong version it could cause problems (maybe like what you're seeing here).

https://github.com/WilliamWelsh/react-native-windows-hermes-fail

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) and removed Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) labels Feb 16, 2024
@tero-paananen
Copy link

We have this kind of project and currently it works with Hermes on release on RNW 0.73.x

I think that solution for you problem is add ContinueOnError="true" flags into react-native-windows/PropertySheets/Bundle.Common.targets into commands Exec and Move

diff --git a/node_modules/react-native-windows/PropertySheets/Bundle.Common.targets b/node_modules/react-native-windows/PropertySheets/Bundle.Common.targets
index 8170719..1124f9a 100644
--- a/node_modules/react-native-windows/PropertySheets/Bundle.Common.targets
+++ b/node_modules/react-native-windows/PropertySheets/Bundle.Common.targets
@@ -19,9 +19,9 @@
   <!-- See https://github.com/facebook/react-native/blob/07d090dbc6c46b8f3760dbd25dbe0540c18cb3f3/react.gradle#L190 for reference -->
   <Target Name="CompileHermesBytecode" AfterTargets="MakeBundle" Condition="'$(UseBundle)' == 'true' AND '$(UseHermes)' == 'true'">
     <Message Importance="High" Text="Running [$(HermesCompilerCommand) -emit-binary -out $(BundleOutputFile).hbc $(BundleOutputFile) $(HermesCompilerFlags) -output-source-map] to precompile bundle file." />
-    <Exec Command='$(HermesCompilerCommand) -emit-binary -out "$(BundleOutputFile).hbc" "$(BundleOutputFile)" $(HermesCompilerFlags) -output-source-map' ConsoleToMSBuild="true" WorkingDirectory="$(BundleCommandWorkingDir)" />
-    <Move SourceFiles="$(BundleOutputFile).hbc" DestinationFiles="$(BundleOutputFile)" />
-    <Move SourceFiles="$(BundleOutputFile).hbc.map" DestinationFiles="$(HermesSourceMap)" />
+    <Exec Command='$(HermesCompilerCommand) -emit-binary -out "$(BundleOutputFile).hbc" "$(BundleOutputFile)" $(HermesCompilerFlags) -output-source-map' ContinueOnError="true" ConsoleToMSBuild="true" WorkingDirectory="$(BundleCommandWorkingDir)" />
+    <Move SourceFiles="$(BundleOutputFile).hbc" ContinueOnError="true" DestinationFiles="$(BundleOutputFile)" />
+    <Move SourceFiles="$(BundleOutputFile).hbc.map" ContinueOnError="true" DestinationFiles="$(HermesSourceMap)" />
     <Exec Command='node "$(ReactNativeDir)\scripts\compose-source-maps.js" "$(PackagerSourceMap)" "$(HermesSourceMap)" -o "$(BundleSourceMap)"' ConsoleToMSBuild="true" WorkingDirectory="$(BundleCommandWorkingDir)" />
   </Target>
 </Project>
\ No newline at end of file

@tero-paananen
Copy link

There is our RNW 0.73 patch

diff --git a/node_modules/react-native-windows/Libraries/Components/View/View.windows.js b/node_modules/react-native-windows/Libraries/Components/View/View.windows.js
index 5367fe6..cf1e578 100644
--- a/node_modules/react-native-windows/Libraries/Components/View/View.windows.js
+++ b/node_modules/react-native-windows/Libraries/Components/View/View.windows.js
@@ -191,7 +191,7 @@ const View: React.AbstractComponent<
         }
         return child;
       });
-      if (updatedChildren.length == 1) {
+      if (updatedChildren?.length == 1) {
         return updatedChildren[0];
       } else {
         return updatedChildren;
diff --git a/node_modules/react-native-windows/Microsoft.ReactNative.Managed.CodeGen/Microsoft.ReactNative.Managed.CodeGen.csproj b/node_modules/react-native-windows/Microsoft.ReactNative.Managed.CodeGen/Microsoft.ReactNative.Managed.CodeGen.csproj
index 59ed3e1..a6fe347 100644
--- a/node_modules/react-native-windows/Microsoft.ReactNative.Managed.CodeGen/Microsoft.ReactNative.Managed.CodeGen.csproj
+++ b/node_modules/react-native-windows/Microsoft.ReactNative.Managed.CodeGen/Microsoft.ReactNative.Managed.CodeGen.csproj
@@ -15,6 +15,9 @@
     
     <Nullable>enable</Nullable>
     <LangVersion>8.0</LangVersion>
+
+    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
+    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
   </PropertyGroup>
 
   <ItemGroup>
diff --git a/node_modules/react-native-windows/Microsoft.ReactNative/Modules/NativeUIManager.cpp b/node_modules/react-native-windows/Microsoft.ReactNative/Modules/NativeUIManager.cpp
index af36d60..685927d 100644
--- a/node_modules/react-native-windows/Microsoft.ReactNative/Modules/NativeUIManager.cpp
+++ b/node_modules/react-native-windows/Microsoft.ReactNative/Modules/NativeUIManager.cpp
@@ -953,7 +953,8 @@ void NativeUIManager::SetLayoutPropsRecursive(int64_t tag) {
       const auto hasLayoutChanged = !YogaFloatEquals(left, shadowNode.m_layout.Left) ||
           !YogaFloatEquals(top, shadowNode.m_layout.Top) || !YogaFloatEquals(width, shadowNode.m_layout.Width) ||
           !YogaFloatEquals(height, shadowNode.m_layout.Height);
-      if (hasLayoutChanged) {
+      const auto isValidLayout = !isnan(width) && !isnan(height);
+      if (isValidLayout && hasLayoutChanged) {
         React::JSValueObject layout{{"x", left}, {"y", top}, {"height", height}, {"width", width}};
         React::JSValueObject eventData{{"target", tag}, {"layout", std::move(layout)}};
         pViewManager->DispatchCoalescingEvent(tag, L"topLayout", MakeJSValueWriter(std::move(eventData)));
diff --git a/node_modules/react-native-windows/PropertySheets/Bundle.Common.targets b/node_modules/react-native-windows/PropertySheets/Bundle.Common.targets
index 8170719..1124f9a 100644
--- a/node_modules/react-native-windows/PropertySheets/Bundle.Common.targets
+++ b/node_modules/react-native-windows/PropertySheets/Bundle.Common.targets
@@ -19,9 +19,9 @@
   <!-- See https://github.com/facebook/react-native/blob/07d090dbc6c46b8f3760dbd25dbe0540c18cb3f3/react.gradle#L190 for reference -->
   <Target Name="CompileHermesBytecode" AfterTargets="MakeBundle" Condition="'$(UseBundle)' == 'true' AND '$(UseHermes)' == 'true'">
     <Message Importance="High" Text="Running [$(HermesCompilerCommand) -emit-binary -out $(BundleOutputFile).hbc $(BundleOutputFile) $(HermesCompilerFlags) -output-source-map] to precompile bundle file." />
-    <Exec Command='$(HermesCompilerCommand) -emit-binary -out "$(BundleOutputFile).hbc" "$(BundleOutputFile)" $(HermesCompilerFlags) -output-source-map' ConsoleToMSBuild="true" WorkingDirectory="$(BundleCommandWorkingDir)" />
-    <Move SourceFiles="$(BundleOutputFile).hbc" DestinationFiles="$(BundleOutputFile)" />
-    <Move SourceFiles="$(BundleOutputFile).hbc.map" DestinationFiles="$(HermesSourceMap)" />
+    <Exec Command='$(HermesCompilerCommand) -emit-binary -out "$(BundleOutputFile).hbc" "$(BundleOutputFile)" $(HermesCompilerFlags) -output-source-map' ContinueOnError="true" ConsoleToMSBuild="true" WorkingDirectory="$(BundleCommandWorkingDir)" />
+    <Move SourceFiles="$(BundleOutputFile).hbc" ContinueOnError="true" DestinationFiles="$(BundleOutputFile)" />
+    <Move SourceFiles="$(BundleOutputFile).hbc.map" ContinueOnError="true" DestinationFiles="$(HermesSourceMap)" />
     <Exec Command='node "$(ReactNativeDir)\scripts\compose-source-maps.js" "$(PackagerSourceMap)" "$(HermesSourceMap)" -o "$(BundleSourceMap)"' ConsoleToMSBuild="true" WorkingDirectory="$(BundleCommandWorkingDir)" />
   </Target>
 </Project>
\ No newline at end of file

@WilliamWelsh
Copy link
Author

After updating those four files, my packaged Hermes app runs in release now! Even from the Microsoft store as a flight

@tero-paananen
Copy link

I did previously issue about this but could not manage to find that anymore. Reason why we need that hack is our project structure - packaging project.

@tero-paananen
Copy link

I do not remember fully this now but it was related to somehow managed to copy Hermes compiled binary bundle.

@tero-paananen
Copy link

tero-paananen commented Feb 20, 2024

We have somehow NuGet restore issue with packaging project and RNW 0.73.x. I have to call nuget restore from PowerShell to get my project build. Calling Nuget Restore from Visual Studio fails into error that some package.json is missing.

#10059 (comment)

If you use npx react-native run-windows this issue does not exists because run-windows scripts calls NuGet restore.

Here is some kind of packaging project example https://github.com/microsoft/react-native-windows-samples/tree/main/samples/AppServiceDemo I tested about year ago that when enabling Hermes in that example it failed into this same issue and i made issue for that microsoft/react-native-windows-samples#776

@WilliamWelsh
Copy link
Author

So how do we move forward with getting this to work in future versions without having to manually patch?

@jonthysell
Copy link
Contributor

Does adding "ContinueOnError" mean you're not actually using hermes bytecode? It sounds like the hermes compiler is complaining about your bundle, so my guess would be it "works" now, but with a regular JS bundle.

@jonthysell jonthysell changed the title Hermes fails to run in release mode for packaged projects Hermes bytecode compilation fails in release mode when app is included in a separate wapproj project Feb 22, 2024
@tero-paananen
Copy link

Does adding "ContinueOnError" mean you're not actually using hermes bytecode? It sounds like the hermes compiler is complaining about your bundle, so my guess would be it "works" now, but with a regular JS bundle.

Hermes bytecode is in use, see more from here microsoft/react-native-windows-samples#776 (comment)

@chrisglein
Copy link
Member

So how do we move forward with getting this to work in future versions without having to manually patch?

As far as this patch: #12708 (comment)
Most of it you could put into a PR to be evaluated. But that part that sets ContinueOnError wouldn't be something we would want to merge to the default template.

If there are JS compilation errors, those will need to be fixed instead of setting ContinueOnError.

@chrisglein chrisglein removed the Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) label Feb 26, 2024
@chrisglein
Copy link
Member

Closing because workaround exists and this is a nonstandard configuration. For reducing need for patches, we can look at PRs on this. But original issue has been unblocked.

@tero-paananen
Copy link

tero-paananen commented Feb 26, 2024

In example package project is Hermes bundle build 2 times like i wrote in the example's issue

Hermes build hermes.exe -emit-binary... is done two times: first with appservicedemo and then with the package appservicedemo.Package when it try to build already builded hermes bundle and fails.

thats why "continue on error" hack is only workaround that i found for this.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Invalid Triage https://github.com/microsoft/react-native-windows/wiki/Triage-Process (label applied by bot) label Feb 27, 2024
@chrisglein chrisglein removed the Invalid Triage https://github.com/microsoft/react-native-windows/wiki/Triage-Process (label applied by bot) label Apr 30, 2024
@chrisglein chrisglein added this to the Backlog milestone Apr 30, 2024
@maoziliang
Copy link

Are there any PRs fixing this issue?

@WilliamWelsh
Copy link
Author

Are there any PRs fixing this issue?

No, I have to manually patch for every update

@warrenronsiek
Copy link

I run this powershell script in my CI to auto-fix the problem during every build:

$filePath = "node_modules/react-native-windows/PropertySheets/Bundle.Common.targets"
[xml]$xml = Get-Content $filePath
$namespace = @{msb = "http://schemas.microsoft.com/developer/msbuild/2003"}
function Add-ContinueOnErrorAttribute {
    param ($element)
    if (-not $element.Attributes["ContinueOnError"]) {
      $attr = $xml.CreateAttribute("ContinueOnError")
      $attr.Value = "true"
      $element.Attributes.Append($attr) | Out-Null
    }
}
$execElements = $xml.SelectNodes("//msb:Exec", $namespace)
foreach ($exec in $execElements) {
  if ($exec.InnerText -notlike "*compose-source-maps.js*") {
    Add-ContinueOnErrorAttribute $exec
  }
}
$moveElements = $xml.SelectNodes("//msb:Move", $namespace)
foreach ($move in $moveElements) {
  Add-ContinueOnErrorAttribute $move
}
$xml.Save($filePath)

FWIW - @chrisglein , yes the project structure is non standard, but if you want to access any OS internals via full trust you have to do this non-standard structure. The UWP "happy path" is very narrow and if you want to do anything outside that, you have to bundle UWP+fullTrust inside a WAP, which leads to this error.

@WilliamWelsh
Copy link
Author

Exactly ! This is why I think we need an official patch for this, I think this error is going to occur more and more as rnw gets more adopted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants