Fix Svelte target ID mismatch with Hugo shortcode IDs #18

Open
xrd wants to merge 1 commit from fix/svekyll-target-id-mismatch into main
Owner

Problem

The template main.js hardcoded 'svekyll-app' as the Svelte mount target, but Hugo shortcodes generate IDs like svekyll-app-{slug} (e.g., svekyll-app-test).

This caused the Svelte app to fail mounting with:

Uncaught TypeError: can't access property '$$', i is undefined

Root Cause

  • templates/svekyll-template/src/main.js line 5: const targetId = 'svekyll-app'
  • Hugo shortcode generates: <div id="svekyll-app-{slug}">
  • document.getElementById("svekyll-app") returns null

Fix

Added a fallback in templates/svekyll-template/src/main.js that queries for any element with ID starting with svekyll-app- when the exact ID is not found.

Fixes #17

## Problem The template `main.js` hardcoded `'svekyll-app'` as the Svelte mount target, but Hugo shortcodes generate IDs like `svekyll-app-{slug}` (e.g., `svekyll-app-test`). This caused the Svelte app to fail mounting with: ``` Uncaught TypeError: can't access property '$$', i is undefined ``` ## Root Cause - `templates/svekyll-template/src/main.js` line 5: `const targetId = 'svekyll-app'` - Hugo shortcode generates: `<div id="svekyll-app-{slug}">` - `document.getElementById("svekyll-app")` returns `null` ## Fix Added a fallback in `templates/svekyll-template/src/main.js` that queries for any element with ID starting with `svekyll-app-` when the exact ID is not found. Fixes #17
The template main.js hardcoded 'svekyll-app' as the mount target, but
Hugo shortcodes generate IDs like 'svekyll-app-{slug}'. This caused the
Svelte app to fail mounting with:

  Uncaught TypeError: can't access property '14779', i is undefined

Added a fallback that queries for any element with ID starting with
'svekyll-app-' when the exact ID is not found.
xrd force-pushed fix/svekyll-target-id-mismatch from 33adbd8a9f to 979d5a54d9 2026-10-23 21:36:17 +00:00 Compare
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix/svekyll-target-id-mismatch:fix/svekyll-target-id-mismatch
git switch fix/svekyll-target-id-mismatch

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff fix/svekyll-target-id-mismatch
git switch fix/svekyll-target-id-mismatch
git rebase main
git switch main
git merge --ff-only fix/svekyll-target-id-mismatch
git switch fix/svekyll-target-id-mismatch
git rebase main
git switch main
git merge --no-ff fix/svekyll-target-id-mismatch
git switch main
git merge --squash fix/svekyll-target-id-mismatch
git switch main
git merge --ff-only fix/svekyll-target-id-mismatch
git switch main
git merge fix/svekyll-target-id-mismatch
git push origin main
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
svekyll/sprinkyll!18
No description provided.