{"record":{"id":"c4a874286c18e060","repo":"ankane/pghero","slug":"nouislider-slider-was-already-initialized","errorCode":null,"errorMessage":"noUiSlider: Slider was already initialized.","messagePattern":"noUiSlider: Slider was already initialized\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/assets/javascripts/pghero/nouislider.js","lineNumber":2318,"sourceCode":"            },\n            getTooltips: function () {\n                return scope_Tooltips;\n            },\n            getOrigins: function () {\n                return scope_Handles;\n            },\n            pips: pips, // Issue #594\n        };\n        return scope_Self;\n    }\n    // Run the standard initializer\n    function initialize(target, originalOptions) {\n        if (!target || !target.nodeName) {\n            throw new Error(\"noUiSlider: create requires a single element, got: \" + target);\n        }\n        // Throw an error if the slider was already initialized.\n        if (target.noUiSlider) {\n            throw new Error(\"noUiSlider: Slider was already initialized.\");\n        }\n        // Test the options and create the slider environment;\n        var options = testOptions(originalOptions);\n        var api = scope(target, options, originalOptions);\n        target.noUiSlider = api;\n        return api;\n    }\n    var nouislider = {\n        // Exposed for unit testing, don't use this in your application.\n        __spectrum: Spectrum,\n        // A reference to the default classes, allows global changes.\n        // Use the cssClasses option for changes to one slider.\n        cssClasses: cssClasses,\n        create: initialize,\n    };\n\n    exports.create = initialize;\n    exports.cssClasses = cssClasses;","sourceCodeStart":2300,"sourceCodeEnd":2336,"githubUrl":"https://github.com/ankane/pghero/blob/7edb57986ffd36f9d64f0830c4ccc90a5eac46d6/app/assets/javascripts/pghero/nouislider.js#L2300-L2336","documentation":"initialize() stores the API on the element itself (target.noUiSlider) and refuses to run twice on the same element: if that property is already set it throws this Error. It guards against double initialization corrupting the existing slider's DOM and event bindings.","triggerScenarios":"Calling noUiSlider.create on an element that was already initialized - typically when an init function runs again after a Turbo/Turbolinks page restore (cached page), a React useEffect running twice (e.g. StrictMode), or a hot-reload / partial page refresh that re-runs setup scripts without removing the old slider.","commonSituations":"Rails UJS :page:load and turbolinks:load both firing; JavaScript bundled once but executed on every AJAX content swap; dev-time hot module replacement re-executing the module.","solutions":["Guard before creating: if (!el.noUiSlider) { noUiSlider.create(el, options); }","Or destroy first when rebuilding: if (el.noUiSlider) { el.noUiSlider.destroy(); } then create again","Move initialization to a single lifecycle hook that cannot re-run for the same DOM node"],"exampleFix":"// before\nnoUiSlider.create(el, options);\n\n// after\nif (el.noUiSlider) {\n  el.noUiSlider.destroy();\n}\nnoUiSlider.create(el, options);","handlingStrategy":"validation","validationCode":"if (el.noUiSlider) {\n  el.noUiSlider.destroy(); // or return early to reuse the existing slider\n}\nnoUiSlider.create(el, options);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make initialization idempotent in Turbo/Turbolinks/React setups","Destroy before rebuilding when options may have changed"],"tags":["nouislider","duplicate-initialization","dom","javascript"],"backgroundTag":"duplicate-initialization","analyzedSha":"7edb57986ffd36f9d64f0830c4ccc90a5eac46d6","analyzedAt":"2026-08-21T17:33:54.942Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}