ScanInput callback is called multiple times #147

Closed
opened 2025-11-09 02:07:27 +00:00 by Ghost · 3 comments
Ghost commented 2025-11-09 02:07:27 +00:00 (Migrated from code.ole.blue)

After the merge of #139, particularly at https://github.com/strichliste-rs/strichliste-rs/pull/139/files#diff-fb748d4eef48d0e31b49d1cad1e952bb5678d24a204b703946049a530c049777L112-L127 , the scan input callback get's triggered multiple times.

I don't know why, but it seems like the scan_input get's registered multiple times:

In scan_input.rs

    let tmp = Utc::now()
    ...
    console_log(&format!("created handle: {tmp}"));

    on_cleanup(move || {
        console_log(&format!("removed handle: {tmp}"));
        handle.remove();
    });

Console output

# initial page load
created user barcode handle: 2025-11-09 02:18:36.255 UTC -- never gets cleaned up

# clicked on user
created article barcode handle: 2025-11-09 02:18:38.755 UTC -- wtf
removed article barcode handle: 2025-11-09 02:18:38.755 UTC -- wtf
created article barcode handle: 2025-11-09 02:18:38.855 UTC 

# returned to homepage
created user barcode handle: 2025-11-09 02:18:42.806 UTC 
removed article barcode handle: 2025-11-09 02:18:38.855 UTC 
After the merge of #139, particularly at https://github.com/strichliste-rs/strichliste-rs/pull/139/files#diff-fb748d4eef48d0e31b49d1cad1e952bb5678d24a204b703946049a530c049777L112-L127 , the scan input callback get's triggered multiple times. I don't know why, but it seems like the scan_input get's registered multiple times: In `scan_input.rs` ```rust let tmp = Utc::now() ... console_log(&format!("created handle: {tmp}")); on_cleanup(move || { console_log(&format!("removed handle: {tmp}")); handle.remove(); }); ``` Console output ``` # initial page load created user barcode handle: 2025-11-09 02:18:36.255 UTC -- never gets cleaned up # clicked on user created article barcode handle: 2025-11-09 02:18:38.755 UTC -- wtf removed article barcode handle: 2025-11-09 02:18:38.755 UTC -- wtf created article barcode handle: 2025-11-09 02:18:38.855 UTC # returned to homepage created user barcode handle: 2025-11-09 02:18:42.806 UTC removed article barcode handle: 2025-11-09 02:18:38.855 UTC ```
Ghost commented 2025-11-09 02:22:53 +00:00 (Migrated from code.ole.blue)

debug info in branch: 147-scaninput-callback-is-called-multiple-times

debug info in branch: 147-scaninput-callback-is-called-multiple-times
Ghost commented 2025-11-09 02:27:04 +00:00 (Migrated from code.ole.blue)

This seems to indeed be the problem

created user barcode handle: 2025-11-09 02:25:49.181 UTC 
Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC 
There is no user with barcode "123" 
Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC 
There is no user with barcode "2" 
Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC 
There is no user with barcode "1" 
Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC 
There is no user with barcode "2" 
Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC 
There is no user with barcode "3" 
Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC 
There is no user with barcode "1" 
created article barcode handle: 2025-11-09 02:25:56.664 UTC 
removed article barcode handle: 2025-11-09 02:25:56.664 UTC 
created article barcode handle: 2025-11-09 02:25:56.748 UTC 
created user barcode handle: 2025-11-09 02:25:57.448 UTC 
removed article barcode handle: 2025-11-09 02:25:56.748 UTC 
Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC 
Triggering callback user barcode: 2025-11-09 02:25:57.448 UTC 
There is no user with barcode "123" 
There is no user with barcode "123" 
created article barcode handle: 2025-11-09 02:26:17.615 UTC 
removed article barcode handle: 2025-11-09 02:26:17.615 UTC 
created article barcode handle: 2025-11-09 02:26:17.715 UTC 
created user barcode handle: 2025-11-09 02:26:27.798 UTC 
removed article barcode handle: 2025-11-09 02:26:17.715 UTC 
Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC 
Triggering callback user barcode: 2025-11-09 02:25:57.448 UTC 
Triggering callback user barcode: 2025-11-09 02:26:27.798 UTC 
There is no user with barcode "123" 
There is no user with barcode "123" 
There is no user with barcode "123" 
This seems to indeed be the problem ``` created user barcode handle: 2025-11-09 02:25:49.181 UTC Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC There is no user with barcode "123" Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC There is no user with barcode "2" Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC There is no user with barcode "1" Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC There is no user with barcode "2" Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC There is no user with barcode "3" Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC There is no user with barcode "1" created article barcode handle: 2025-11-09 02:25:56.664 UTC removed article barcode handle: 2025-11-09 02:25:56.664 UTC created article barcode handle: 2025-11-09 02:25:56.748 UTC created user barcode handle: 2025-11-09 02:25:57.448 UTC removed article barcode handle: 2025-11-09 02:25:56.748 UTC Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC Triggering callback user barcode: 2025-11-09 02:25:57.448 UTC There is no user with barcode "123" There is no user with barcode "123" created article barcode handle: 2025-11-09 02:26:17.615 UTC removed article barcode handle: 2025-11-09 02:26:17.615 UTC created article barcode handle: 2025-11-09 02:26:17.715 UTC created user barcode handle: 2025-11-09 02:26:27.798 UTC removed article barcode handle: 2025-11-09 02:26:17.715 UTC Triggering callback user barcode: 2025-11-09 02:25:49.181 UTC Triggering callback user barcode: 2025-11-09 02:25:57.448 UTC Triggering callback user barcode: 2025-11-09 02:26:27.798 UTC There is no user with barcode "123" There is no user with barcode "123" There is no user with barcode "123" ```
Ghost commented 2025-11-09 02:33:50 +00:00 (Migrated from code.ole.blue)

I don't really see how this is caused. Why is only the user barcode handles not getting removed?

As a fix, we could create a new store with the current window handle as it's value, since we only need a single scan_input at the same time.

I don't really see how this is caused. Why is only the user barcode handles not getting removed? As a fix, we could create a new store with the current window handle as it's value, since we only need a single scan_input at the same time.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Strichliste/strichliste#147
No description provided.