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

TRA | No listeners for event #4160

Open
aquinary opened this issue Mar 23, 2025 · 6 comments
Open

TRA | No listeners for event #4160

aquinary opened this issue Mar 23, 2025 · 6 comments
Labels
Bug Something isn't working

Comments

@aquinary
Copy link

Description

When using the runtime.Eventsummit(a.ctx, "update", "test") I receive a message in the terminal saying TRA | No listeners for event 'update'.

But EventsEmit itself is working and I get the result on the frontend.

To Reproduce

Modify example func:

func (a *App) Greet(name string) string {
	runtime.EventsEmit(a.ctx, "update", "test")
	return fmt.Sprintf("Hello %s, It's show time!", name)
}

and modify web component:

EventsOn("update", (data) => {
  name = data; // name will update
});

Expected behaviour

I'm not sure if this is a mistake. Documentation on Events in Wails is extremely scarce.

This message not show in production mode

Screenshots

No response

Attempted Fixes

search in issues

System Details

# Wails
Version         | v2.10.1
Package Manager | nixpkgs


# System
WARNING: failed to read int from file: open /sys/devices/system/cpu/cpu0/online: no such file or directory
┌────────────────────────────────────────────────────────┐
| OS           | NixOS                                   |
| Version      | 24.11                                   |
| ID           | nixos                                   |
| Go Version   | go1.23.6                                |
| Platform     | linux                                   |
| Architecture | amd64                                   |
| CPU          | Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz |
| GPU          | Unknown                                 |
| Memory       | 16GB                                    |
└────────────────────────────────────────────────────────┘

# Dependencies
┌────────────────────────────────────────────────────────────┐
| Dependency | Package Name     | Status    | Version        |
| *docker    | nixos.docker     | Installed | 25.0.6         |
| gcc        | nixos.gcc        | Installed | 13.3.0         |
| libgtk-3   | nixos.gtk3       | Available | 3.24.43        |
| libwebkit  | nixos.webkitgtk  | Available | 2.44.3+abi=4.0 |
| npm        | nixos.nodejs     | Installed | 20.15.1        |
| *nsis      | nixos.nsis       | Available | 3.06.1         |
| pkg-config | nixos.pkg-config | Installed | 0.29.2         |
| *upx       | nixos.upx        | Available | 4.2.3          |
|                                                            |
└───────────────── * - Optional Dependency ──────────────────┘

Additional context

No response

@aquinary aquinary added the Bug Something isn't working label Mar 23, 2025
@atwright147
Copy link

I have experienced this too

@Tokimon
Copy link

Tokimon commented Mar 27, 2025

I get this message when using the DragAndDrop configuration with OnFileDrop. However the functionality seems to work anyway. So I am not sure why the message pops up 🤔

@RockyF
Copy link

RockyF commented Mar 31, 2025

Same bug.

I had reviewed the code,you should EventsOn event which you emit...

@emm1R
Copy link

emm1R commented Mar 31, 2025

I have the same issue. This was not happening in version 2.9.2.

@leaanthony
Copy link
Member

Could someone please use git bisect and determine where the breaking change happened? Thanks.

@superDingda
Copy link
Contributor

superDingda commented Apr 9, 2025

@leaanthony @aquinary

Interestingly, this isn't a new issue introduced in 2.10.1 — it's actually been there all along. The only reason it's surfaced now is because the loglevel mechanism in 2.10.1 has stopped working as expected.

Wails' event system supports event propagation in all directions: frontend ↔ frontend, frontend ↔ backend, backend ↔ backend. So when you call the following:

runtime.EventsEmit(a.ctx, "update", "test")
  1. It tries to notify Go-side listeners for the "update" event
    – unfortunately, none exist, so it logs: TRA | No listeners for event ***
  2. It tries to notifies any frontend-side listeners

If you're curious, you can follow this trail in the v2.10.1 source code to see where and why the log appears:

runtime.EventsEmit(a.ctx, "update", "test")

// v2/pkg/runtime/events.go:46
func EventsEmit(ctx context.Context, eventName string, optionalData ...interface{}) {
	events := getEvents(ctx)
	events.Emit(eventName, optionalData...)
}

// v2/internal/frontend/runtime/events.go:57
func (e *Events) Emit(eventName string, data ...interface{}) {
	e.notifyBackend(eventName, data...)
	for _, thisFrontend := range e.frontend {
		thisFrontend.Notify(eventName, data...)
	}
}

// v2/internal/frontend/runtime/events.go:119
func (e *Events) notifyBackend(eventName string, data ...interface{}) {
	e.notifyLock.Lock()
	defer e.notifyLock.Unlock()

	// Get list of event listeners
	listeners := e.listeners[eventName]
	if listeners == nil {
		e.log.Trace("No listeners for event '%s'", eventName)  // <- this is the message you're seeing
		return
	}
	// ...
}

// v2/internal/frontend/desktop/windows/frontend.go:601
func (f *Frontend) Notify(name string, data ...interface{}) {
	notification := EventNotify{
		Name: name,
		Data: data,
	}
	payload, err := json.Marshal(notification)
	if err != nil {
		f.logger.Error(err.Error())
		return
	}
	f.ExecJS(`window.wails.EventsNotify('` + template.JSEscapeString(string(payload)) + `');`)  
	// <- this triggers the frontend’s EventsOn handler
}

Conclusion:

I don't think this is actually a bug. A simple improvement would be to make the log message more descriptive. For example, change it to:

e.log.Trace("No backend listeners for event '%s'", eventName)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants