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

Live Preview: dispatch an event after DOM is updated #864

Open
1 task done
bentouch-digital opened this issue Jul 15, 2024 · 2 comments
Open
1 task done

Live Preview: dispatch an event after DOM is updated #864

bentouch-digital opened this issue Jul 15, 2024 · 2 comments
Labels
investigation [Issue] The Storyblok team is investigating

Comments

@bentouch-digital
Copy link

Description

Hi,

We use Astro with UnoCSS to generate our CSS. In preview mode, we use the plugin "unocss/runtime" which generate CSS class at runtime.

Live preview is a nice feature but if we modify a field which generate new CSS the CSS it not generated by UnoCSS because we can't detect when the body is updated. It would be nice if a JS event is dispatched as the Astro Navigation work. Astro navigation dispatch events when the page swap.

Suggested solution or improvement

Dispatch an event when the body is updated in file /lib/live-preview/handleStoryblokMessage.ts

Additional context

No response

Validations

@bentouch-digital bentouch-digital added enhancement pending-author [Issue] Awaiting further information or action from the issue author pending-triage [Issue] Ticket is pending to be prioritised labels Jul 15, 2024
@schabibi1 schabibi1 added investigation [Issue] The Storyblok team is investigating and removed enhancement pending-author [Issue] Awaiting further information or action from the issue author pending-triage [Issue] Ticket is pending to be prioritised labels Jul 18, 2024
@schabibi1
Copy link
Contributor

Hi, @bentouch-digital
We'll have a look at this issue. Please feel free to add additional resources to help us investigate. (i.e. Screen recording of the behavior you described, reproduction steps, etc)

@bentouch-digital
Copy link
Author

Hi @schabibi1,

I don't have any screen recording but the idea is just to dispatch a JS event when the body is updated.
If a Javascript event were dispatched, we could do this:

document.addEventListener('storyblok-astro-live-preview-body-updated', () => {
  // Here is the callback we could run code every time the body is updated via live preview
  console.log('Live preview: body updated');
  initUnoCssRuntime(); // With this line all our CSS is regenerated
});

dipankarmaikap added a commit that referenced this issue Dec 24, 2024
A new event is introduced that triggers when changes are made in the Storyblok Visual Editor.
This is particularly helpful for generating CSS dynamically, as outlined in issue #864.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigation [Issue] The Storyblok team is investigating
Projects
None yet
Development

No branches or pull requests

2 participants