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

[Bug]: Inline HTML <script> tags get removed from DOM in rendered story #29275

Open
basher opened this issue Oct 4, 2024 · 1 comment
Open

Comments

@basher
Copy link

basher commented Oct 4, 2024

Describe the bug

I'm creating a new UI component library for an existing web app in Storybook/HTML.

Component HTML contains inline <script> tags, which are getting stripped out of story DOM:

Image

These inline scripts need to be detectable via document.querySelector() inside global script, which are loaded inside preview-head.html.

They're returning null.

Is there a reason why inline scripts get removed from DOM???

Reproduction link

https://github.com/basher/sb-test

Reproduction steps

  1. Load the story from reproduction link.
  2. Scripts executing via preview-head.html cannot find inline script tags inside story DOM.

System

Storybook Environment Info:

System:
OS: Windows 10 10.0.19045
CPU: (4) x64 Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz
Binaries:
Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD <----- active
Browsers:
Chrome: 129.0.6668.90
Edge: Chromium (127.0.2651.74)
npmPackages:
@storybook/html: ^8.2.3 => 8.3.5
@storybook/html-vite: ^8.2.3 => 8.3.5
storybook: ^8.2.3 => 8.3.5

Additional context

No response

@basher
Copy link
Author

basher commented Oct 7, 2024

The inline <script> tags get moved to a #scripts-root node, so they do actually "execute" whatever is inside them.

However, I need the scripts to remain where they are originally - i.e. inside #storybook-root - so that I can mimic the real behaviour of the web app that I'm Storybooking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants