Skip to content

Commit 1ec3708

Browse files
leaanthonyclaude
andauthored
feat: Make Vite server timeout configurable (#4374)
* feat: Make Vite server timeout configurable - Add ViteServerTimeout field to wails.json configuration (default: 10 seconds) - Add --viteservertimeout CLI flag for dev command - Update error message to be more descriptive about timeout duration - Fix issue #4372 where slow Vite servers with SvelteKit/Tailwind exceeded 10s timeout Users can now configure the timeout via: 1. wails.json: "viteServerTimeout": 30 2. CLI flag: wails dev --viteservertimeout 30 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * docs: Add documentation for viteServerTimeout configuration - Document viteServerTimeout field in wails.json project config - Add --viteservertimeout CLI flag documentation - Update save flag description to include new option 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Update changelog --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a0937fd commit 1ec3708

6 files changed

Lines changed: 27 additions & 6 deletions

File tree

v2/cmd/wails/flags/dev.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Dev struct {
3131
AppArgs string `flag:"appargs" description:"arguments to pass to the underlying app (quoted and space separated)"`
3232
Save bool `flag:"save" description:"Save the given flags as defaults"`
3333
FrontendDevServerURL string `flag:"frontenddevserverurl" description:"The url of the external frontend dev server to use"`
34+
ViteServerTimeout int `flag:"viteservertimeout" description:"The timeout in seconds for Vite server detection (default: 10)"`
3435

3536
// Internal state
3637
devServerURL *url.URL
@@ -105,6 +106,13 @@ func (d *Dev) loadAndMergeProjectConfig() error {
105106

106107
d.AppArgs, _ = lo.Coalesce(d.AppArgs, d.projectConfig.AppArgs)
107108

109+
if d.ViteServerTimeout == 0 && d.projectConfig.ViteServerTimeout != 0 {
110+
d.ViteServerTimeout = d.projectConfig.ViteServerTimeout
111+
} else if d.ViteServerTimeout == 0 {
112+
d.ViteServerTimeout = 10 // Default timeout
113+
}
114+
d.projectConfig.ViteServerTimeout = d.ViteServerTimeout
115+
108116
if d.Save {
109117
err = d.projectConfig.Save()
110118
if err != nil {

v2/cmd/wails/internal/dev/dev.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func Application(f *flags.Dev, logger *clilogger.CLILogger) error {
9999
// frontend:dev:watcher command.
100100
frontendDevAutoDiscovery := projectConfig.IsFrontendDevServerURLAutoDiscovery()
101101
if command := projectConfig.DevWatcherCommand; command != "" {
102-
closer, devServerURL, devServerViteVersion, err := runFrontendDevWatcherCommand(projectConfig.GetFrontendDir(), command, frontendDevAutoDiscovery)
102+
closer, devServerURL, devServerViteVersion, err := runFrontendDevWatcherCommand(projectConfig.GetFrontendDir(), command, frontendDevAutoDiscovery, projectConfig.ViteServerTimeout)
103103
if err != nil {
104104
return err
105105
}
@@ -205,7 +205,7 @@ func runCommand(dir string, exitOnError bool, command string, args ...string) er
205205
}
206206

207207
// runFrontendDevWatcherCommand will run the `frontend:dev:watcher` command if it was given, ex- `npm run dev`
208-
func runFrontendDevWatcherCommand(frontendDirectory string, devCommand string, discoverViteServerURL bool) (func(), string, string, error) {
208+
func runFrontendDevWatcherCommand(frontendDirectory string, devCommand string, discoverViteServerURL bool, viteServerTimeout int) (func(), string, string, error) {
209209
ctx, cancel := context.WithCancel(context.Background())
210210
scanner := NewStdoutScanner()
211211
cmdSlice := strings.Split(devCommand, " ")
@@ -225,9 +225,9 @@ func runFrontendDevWatcherCommand(frontendDirectory string, devCommand string, d
225225
select {
226226
case serverURL := <-scanner.ViteServerURLChan:
227227
viteServerURL = serverURL
228-
case <-time.After(time.Second * 10):
228+
case <-time.After(time.Second * time.Duration(viteServerTimeout)):
229229
cancel()
230-
return nil, "", "", errors.New("failed to find Vite server URL")
230+
return nil, "", "", fmt.Errorf("failed to find Vite server URL: Timed out waiting for Vite to output a URL after %d seconds", viteServerTimeout)
231231
}
232232
}
233233

v2/internal/project/project.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ type Project struct {
9393
// Frontend directory
9494
FrontendDir string `json:"frontend:dir"`
9595

96+
// The timeout in seconds for Vite server detection. Default 10
97+
ViteServerTimeout int `json:"viteServerTimeout"`
98+
9699
Bindings Bindings `json:"bindings"`
97100
}
98101

@@ -175,6 +178,9 @@ func (p *Project) setDefaults() {
175178
if p.DevServer == "" {
176179
p.DevServer = "localhost:34115"
177180
}
181+
if p.ViteServerTimeout == 0 {
182+
p.ViteServerTimeout = 10
183+
}
178184
if p.NSISType == "" {
179185
p.NSISType = "multiple"
180186
}

website/docs/reference/cli.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ Your system is ready for Wails development!
194194
| -extensions | Extensions to trigger rebuilds (comma separated) | go |
195195
| -forcebuild | Force build of application | |
196196
| -frontenddevserverurl "url" | Use 3rd party dev server url to serve assets, EG Vite | "" |
197+
| -viteservertimeout | The timeout in seconds for Vite server detection when frontend dev server url is set to 'auto' | 10 |
197198
| -ldflags "flags" | Additional ldflags to pass to the compiler | |
198199
| -loglevel "loglevel" | Loglevel to use - Trace, Debug, Info, Warning, Error | Debug |
199200
| -nocolour | Turn off colour cli output | false |
@@ -202,7 +203,7 @@ Your system is ready for Wails development!
202203
| -race | Build with Go's race detector | false |
203204
| -reloaddirs | Additional directories to trigger reloads (comma separated) | Value in `wails.json` |
204205
| -s | Skip building the frontend | false |
205-
| -save | Saves the given `assetdir`, `reloaddirs`, `wailsjsdir`, `debounce`, `devserver` and `frontenddevserverurl` flags in `wails.json` to become the defaults for subsequent invocations. | |
206+
| -save | Saves the given `assetdir`, `reloaddirs`, `wailsjsdir`, `debounce`, `devserver`, `frontenddevserverurl` and `viteservertimeout` flags in `wails.json` to become the defaults for subsequent invocations. | |
206207
| -skipbindings | Skip bindings generation | |
207208
| -skipembedcreate | Skip automatic creation of non-existent embed directories and gitkeep files | |
208209
| -tags "extra tags" | Build tags to pass to compiler (quoted and space separated) | |

website/docs/reference/project-config.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ The project config resides in the `wails.json` file in the project directory. Th
3434
"frontend:dev:watcher": "",
3535
// URL to a 3rd party dev server to be used to serve assets, EG Vite. \nIf this is set to 'auto' then the devServerUrl will be inferred from the Vite output
3636
"frontend:dev:serverUrl": "",
37+
// The timeout in seconds for Vite server detection when frontend:dev:serverUrl is set to 'auto'. Default: 10
38+
"viteServerTimeout": 10,
3739
// Relative path to the directory that the auto-generated JS modules will be created
3840
"wailsjsdir": "",
3941
// The name of the binary
@@ -124,7 +126,7 @@ The project config resides in the `wails.json` file in the project directory. Th
124126

125127
This file is read by the Wails CLI when running `wails build` or `wails dev`.
126128

127-
The `assetdir`, `reloaddirs`, `wailsjsdir`, `debounceMS`, `devserver` and `frontenddevserverurl` flags in `wails build/dev` will update the project config
129+
The `assetdir`, `reloaddirs`, `wailsjsdir`, `debounceMS`, `devserver`, `frontenddevserverurl` and `viteservertimeout` flags in `wails build/dev` will update the project config
128130
and thus become defaults for subsequent runs.
129131

130132
The JSON Schema for this file is located [here](https://wails.io/schemas/config.v2.json).

website/src/pages/changelog.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
## [Unreleased]
1616

17+
### Added
18+
19+
- Configure Vite timeout by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/4374)
20+
1721
## v2.10.2 - 2025-07-06
1822

1923
### Fixed

0 commit comments

Comments
 (0)