Skip to content

Fix Youtube Previewing Crashing by adding shorts support#578

Merged
7w1 merged 3 commits intoSableClient:devfrom
nushea:links-msc4095
Mar 28, 2026
Merged

Fix Youtube Previewing Crashing by adding shorts support#578
7w1 merged 3 commits intoSableClient:devfrom
nushea:links-msc4095

Conversation

@nushea
Copy link
Copy Markdown
Contributor

@nushea nushea commented Mar 28, 2026

Description

Added basic shorts support and a fallback to fix it from crashing on shorts.

Fixes #

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

AI disclosure:

  • Partially AI assisted (clarify which code was AI assisted and briefly explain what it does).
  • Fully AI generated (explain what all the generated code does in moderate detail).

Athena has cursed me with the wisdom to fix this.

@nushea nushea requested review from 7w1 and hazre as code owners March 28, 2026 20:12
@nushea nushea closed this Mar 28, 2026
@nushea nushea reopened this Mar 28, 2026
@nushea
Copy link
Copy Markdown
Contributor Author

nushea commented Mar 28, 2026

i swear i am going mad w the browsers ~-~

@7w1 7w1 added this pull request to the merge queue Mar 28, 2026
Merged via the queue into SableClient:dev with commit a8ddeb6 Mar 28, 2026
9 checks passed
@nushea nushea deleted the links-msc4095 branch March 28, 2026 22:49
Just-Insane added a commit to Just-Insane/Sable that referenced this pull request Mar 29, 2026
… parser

Non-video YouTube URLs (channels, @Handles, shorts-style paths without query
params) caused `path.split('?')[1]` to return undefined, crashing with
'Cannot read properties of undefined (reading split)'.

Changed to optional chaining with nullish coalescing fallback:
  `path.split('?')[1]?.split('&') ?? []`

Part of the fix started in SableClient#578 (shorts support).
github-merge-queue bot pushed a commit that referenced this pull request Mar 30, 2026
… parser (#584)

### Description

Fixes a crash when any non-video YouTube URL is previewed — channels
(`youtube.com/@handle`), channel IDs (`youtube.com/channel/...`), or any
URL path without a `?` query string.

The existing code (even after #578) had:
```ts
params = path.split('?')[1].split('&');
```
When there is no `?` in the URL, `split('?')[1]` returns `undefined`,
and calling `.split('&')` on it throws:
> `TypeError: Cannot read properties of undefined (reading 'split')`

Fixed with optional chaining + nullish fallback:
```ts
params = path.split('?')[1]?.split('&') ?? [];
```

This causes `videoId` to remain `undefined` for non-video URLs, which is
handled correctly by the existing `if (!videoId) return null` guard —
the preview simply doesn't render rather than crashing the entire app.

Fixes #

#### Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings

### AI disclosure:

- [x] Partially AI assisted (clarify which code was AI assisted and
briefly explain what it does).

AI identified the root cause after reviewing the PR #578 diff — the
shorts fix added the `/shorts/` branch but left the original
`youtube.com` branch with the same unguarded `.split()` call. The
one-line fix (`?.split('&') ?? []`) was AI-suggested; I reviewed and
confirmed it is correct.
github-merge-queue bot pushed a commit that referenced this pull request Mar 30, 2026
> [!IMPORTANT]
> Merging this PR will create a new release.

## Fixes

* Add youtube shorts support to stop it from crashing sable.
([#578](#578) by @nushea)
* Fix rich-text reply previews and custom-formatted messages so unsafe
HTML is filtered more strictly and Matrix colors render correctly.
([#571](#571) by @hazre)
* Fix crash when previewing non-video YouTube URLs (channels, @Handles,
etc.) that lack query parameters.
([#584](#584) by @Just-Insane)
* fix id handling and id generation for Personas
([#583](#583) by @dozro)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants