Skip to content

fix: correct default sectionImage path in new-section layout#12

Open
dp-daesung wants to merge 1 commit intoDawntraoz:masterfrom
dp-daesung:fix/new-section-default-image-path
Open

fix: correct default sectionImage path in new-section layout#12
dp-daesung wants to merge 1 commit intoDawntraoz:masterfrom
dp-daesung:fix/new-section-default-image-path

Conversation

@dp-daesung
Copy link
Copy Markdown

@dp-daesung dp-daesung commented Mar 27, 2026

Problem

The default value for sectionImage in layouts/new-section.vue is ../public/section-illustration.svg. Since this path does not start with /, resolveAssetUrl passes it through unchanged. The browser then tries to resolve it relative to the page URL, which fails — leaving the section slide with no illustration.

Reported in #8.

Root Cause: Regression in 1.1.2

In 1.1.1, the layout imported resolveAssetUrl from @slidev/client/layoutHelper, which handled the relative path correctly. PR #6 replaced this with a local ../layoutHelper, whose implementation only processes paths starting with /:

export function resolveAssetUrl(url: string) {
  if (url.startsWith('/'))
    return import.meta.env.BASE_URL + url.slice(1)
  return url  // ../public/... falls through here, broken in browser
}

The default value ../public/section-illustration.svg was never updated to match, causing it to break in 1.1.2.

How Slidev Serves Theme Public Assets

Slidev uses vite-plugin-static-copy to serve theme public/ assets under the /theme/ path (not /). So section-illustration.svg from the theme package is available at /theme/section-illustration.svg.

Fix

Change the default from ../public/section-illustration.svg to /theme/section-illustration.svg:

- default: "../public/section-illustration.svg",
+ default: "/theme/section-illustration.svg",

This allows sectionImage to be safely omitted in frontmatter and the illustration will render correctly.

Fixes #8

The previous default '../public/section-illustration.svg' is a relative
path that does not start with '/', so resolveAssetUrl passes it through
unchanged. Browsers then try to resolve it relative to the page URL,
causing the illustration to fail to load.

Changing the default to '/section-illustration.svg' makes resolveAssetUrl
prepend BASE_URL correctly, matching how Slidev serves theme public assets
at the root path.

Fixes Dawntraoz#8
@dp-daesung dp-daesung force-pushed the fix/new-section-default-image-path branch from 44cd1bd to 6d1fbd4 Compare March 27, 2026 23:27
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.

Default Section Illustration Does Not Render

1 participant