[PR #22853] [CLOSED] fix(modal): resolve ReferenceError for idx in InputVariablesModal #42518

Closed
opened 2026-04-25 14:23:48 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/22853
Author: @futhgar
Created: 3/19/2026
Status: Closed

Base: devHead: fix/input-variables-modal-idx


📝 Commits (1)

  • 93d5c47 fix(modal): resolve ReferenceError for idx in InputVariablesModal

📊 Changes

1 file changed (+24 additions, -16 deletions)

View changed files

📝 src/lib/components/chat/MessageInput/InputVariablesModal.svelte (+24 -16)

📄 Description

Pull Request Checklist

  • Target branch: Verify that the pull request targets the dev branch.
  • Description: Provided below.
  • Changelog: Provided below.
  • Documentation: No user-facing behavior changes; no docs update needed.
  • Dependencies: No new or upgraded dependencies.
  • Testing: Manually verified the fix compiles correctly and the problematic {@const} derived is no longer generated. Full build passes.
  • Agentic AI Code: This PR has gone through human review and manual testing.
  • Code review: Self-reviewed.
  • Design & Architecture: Minimal fix, no new settings or architectural changes.
  • Git Hygiene: Single atomic commit addressing one issue.
  • Title Prefix: fix

Changelog Entry

Description

When selecting a custom prompt with template variables (e.g. {{variable_name}}), the Input Variables modal threw ReferenceError: idx is not defined and displayed an infinite loading spinner instead of the input fields.

The root cause is a {@const} declaration with rest-spread destructuring ({@const { type, ...variableAttributes } = variables[variable] ?? {}}) inside an {#each} block. In Svelte 5's legacy reactivity mode, this pattern creates a $.derived_safe_equal() that interferes with the each-block index variable (idx) scoping when combined with {...variableAttributes} spread on elements that also reference idx for their id attribute.

The fix moves the rest-spread destructuring from an inline {@const} to a helper function (getVariableAttributes) in the <script> section. This avoids the problematic Svelte 5 compiled derived while preserving the same attribute-spreading behavior.

Added

  • getVariableAttributes() helper function that extracts all properties except type from a variable definition

Fixed

  • ReferenceError: idx is not defined in InputVariablesModal.svelte when opening the Input Variables modal (Fixes #22748)
  • Infinite loading spinner on the Input Variables modal

Additional Information

  • The {@const} with rest-spread destructuring inside {#each} blocks is a known problematic pattern in Svelte 5 legacy mode. Moving the destructuring to a script-level function avoids the compiler generating a derived that interferes with the each-block index variable scoping.
  • Build verified: vite build passes successfully with the fix applied.
  • Related Svelte issues: sveltejs/svelte#7134, sveltejs/svelte#7843

Contributor License Agreement


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/22853 **Author:** [@futhgar](https://github.com/futhgar) **Created:** 3/19/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix/input-variables-modal-idx` --- ### 📝 Commits (1) - [`93d5c47`](https://github.com/open-webui/open-webui/commit/93d5c473b1844598a3af8ec1f56bb225d4f286e3) fix(modal): resolve ReferenceError for idx in InputVariablesModal ### 📊 Changes **1 file changed** (+24 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `src/lib/components/chat/MessageInput/InputVariablesModal.svelte` (+24 -16) </details> ### 📄 Description # Pull Request Checklist - [x] **Target branch:** Verify that the pull request targets the `dev` branch. - [x] **Description:** Provided below. - [x] **Changelog:** Provided below. - [x] **Documentation:** No user-facing behavior changes; no docs update needed. - [x] **Dependencies:** No new or upgraded dependencies. - [x] **Testing:** Manually verified the fix compiles correctly and the problematic `{@const}` derived is no longer generated. Full build passes. - [x] **Agentic AI Code:** This PR has gone through human review and manual testing. - [x] **Code review:** Self-reviewed. - [x] **Design & Architecture:** Minimal fix, no new settings or architectural changes. - [x] **Git Hygiene:** Single atomic commit addressing one issue. - [x] **Title Prefix:** `fix` # Changelog Entry ### Description When selecting a custom prompt with template variables (e.g. `{{variable_name}}`), the Input Variables modal threw `ReferenceError: idx is not defined` and displayed an infinite loading spinner instead of the input fields. The root cause is a `{@const}` declaration with rest-spread destructuring (`{@const { type, ...variableAttributes } = variables[variable] ?? {}}`) inside an `{#each}` block. In Svelte 5's legacy reactivity mode, this pattern creates a `$.derived_safe_equal()` that interferes with the each-block index variable (`idx`) scoping when combined with `{...variableAttributes}` spread on elements that also reference `idx` for their `id` attribute. The fix moves the rest-spread destructuring from an inline `{@const}` to a helper function (`getVariableAttributes`) in the `<script>` section. This avoids the problematic Svelte 5 compiled derived while preserving the same attribute-spreading behavior. ### Added - `getVariableAttributes()` helper function that extracts all properties except `type` from a variable definition ### Fixed - `ReferenceError: idx is not defined` in `InputVariablesModal.svelte` when opening the Input Variables modal (Fixes #22748) - Infinite loading spinner on the Input Variables modal ### Additional Information - The `{@const}` with rest-spread destructuring inside `{#each}` blocks is a known problematic pattern in Svelte 5 legacy mode. Moving the destructuring to a script-level function avoids the compiler generating a derived that interferes with the each-block index variable scoping. - Build verified: `vite build` passes successfully with the fix applied. - Related Svelte issues: [sveltejs/svelte#7134](https://github.com/sveltejs/svelte/issues/7134), [sveltejs/svelte#7843](https://github.com/sveltejs/svelte/issues/7843) ### Contributor License Agreement - [x] By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 14:23:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#42518