-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
Isolate global styles #339
Comments
Start a new pull request in StackBlitz Codeflow. |
I have the same issue: #66 (comment) I would love to see this be addressed in some way. I'm open to sponsoring a little to help make this happen :) |
Not strictly related, but there's no iframe at all in grid mode. |
This is already supported :) |
Yes that’s not the problem. Global styles leaking into histoire’s UI are the problem
Met vriendelijke groet,
Luuk Lamers
…On 10 Feb 2023 at 20:31 +0100, Guillaume Chau ***@***.***>, wrote:
> support the [scoped] attribute on style blocks inside SFCs
This is already supported :)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Yeah it's a tough issue with no obvious solution (iframe comes with a lot of tradeoffs) |
Would it be possible to run the stories inside a shadow DOM? That would isolate the styles completely. |
I don't think so, as I have a global stylesheet that gets imported through the main javascript file. I can't import the stylesheet in every story. |
After playing around a bit I noticed some things that may help this along. Perhaps sharing them sparks some new inspiration to get this resolved. The styles imported in This can be confirmed by opening the Stackblitz in the original post, opening the app in a new tab, and playing around with it there. It starts out with three I guess this means the feature is somehow halfway there already? It definitely seems to be possible, at least. |
This is an issue that prevents histoire from being used in a ton of projects, unfortunately. I hope this’ll be solved soon. Thanks to @PhotonBursted’s comment, I wrote this in my const isIframe = window.self !== window.top;
document.head
.querySelectorAll("style[type='text/css']:not([data-vite-dev-id*='histoire'])")
.forEach((style) => isIframe || style.remove()); It’s dirty but it works with v0.15.9 |
@Aksamyt but work only in dev mode for using // src/histoire.setup.ts
import { defineSetupVue3 } from '@histoire/plugin-vue'
import { IonicVue } from '@ionic/vue'
export const setupVue3 = defineSetupVue3(async ({ app, story, variant }) => {
// https://github.com/histoire-dev/histoire/issues/339#issuecomment-1522329599
const isIframe = window.self !== window.top
if (isIframe) {
await import('@/theme/styles')
app.use(IonicVue)
}
}) // src/theme/styles.ts
import '@ionic/vue/css/core.css'
import '@ionic/vue/css/normalize.css'
import '@ionic/vue/css/structure.css'
import '@ionic/vue/css/typography.css'
import '@ionic/vue/css/padding.css'
import '@ionic/vue/css/float-elements.css'
import '@ionic/vue/css/text-alignment.css'
import '@ionic/vue/css/text-transformation.css'
import '@ionic/vue/css/flex-utils.css'
import '@ionic/vue/css/display.css'
import './variables.css' And additional styles bundled in BUT Dynamic CSS load in one bundle:
build: {
rollupOptions: {
output: {
manualChunks: {
ionic: ['@ionic/vue', '@ionic/vue-router'],
},
},
},
}, proof: histoire/packages/histoire/src/node/build.ts Lines 142 to 143 in 9209381
histoire/packages/histoire/src/node/build.ts Line 165 in 9209381
pnpm patch histoire@0.16.1 and remove code in 1 step, and set --- a/dist/node/build.js
+++ b/dist/node/build.js
@@ -114,29 +114,19 @@ export async function build(ctx) {
config(config) {
// Don't externalize
config.build.rollupOptions.external = [];
- // Force chunk strategy
- config.build.rollupOptions.output = {
- manualChunks(id) {
- if (!id.includes('@histoire/app') && id.includes('node_modules')) {
- for (const test of ctx.config.build?.excludeFromVendorsChunk ?? []) {
- if ((typeof test === 'string' && id.includes(test)) || (test instanceof RegExp && test.test(id))) {
- // Excluded from vendor chunk
- return;
- }
- }
- return 'vendor';
- }
- },
- };
+
// Force vite build options
Object.assign(config.build, {
outDir: ctx.config.outDir,
emptyOutDir: true,
- cssCodeSplit: false,
+ cssCodeSplit: true,
minify: false,
// Don't build in SSR mode
ssr: false,
}); We are getting the expected effect. But then the HTML generation breaks down, and this is the basic logic need @Akryum help, because now using ionic is not fully production ready. |
Hi, any updates about isolating Histoire UI and global story styles? That issue defeats Histoire's purpose (sandboxing). |
Was so excited at how fast we got this working, but now I am embarrassed to show anyone how bad it looks, because the global styles leak and make Histoire look terrible. |
Also hacky - however works for now - took this and added it to setupCode: export default defineConfig({
plugins: [
HstVue(),
HstNuxt(),
],
setupCode: [`const isIframe = window.self !== window.top;
const sandbox = window.location.pathname === '/__sandbox.html';
document.head
.querySelectorAll("style[type='text/css']:not([data-vite-dev-id*='histoire'])")
.forEach((style) => (!isIframe && !sandbox) && style.remove());`]
}) This does not work with variants, since these don't use an iFrame. |
Hi, any updates about this issue? |
Describe the bug
When using a histoire.setup.js or style block inside a Vue 3 SFC to import global styles, these styles bleed out into the Histoire styling, overriding color, inputs and theming.
I don't think my application styling should inform Histoire's styling, right?
I suggest to either:
styles
in histoire.config.jsReproduction
*{color: black}
https://stackblitz.com/edit/histoire-vue3-starter-cbmzxo?file=src%2Findex.css
System Info
Used Package Manager
Validations
The text was updated successfully, but these errors were encountered: