{"record":{"id":"b7b800d3ed1013d4","repo":"Dogfalo/materialize","slug":"slider-was-already-initialized","errorCode":null,"errorMessage":"Slider was already initialized.","messagePattern":"Slider was already initialized\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"extras/noUiSlider/nouislider.js","lineNumber":2079,"sourceCode":"\n            // Save current spectrum direction as testOptions in testRange call\n            // doesn't rely on current direction\n            newOptions.spectrum.direction = scope_Spectrum.direction;\n            scope_Spectrum = newOptions.spectrum;\n\n            // Limit, margin and padding depend on the spectrum but are stored outside of it. (#677)\n            options.margin = newOptions.margin;\n            options.limit = newOptions.limit;\n            options.padding = newOptions.padding;\n\n            // Invalidate the current positioning so valueSet forces an update.\n            scope_Locations = [];\n            valueSet(optionsToUpdate.start || v, fireSetEvent);\n        }\n\n        // Throw an error if the slider was already initialized.\n        if ( scope_Target.noUiSlider ) {\n            throw new Error('Slider was already initialized.');\n        }\n\n        // Create the base element, initialise HTML and set classes.\n        // Add handles and connect elements.\n        addSlider(scope_Target);\n        addElements(options.connect, scope_Base);\n\n        scope_Self = {\n            destroy: destroy,\n            steps: getCurrentStep,\n            on: bindEvent,\n            off: removeEvent,\n            get: valueGet,\n            set: valueSet,\n            reset: valueReset,\n            // Exposed for unit testing, don't use this in your application.\n            __moveHandles: function(a, b, c) { moveHandles(a, b, scope_Locations, c); },\n            options: originalOptions, // Issue #600, #678","sourceCodeStart":2061,"sourceCodeEnd":2097,"githubUrl":"https://github.com/Dogfalo/materialize/blob/824e78248b3de81e383445e76ffb04cc3264fe7d/extras/noUiSlider/nouislider.js#L2061-L2097","documentation":"noUiSlider stamps the created API onto target.noUiSlider. The initializer guards against double initialization by throwing if that property already exists, preventing duplicate event bindings, overlapping handles, and orphaned DOM.","triggerScenarios":"Call noUiSlider.create(el, ...) twice on the same DOM element without first calling el.noUiSlider.destroy(). Common in React/Vue/jQuery when a component re-mounts or a re-render re-runs the create call.","commonSituations":"React useEffect without a cleanup, jQuery plugin reapplied to an existing element, re-running a setup function after a route change, or hot-module reloading that re-executes module init.","solutions":["Call el.noUiSlider.destroy() before re-creating, or in a framework cleanup hook.","Guard with: if (!el.noUiSlider) noUiSlider.create(el, opts);","In React useEffect, return () => el.noUiSlider && el.noUiSlider.destroy()."],"exampleFix":"// before\nuseEffect(() => { noUiSlider.create(ref.current, opts); }, []);\n// after\nuseEffect(() => {\n  noUiSlider.create(ref.current, opts);\n  return () => ref.current.noUiSlider && ref.current.noUiSlider.destroy();\n}, []);","handlingStrategy":"validation","validationCode":"function safeCreate(el, opts) {\n  if (el.noUiSlider) {\n    el.noUiSlider.destroy();\n  }\n  return noUiSlider.create(el, opts);\n}","typeGuard":"function isInitialized(el) { return !!el && !!el.noUiSlider; }","tryCatchPattern":"try {\n  noUiSlider.create(el, opts);\n} catch (e) {\n  if (/already initialized/.test(e.message) && el.noUiSlider) {\n    el.noUiSlider.destroy();\n    noUiSlider.create(el, opts);\n  } else { throw e; }\n}","preventionTips":["Always pair create() with a destroy() in the same lifecycle scope.","In React, return a cleanup from useEffect that calls destroy().","Guard re-entrancy with if (!el.noUiSlider) before create()."],"tags":["nouislider","lifecycle","initialization","react","double-init"],"backgroundTag":null,"analyzedSha":"824e78248b3de81e383445e76ffb04cc3264fe7d","analyzedAt":"2026-08-13T04:14:22.506Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}