slidevjs / slidev

Presentation Slides for Developers
https://sli.dev
MIT License
33.49k stars 1.37k forks source link

Duplicate root with "theme: ./" due to difference in trailing slash #1783

Closed cebamps closed 3 months ago

cebamps commented 3 months ago

Describe the bug

When developing a theme, the create-slidev-theme template puts theme: ./ in the frontmatter (source). This adds a new root to Slidev's roots option, which coincides with the userRoot and should be deduplicated (source), but isn't because the theme contains a final slash and the user root does not.

As a result, when developing a theme, global layers are rendered twice because each duplicated root contributes one rendered global-top.vue for example.

Replacing theme: ./ with theme: . in the frontmatter works around the issue, fortunately.

Minimal reproduction

Steps to reproduce the behavior:

  1. Initialize a theme following the docs: https://sli.dev/guide/write-theme
  2. Add a global-top.vue file to the root of the theme, with some content.
  3. Run the dev server with environment variable DEBUG=slidev:options.
  4. Observe that the component is rendered twice. Observe that the debug output for roots shows something like this:
    ...
    slidev:options   roots: [
    slidev:options     '/Users/c/slidev-theme-foo/',
    slidev:options     '/Users/c/slidev-theme-foo'
    slidev:options   ]

Environment

KermanX commented 3 months ago

Fixed via 787de2c.