Javascript exception is thrown when using htmx features #7642

Closed
opened 2025-12-29 20:26:23 +01:00 by adam · 4 comments
Owner

Originally created by @kkthxbye-code on GitHub (Feb 15, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.5.0-dev

Python version

3.10

Steps to Reproduce

  1. Go to the device list
  2. Type something in the quick search bar

Expected Behavior

The table should be filtered and no exceptions should be thrown in the javascript console

Observed Behavior

The table is filtered, but an exception is thrown in the console:

netbox.js?v=3.5.0-dev:16081 Uncaught TypeError: Cannot read properties of undefined (reading 'showContent')
    at l2.destroy (netbox.js?v=3.5.0-dev:16081:93)
    at new l2 (netbox.js?v=3.5.0-dev:16091:33)
    at new APISelect (netbox.js?v=3.5.0-dev:16546:19)
    at initApiSelect (netbox.js?v=3.5.0-dev:17024:7)
    at initSelect (netbox.js?v=3.5.0-dev:17097:7)
    at HTMLDivElement.initDepedencies (netbox.js?v=3.5.0-dev:20446:7)
    at $ (netbox.js?v=3.5.0-dev:1538:25)
    at netbox.js?v=3.5.0-dev:2487:23
    at G (netbox.js?v=3.5.0-dev:236:17)
    at o3 (netbox.js?v=3.5.0-dev:2483:21)
Originally created by @kkthxbye-code on GitHub (Feb 15, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.5.0-dev ### Python version 3.10 ### Steps to Reproduce 1. Go to the device list 2. Type something in the quick search bar ### Expected Behavior The table should be filtered and no exceptions should be thrown in the javascript console ### Observed Behavior The table is filtered, but an exception is thrown in the console: ``` netbox.js?v=3.5.0-dev:16081 Uncaught TypeError: Cannot read properties of undefined (reading 'showContent') at l2.destroy (netbox.js?v=3.5.0-dev:16081:93) at new l2 (netbox.js?v=3.5.0-dev:16091:33) at new APISelect (netbox.js?v=3.5.0-dev:16546:19) at initApiSelect (netbox.js?v=3.5.0-dev:17024:7) at initSelect (netbox.js?v=3.5.0-dev:17097:7) at HTMLDivElement.initDepedencies (netbox.js?v=3.5.0-dev:20446:7) at $ (netbox.js?v=3.5.0-dev:1538:25) at netbox.js?v=3.5.0-dev:2487:23 at G (netbox.js?v=3.5.0-dev:236:17) at o3 (netbox.js?v=3.5.0-dev:2483:21) ```
adam added the type: bugstatus: acceptedbeta labels 2025-12-29 20:26:23 +01:00
adam closed this issue 2025-12-29 20:26:23 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Feb 15, 2023):

Issue is caused by: cb0dfe5e49

The exceptions stems from trying to initialize a SlimSelect on a select field that has already been initialized.

Potential fix is to append :not([data-ssid]) to the getElements argument the following places:

cb0dfe5e49/netbox/project-static/src/select/color.ts (L43)

cb0dfe5e49/netbox/project-static/src/select/static.ts (L5)

cb0dfe5e49/netbox/project-static/src/select/api/index.ts (L5)

There's a related issue here: https://github.com/brianvoe/slim-select/issues/317

However slim-select has been updated to a version "2.0" which vastly changes the library, with no documentation of the exact changes (the js ecosystem is great). Because of this an ugrade to the new version is not really feasible currently imo.

@jeremystretch - When you get the time, could you explain the reason for the following commit? cb0dfe5e49 - I'm not sure if my fix works, because I'm not sure what the change is supposed to fix.

@kkthxbye-code commented on GitHub (Feb 15, 2023): Issue is caused by: https://github.com/netbox-community/netbox/pull/11646/commits/cb0dfe5e49b2a7a1c8c8b7ffd70887910195b5ab The exceptions stems from trying to initialize a SlimSelect on a select field that has already been initialized. Potential fix is to append `:not([data-ssid])` to the getElements argument the following places: https://github.com/netbox-community/netbox/blob/cb0dfe5e49b2a7a1c8c8b7ffd70887910195b5ab/netbox/project-static/src/select/color.ts#L43 https://github.com/netbox-community/netbox/blob/cb0dfe5e49b2a7a1c8c8b7ffd70887910195b5ab/netbox/project-static/src/select/static.ts#L5 https://github.com/netbox-community/netbox/blob/cb0dfe5e49b2a7a1c8c8b7ffd70887910195b5ab/netbox/project-static/src/select/api/index.ts#L5 There's a related issue here: https://github.com/brianvoe/slim-select/issues/317 However slim-select has been updated to a version "2.0" which vastly changes the library, with no documentation of the exact changes (the js ecosystem is great). Because of this an ugrade to the new version is not really feasible currently imo. @jeremystretch - When you get the time, could you explain the reason for the following commit? https://github.com/netbox-community/netbox/pull/11646/commits/cb0dfe5e49b2a7a1c8c8b7ffd70887910195b5ab - I'm not sure if my fix works, because I'm not sure what the change is supposed to fix.
Author
Owner

@jeremystretch commented on GitHub (Feb 17, 2023):

The commit ensures that new form elements are initialized by SlimSelect after being loaded via an HTMX call. I'll see if I can clean it up a bit.

@jeremystretch commented on GitHub (Feb 17, 2023): The commit ensures that new form elements are initialized by SlimSelect after being loaded via an HTMX call. I'll see if I can clean it up a bit.
Author
Owner

@kkthxbye-code commented on GitHub (Feb 23, 2023):

I found some places where this actually breaks functionality.

/dcim/device-roles/add/ and /dcim/rack-roles/add/ - the automatic slug field and the regenerate slug buttons do not work. The sidebar also doesn't work properly (starts folded, when it should be unfolded).

I think my fix should be good by only initializing select fields if they haven't already been slim-selectified.

@kkthxbye-code commented on GitHub (Feb 23, 2023): I found some places where this actually breaks functionality. `/dcim/device-roles/add/` and `/dcim/rack-roles/add/` - the automatic slug field and the regenerate slug buttons do not work. The sidebar also doesn't work properly (starts folded, when it should be unfolded). I think my fix should be good by only initializing select fields if they haven't already been slim-selectified.
Author
Owner

@jeremystretch commented on GitHub (Feb 25, 2023):

Ok, I believe I've got this sorted. Thanks for tracking this down @kkthxbye-code!

@jeremystretch commented on GitHub (Feb 25, 2023): Ok, I believe I've got this sorted. Thanks for tracking this down @kkthxbye-code!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7642