Skip to content

Commit

Permalink
Add timeout to JS bundle creation in release builds (#14063)
Browse files Browse the repository at this point in the history
## Description

This PR sets a timeout for the bundle command (`npx react-native bundle`) that happens during release builds with `run-windows`. This is because sometimes Metro can hang indefinitely even after it's done, causing the command to not exit, and otherwise hold up a good build from finishing.

The new timeout defaults to 5m (a new app takes ~40s to bundle) but this variable can easily be modified by defining `BundleCommandTimeoutMs` MSBuild property.

For our new project tests, setting the timeout to 1m, so that, in theory, if the bundle actually finished at 40s, then timing out won't block the remainder of the build.

### Type of Change
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)

### Why
See above.

May help fix some of the times we've seen hanging with #14055.

### What
See above.

## Screenshots
N/A

## Testing
Verified build continues after the timeout has hit.

## Changelog
Should this change be included in the release notes: _yes_

Add timeout to JS bundle creation in release builds
  • Loading branch information
jonthysell authored Nov 4, 2024
1 parent 3191a4a commit 914b6b7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions .ado/templates/react-native-init-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ steps:
${{ else }}:
workingDirectory: $(Agent.BuildDirectory)\testcli
restoreLockedMode: false # Allow new lockfile to be created
moreMSBuildProps: ',BundleCommandTimeoutMs=60000' # Reduce bundle timeout to 1m

- template: upload-build-logs.yml
parameters:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Add timeout to JS bundle creation in release builds",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion vnext/PropertySheets/Bundle.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<MakeDir Directories="$(BundleContentRoot)" />
<MakeDir Directories="$(BundleSourceMapDir)" />
<Message Importance="High" Text="Running [$(BundleCliCommand) --platform windows --entry-file $(BundleEntryFile) --bundle-output $(BundleOutputFile) --assets-dest $(BundleContentRoot) --dev $(UseDevBundle) --reset-cache --sourcemap-output $(PackagerSourceMap) $(BundlerExtraArgs)] to build bundle file." />
<Exec Command='$(BundleCliCommand) --platform windows --entry-file "$(BundleEntryFile)" --bundle-output "$(BundleOutputFile)" --assets-dest "$(BundleContentRoot)" --dev $(UseDevBundle) --reset-cache --sourcemap-output "$(PackagerSourceMap)" $(BundlerExtraArgs)' ConsoleToMSBuild="true" WorkingDirectory="$(BundleCommandWorkingDir)" />
<Exec Command='$(BundleCliCommand) --platform windows --entry-file "$(BundleEntryFile)" --bundle-output "$(BundleOutputFile)" --assets-dest "$(BundleContentRoot)" --dev $(UseDevBundle) --reset-cache --sourcemap-output "$(PackagerSourceMap)" $(BundlerExtraArgs)' ConsoleToMSBuild="true" WorkingDirectory="$(BundleCommandWorkingDir)" Timeout="$(BundleCommandTimeoutMs)" ContinueOnError="true" />
</Target>

<!-- See https://github.com/facebook/react-native/blob/07d090dbc6c46b8f3760dbd25dbe0540c18cb3f3/react.gradle#L190 for reference -->
Expand Down
3 changes: 3 additions & 0 deletions vnext/PropertySheets/Bundle.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<!-- This should be the app package root, this is where the bundle command will be run from -->
<BundleCommandWorkingDir Condition="'$(BundleCommandWorkingDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(ProjectDir), 'package.json'))</BundleCommandWorkingDir>

<!-- This timeout is to catch when the bundler hangs and can be increased for larger apps -->
<BundleCommandTimeoutMs Condition="'$(BundleCommandTimeoutMs)' == ''">300000</BundleCommandTimeoutMs>

<!-- Entry file of the JS bundle. Defaults to use index.windows.js if it exists, otherwise index.js -->
<BundleEntryFile Condition="'$(BundleEntryFile)' == '' and Exists('$(BundleCommandWorkingDir)\index.windows.js')">index.windows.js</BundleEntryFile>
<BundleEntryFile Condition="'$(BundleEntryFile)' == ''">index.js</BundleEntryFile>
Expand Down

0 comments on commit 914b6b7

Please sign in to comment.