Skip to content

Commit 5bdf818

Browse files
committed
v
1 parent 250f1b2 commit 5bdf818

File tree

7 files changed

+78
-2
lines changed

7 files changed

+78
-2
lines changed

packages/basehub/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# basehub
22

3+
## 7.5.26
4+
5+
### Patch Changes
6+
7+
- Add manual revalidation for pending tags
8+
39
## 7.5.25
410

511
### Patch Changes

packages/basehub/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "basehub",
33
"description": "A very fast Headless CMS.",
44
"author": "JB <[email protected]>",
5-
"version": "7.5.25",
5+
"version": "7.5.26",
66
"license": "MIT",
77
"repository": "basehub-ai/basehub",
88
"bugs": "https://github.com/basehub-ai/basehub/issues",

packages/basehub/src/next/toolbar/client-conditional-renderer.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const ClientConditionalRenderer = ({
1717
revalidateTags,
1818
resolvedRef,
1919
getLatestBranches,
20+
humanRevalidatePendingTags,
2021
}: {
2122
draft: boolean;
2223
isForcedDraft: boolean;
@@ -29,6 +30,10 @@ export const ClientConditionalRenderer = ({
2930
status: number;
3031
response: LatestBranch[] | { error: string };
3132
}>;
33+
humanRevalidatePendingTags: (o: {
34+
bshbPreviewToken: string;
35+
ref: string;
36+
}) => Promise<{ success: boolean }>;
3237
resolvedRef: ResolvedRef;
3338
}) => {
3439
const [hasRendered, setHasRendered] = React.useState(false);
@@ -111,6 +116,7 @@ export const ClientConditionalRenderer = ({
111116
seekAndStoreBshbPreviewToken={seekAndStoreBshbPreviewToken}
112117
resolvedRef={resolvedRef}
113118
getLatestBranches={getLatestBranches}
119+
humanRevalidatePendingTags={humanRevalidatePendingTags}
114120
/>,
115121
document.body
116122
);

packages/basehub/src/next/toolbar/client-toolbar.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const ClientToolbar = ({
2020
seekAndStoreBshbPreviewToken,
2121
resolvedRef,
2222
getLatestBranches,
23+
humanRevalidatePendingTags,
2324
}: {
2425
draft: boolean;
2526
isForcedDraft: boolean;
@@ -40,6 +41,10 @@ export const ClientToolbar = ({
4041
status: number;
4142
response: LatestBranch[] | { error: string };
4243
}>;
44+
humanRevalidatePendingTags: (o: {
45+
bshbPreviewToken: string;
46+
ref: string;
47+
}) => Promise<{ success: boolean }>;
4348
}) => {
4449
const [toolbarRef, setToolbarRef] = React.useState<HTMLDivElement | null>(
4550
null
@@ -162,6 +167,17 @@ export const ClientToolbar = ({
162167
window.dispatchEvent(new Event("__bshb_ref_changed"));
163168
}, []);
164169

170+
// human revalidate pending tags
171+
React.useEffect(() => {
172+
if (!bshbPreviewToken) return;
173+
if (!ref) return;
174+
if (isForcedDraft) return;
175+
176+
humanRevalidatePendingTags({ bshbPreviewToken, ref }).catch(() => {
177+
// ignore
178+
});
179+
}, [bshbPreviewToken, humanRevalidatePendingTags, ref, isForcedDraft]);
180+
165181
React.useLayoutEffect(() => {
166182
tooltipRef.current?.checkOverflow();
167183
}, [message]);

packages/basehub/src/next/toolbar/server-toolbar.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,46 @@ export const ServerToolbar = async ({
110110
return { success: true };
111111
};
112112

113+
// used by a client that's authenticated to the toolbar
114+
// sort of as a fallback to the headless browser's revalidation failing
115+
const humanRevalidatePendingTags = async ({
116+
bshbPreviewToken,
117+
ref,
118+
}: {
119+
bshbPreviewToken: string;
120+
ref: string;
121+
}) => {
122+
"use server";
123+
const { headers, url } = getStuffFromEnv(basehubProps);
124+
const appApiEndpoint = getBaseHubAppApiEndpoint(
125+
url,
126+
"/api/nextjs/pending-tags"
127+
);
128+
129+
const res = await fetch(appApiEndpoint, {
130+
cache: "no-store",
131+
method: "GET",
132+
headers: {
133+
"content-type": "application/json",
134+
"x-basehub-token": headers["x-basehub-token"],
135+
"x-basehub-preview-token": bshbPreviewToken,
136+
"x-basehub-ref": ref,
137+
},
138+
});
139+
140+
if (res.status !== 200) {
141+
return { success: false };
142+
}
143+
144+
const response = await res.json();
145+
const tags = response.tags;
146+
if (!tags || !Array.isArray(tags)) {
147+
return { success: false };
148+
}
149+
150+
return await revalidateTags({ tags });
151+
};
152+
113153
return (
114154
<LazyClientConditionalRenderer
115155
draft={(await draftMode()).isEnabled}
@@ -119,6 +159,7 @@ export const ServerToolbar = async ({
119159
revalidateTags={revalidateTags}
120160
getLatestBranches={getLatestBranches}
121161
resolvedRef={resolvedRef}
162+
humanRevalidatePendingTags={humanRevalidatePendingTags}
122163
/>
123164
);
124165
};

playground/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# playground
22

3+
## 0.0.168
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
9+
310
## 0.0.167
411

512
### Patch Changes

playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "playground",
33
"private": true,
4-
"version": "0.0.167",
4+
"version": "0.0.168",
55
"scripts": {
66
"dev": "basehub dev & next dev --port 3003",
77
"build": "basehub && next build",

0 commit comments

Comments
 (0)