Skip to content

Commit

Permalink
Real time preview and cache update fix (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
ingerbird authored Aug 15, 2024
1 parent e9c4c65 commit cb148f7
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 29 deletions.
2 changes: 2 additions & 0 deletions src/app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ async function fetchData(
slug: string,
version: 'published' | 'draft' | undefined,
) {
const cacheVersion = Math.floor(Date.now() / 1000);
const sbParams: ISbStoriesParams = {
version: version,
cv: cacheVersion, // Force bypass cache
};
const storyblokApi = getStoryblokApi();

Expand Down
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { apiPlugin, storyblokInit } from '@storyblok/react';
import { StoryblokBridgeLoader } from '@storyblok/react/rsc';
import { Viewport } from 'next';
import { headers } from 'next/headers';
import Script from 'next/script';
Expand Down Expand Up @@ -86,6 +87,7 @@ export default function RootLayout({
<PosthogPageView />
</Suspense>
</PosthogProvider>
<StoryblokBridgeLoader options={{}} />
</body>
</html>
);
Expand Down
2 changes: 2 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ async function fetchData(
slug: string,
version: 'published' | 'draft' | undefined,
) {
const cacheVersion = Math.floor(Date.now() / 1000);
const sbParams: ISbStoriesParams = {
version: version,
cv: cacheVersion, // Force bypass cache
};
const storyblokApi = getStoryblokApi();

Expand Down
16 changes: 0 additions & 16 deletions src/components/PageComponent.js

This file was deleted.

14 changes: 1 addition & 13 deletions src/lib/storyblok.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
import { getStoryblokApi, ISbResult } from '@storyblok/react';
import { ISbResult } from '@storyblok/react';

import { siteConfig } from '@/constants/config';
import { isProd } from '@/constants/env';
import { openGraph } from '@/utils/og';

export const fetchStory = async (slug: string) => {
const storyblokApi = getStoryblokApi();
try {
const { data } = await storyblokApi.get(`cdn/stories/${slug}`, {
version: isProd ? 'published' : 'draft',
});
return data?.story || null;
} catch (error) {
return null;
}
};

export function generateMetadataFromStory(
story: ISbResult,
isHomePage: boolean,
Expand Down

0 comments on commit cb148f7

Please sign in to comment.