-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat!: making livepreview stable and removing useStoryblok
function
#1050
base: main
Are you sure you want to change the base?
Conversation
`useStoryblok` function has been deprecated and replaced with a new function, `getLiveStory`. For details on how to use getLiveStory and its capabilities, please refer to the updated documentation.
BREAKING CHANGE: The default export has been replaced with a named export when initializing the Storyblok SDK in your `astro.config.js` file. You should now use: `import { storyblok } from '@storyblok/astro';` Update your imports accordingly to ensure compatibility.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @dipankarmaikap this is a great PR, thanks! The named export is ideal for bundling as is set as a standard, and I like how the getLiveStory
it's particularly adapted for Astro's api needs.
I added you a comment about a typo.
Also, can we add some tests on the new feature/changes? I know some parts of this SDK might not be too easy to test, mostly due to Astro integration. However, as a general developing practice, we should always ensure that what we publish is decently tested, at least with some minimal tests.
|
||
export { getLiveStory, renderRichText, useStoryblokApi } from './lib/healpers'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dipankarmaikap I think there is a typo on the filename, do you mean helpers
?
heyyyy, @dipankarmaikap, @alexjoverm I'm not sure if that's more straightforward:It is to directly allow users to access
Finally, thanks to the team's efforts and improvements, this is the most user-friendly headless CMS I've experienced so far ---
// pages/[...slug].astro
import {
getLiveStory,
useStoryblokApi,
type ISbStoryData,
} from '@storyblok/astro';
import StoryblokComponent from '@storyblok/astro/StoryblokComponent.astro';
import BaseLayout from '../layouts/Layout.astro';
const { slug } = Astro.params;
let story: ISbStoryData | null = null;
if (Astro.locals.liveStory) {
story = liveStory;
} else {
const sbApi = useStoryblokApi();
const { data } = await sbApi.get(`cdn/stories/${slug || 'home'}`, {
version: 'draft',
resolve_relations: ['featured-articles.posts'],
});
story = data?.story;
}
---
<BaseLayout>
{story && <StoryblokComponent blok={story.content} />}
</BaseLayout> |
This PR stabilizes the experimental Live Preview feature and introduces breaking changes. The
useStoryblok
hook is now deprecated and replaced by the newgetLiveStory
function. Below are the key updates and usage examples.Breaking Changes
Removal of
useStoryblok
:The
useStoryblok
hook has been deprecated in favor ofgetLiveStory
. This function simplifies the implementation of live preview in your Astro application.Named Export for
storyblok
:The
storyblok
initialization is now exported as a named export instead of a default export. Update yourastro.config.mjs
imports accordingly.Usage Example
Configure Storyblok in
astro.config.mjs
using the named export:Page Example
Here’s how you can use
getLiveStory
in a page:Listening for Live Preview Updates
When the live preview updates content in the Storyblok editor, a custom event (
storyblok-live-preview-updated
) is triggered. Applications can listen for this event as follows:Closing Issues
This PR addresses and closes the following issue(s):
loadStoryblokBridge
is injected twice #943