Fix Svelte target ID mismatch with Hugo shortcode IDs #18
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/svekyll-target-id-mismatch"
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?
Problem
The template
main.jshardcoded'svekyll-app'as the Svelte mount target, but Hugo shortcodes generate IDs likesvekyll-app-{slug}(e.g.,svekyll-app-test).This caused the Svelte app to fail mounting with:
Root Cause
templates/svekyll-template/src/main.jsline 5:const targetId = 'svekyll-app'<div id="svekyll-app-{slug}">document.getElementById("svekyll-app")returnsnullFix
Added a fallback in
templates/svekyll-template/src/main.jsthat queries for any element with ID starting withsvekyll-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.33adbd8a9fto979d5a54d9View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.