Skip to content

feat: defaultBackgroundColor and head config options#837

Open
50rayn wants to merge 1 commit intohistoire-dev:mainfrom
50rayn:feat/default-bg-and-head
Open

feat: defaultBackgroundColor and head config options#837
50rayn wants to merge 1 commit intohistoire-dev:mainfrom
50rayn:feat/default-bg-and-head

Conversation

@50rayn
Copy link
Copy Markdown
Contributor

@50rayn 50rayn commented May 2, 2026

Two small config additions.

defaultBackgroundColorcloses #441

Sets the initial preview background color before the user picks one from the dropdown. Should match a color from backgroundPresets to also highlight the matching entry.

defineConfig({
  defaultBackgroundColor: '#cafff5',
})

headcloses #331, also helps #586

Inject extra <head> tags into both the Histoire app and the story sandbox. Same input shape as Nuxt's useHead, rendered via unhead.

defineConfig({
  head: {
    link: [
      { rel: 'preconnect', href: 'https://fonts.googleapis.com' },
      { rel: 'stylesheet', href: 'https://fonts.googleapis.com/css2?family=Poppins&display=swap' },
    ],
  },
})

Applies in dev (both HTML middlewares) and build (index.html + __sandbox.html).

Notes

  • disableDefaults: true on createHead so unhead doesn't auto-inject lang="en" / its own viewport meta — keeps Histoire's existing template untouched when head is unset.
  • New dep: unhead@^3 in histoire (runtime) and @histoire/shared (types only).
  • Tested on examples/vue3, vue3-themed, vue3-vuetify, svelte4, nuxt4 — all build clean.

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 2, 2026

Deploy Preview for histoire-examples-svelte3 ready!

Name Link
🔨 Latest commit 30569ae
🔍 Latest deploy log https://app.netlify.com/projects/histoire-examples-svelte3/deploys/69f63efa3bc9d10007cfa883
😎 Deploy Preview https://deploy-preview-837--histoire-examples-svelte3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 2, 2026

Deploy Preview for histoire-controls ready!

Name Link
🔨 Latest commit 30569ae
🔍 Latest deploy log https://app.netlify.com/projects/histoire-controls/deploys/69f63efa1444d80007cd4d5b
😎 Deploy Preview https://deploy-preview-837--histoire-controls.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 2, 2026

Deploy Preview for histoire-site ready!

Name Link
🔨 Latest commit 30569ae
🔍 Latest deploy log https://app.netlify.com/projects/histoire-site/deploys/69f63efa85e81600087317b1
😎 Deploy Preview https://deploy-preview-837--histoire-site.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 2, 2026

Deploy Preview for histoire-examples-vue3 ready!

Name Link
🔨 Latest commit 30569ae
🔍 Latest deploy log https://app.netlify.com/projects/histoire-examples-vue3/deploys/69f63efa6d7b080008ca1bb2
😎 Deploy Preview https://deploy-preview-837--histoire-examples-vue3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a defaultBackgroundColor configuration for story previews and adds support for custom <head> tag injection using the unhead library. The changes span the configuration types, the build process, and the Vite development server. Feedback was provided regarding the use of useStorage in the preview settings store, noting that the new default background color may be ignored for existing users who already have a value persisted in their local storage.

responsiveHeight: null,
rotate: false,
backgroundColor: 'transparent',
backgroundColor: histoireConfig.defaultBackgroundColor ?? 'transparent',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of useStorage with a default value means that defaultBackgroundColor will only be applied if there is no existing value in the user's local storage. For existing users who have already visited Histoire, changes to defaultBackgroundColor in the configuration will be ignored because useStorage will prioritize the value already saved in their browser.

To ensure the configured default is respected until a user explicitly chooses a different color, consider using a computed property that falls back to the config value if the stored value is null or undefined.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 2, 2026

Open in StackBlitz

histoire

npm i https://pkg.pr.new/histoire@837

@histoire/app

npm i https://pkg.pr.new/@histoire/app@837

@histoire/controls

npm i https://pkg.pr.new/@histoire/controls@837

@histoire/plugin-nuxt

npm i https://pkg.pr.new/@histoire/plugin-nuxt@837

@histoire/plugin-percy

npm i https://pkg.pr.new/@histoire/plugin-percy@837

@histoire/plugin-screenshot

npm i https://pkg.pr.new/@histoire/plugin-screenshot@837

@histoire/plugin-svelte

npm i https://pkg.pr.new/@histoire/plugin-svelte@837

@histoire/plugin-vue

npm i https://pkg.pr.new/@histoire/plugin-vue@837

@histoire/shared

npm i https://pkg.pr.new/@histoire/shared@837

@histoire/vendors

npm i https://pkg.pr.new/@histoire/vendors@837

commit: 30569ae

@50rayn 50rayn force-pushed the feat/default-bg-and-head branch from 19a369f to 30569ae Compare May 2, 2026 18:14
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.

Ability to pick a default backgroundColor for story previews Option to add tags to the head

1 participant