Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing default composables also imports default theme's styles #182

Closed
mrbbot opened this issue Dec 10, 2020 · 2 comments
Closed

Importing default composables also imports default theme's styles #182

mrbbot opened this issue Dec 10, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@mrbbot
Copy link

mrbbot commented Dec 10, 2020

Describe the bug
When using a custom theme, importing composables like useRoute from "vitepress" in the Layout component also imports the styles for the default theme.

To Reproduce

  1. Follow the Getting Started guide to create a new site
  2. Create docs/.vitepress/theme/Layout.vue with the following contents:
<template>
  <Content />
</template>

<script setup>
// import { useRoute } from "vitepress";
// const route = useRoute();
</script>
  1. Create docs/.vitepress/theme/index.js with the following contents:
import Layout from "./Layout.vue";

export default {
  Layout,
};
  1. Run yarn docs:dev and open http://localhost:3000. Note the heading doesn't have any styles applied to it:

image

  1. Uncomment the lines in the <script setup> section in docs/.vitepress/theme/Layout.vue. Note the heading now has the default styles applied to it, even though we only imported useRoute:

image

Expected behavior
The heading should remain unstyled since we aren't explicitly importing any styles.

System Info

  • vitepress version: v0.9.2
  • vite version: v1.0.0-rc.13
  • Node version: v12.20.0
  • OS version: macOS Catalina 10.15.7

Additional context
I had a quick look at the Vitepress code and it looks like the problem might be to do with this line:

export { default as defaultTheme } from '/@default-theme/index'

Adding the following to docs/.vitepress/config.js:

module.exports = {
  alias: {
    "/@default-theme/index": "/@theme/empty.js",
  },
};

...and creating an empty file docs/.vitepress/theme/empty.js prevents the default styles being applied.

@mrbbot mrbbot added the bug: pending triage Maybe a bug, waiting for confirmation label Dec 10, 2020
@mrbbot mrbbot changed the title Importing default composables also imports default theme's stlyes Importing default composables also imports default theme's styles Dec 10, 2020
@harlan-zw
Copy link
Contributor

harlan-zw commented Jan 2, 2021

This one also tripped me up when I upgraded from version 0.8.1 to latest, I got around it by importing the exactly what I needed.

This causes the styles from the default theme to be applied:

import { useSiteData } from 'vitepress'

This does what we'd expect without the leakage:

import { useSiteData } from 'vitepress/dist/client/app/composables/siteData'

With the suggestion of importing for the default theme from this issue #190 would it make sense / be possible to remove the default theme export from the types/index.d.ts file? (assuming that is the culript)

@kiaking kiaking added enhancement New feature or request and removed bug: pending triage Maybe a bug, waiting for confirmation labels Feb 5, 2021
@kiaking
Copy link
Member

kiaking commented Feb 5, 2021

This issue is fixed in the latest code. Importing things like useSiteData will not include styles. So the styles are only included when you actually do import DefaultTheme from 'vitepress/theme' 👍

@kiaking kiaking closed this as completed Feb 5, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants