mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-18 02:04:06 -05:00
[PR #20343] [MERGED] fix: prevent TypeError when file.url is undefined in UserMessage #112887
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/20343
Author: @silentoplayz
Created: 1/3/2026
Status: ✅ Merged
Merged: 1/3/2026
Merged by: @tjbck
Base:
dev← Head:fix/user-message-undefined-file-url📝 Commits (1)
17c3facfix: handle undefined file.url in UserMessage to prevent TypeError📊 Changes
1 file changed (+1 additions, -1 deletions)
View changed files
📝
src/lib/components/chat/Messages/UserMessage.svelte(+1 -1)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.
This is to ensure large feature PRs are discussed with the community first, before starting work on it. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
This PR fixes a TypeError that occurs when rendering user messages with file attachments where the
file.urlproperty isundefined. The error"can't access property 'startsWith', $.get(...).url is undefined"was thrown when the code attempted to call.startsWith()on an undefined URL value.Root cause:
The code in UserMessage.svelte at line 197 was calling
file.url.startsWith()without first checking iffile.urlexists, causing a crash when messages contained files with missing or undefined URL properties.Solution:
Added optional chaining (
?.) to safely access the url property before calling.startsWith(), allowing the code to gracefully handle undefined values without throwing errors.Changed
file.urlpropertyFixed
file.urlis undefinedfile.url.startsWith('data')andfile.url.startsWith('http')calls"Uncaught TypeError: can't access property 'startsWith', $.get(...).url is undefined"Breaking Changes
Additional Information
Technical Details
Before:
After:
The optional chaining operator (
?.) ensures that iffile.urlisundefinedornull, the expression returnsundefinedinstead of throwing a TypeError. The ternary operator then falls through to the alternative path, constructing the URL using the API base path.Error Stack Trace (Fixed)
Before
After
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.