Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/good-mice-show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"basehub": patch
---

more logs
14 changes: 14 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"mode": "pre",
"tag": "debug-logs",
"initialVersions": {
"eslint-config-custom": "1.0.0",
"tsconfig": "1.0.0",
"basehub": "9.5.0",
"playground": "0.0.258"
},
"changesets": [
"good-mice-show",
"six-buttons-show"
]
}
5 changes: 5 additions & 0 deletions .changeset/six-buttons-show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"basehub": patch
---

add some debug logs
12 changes: 12 additions & 0 deletions packages/basehub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# basehub

## 9.5.1-debug-logs.1

### Patch Changes

- more logs

## 9.5.1-debug-logs.0

### Patch Changes

- add some debug logs

## 9.5.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/basehub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "basehub",
"description": "A very fast Headless CMS.",
"author": "JB <jb@basehub.com>",
"version": "9.5.0",
"version": "9.5.1-debug-logs.1",
"license": "MIT",
"repository": "basehub-ai/basehub",
"bugs": "https://github.com/basehub-ai/basehub/issues",
Expand Down
61 changes: 58 additions & 3 deletions packages/basehub/src/bin/util/get-stuff-from-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { hashObject } from "./hash.js";
import { isV0OrBolt } from "../../vibe.js";
import { getGlobalConfig } from "../../index.js";
import { version } from "../../version.js";
import { debugLog, getDebugCallStack } from "../../debug-utils.js";

export const basehubAPIOrigin = "https://api.basehub.com";
const defaultEnvVarPrefix = "BASEHUB";
Expand Down Expand Up @@ -43,6 +44,8 @@ export type Options = {
};

export const getStuffFromEnv = async (options?: Options) => {
debugLog("[BaseHub Debug] getStuffFromEnv called from:", getDebugCallStack());

if (!options) {
options = {};
}
Expand Down Expand Up @@ -262,10 +265,35 @@ export const getStuffFromEnv = async (options?: Options) => {
if (!isV0OrBolt() && !draft) {
// try to auto-detect (only if draft is not explicitly set by the user)
try {
debugLog(
"[BaseHub Debug] Attempting to import draftMode from next/headers in get-stuff-from-env.ts"
);
debugLog(
"[BaseHub Debug] Current execution context - isV0OrBolt():",
isV0OrBolt(),
"draft:",
draft
);
// @ts-ignore
const { draftMode } = await import(/* @vite-ignore */ "next/headers");
isNextjsDraftMode = (await draftMode()).isEnabled;
debugLog(
"[BaseHub Debug] Successfully imported draftMode, calling draftMode()"
);
const draftModeInstance = await draftMode();
debugLog("[BaseHub Debug] Got draftMode instance, checking isEnabled");
isNextjsDraftMode = draftModeInstance.isEnabled;
debugLog("[BaseHub Debug] draftMode().isEnabled =", isNextjsDraftMode);
} catch (error) {
debugLog(
"[BaseHub Debug] Error accessing draftMode in get-stuff-from-env.ts:",
error
);
debugLog(
"[BaseHub Debug] Error name:",
(error as any)?.name,
"Error message:",
(error as any)?.message
);
// noop, not using nextjs
}
}
Expand All @@ -278,15 +306,42 @@ export const getStuffFromEnv = async (options?: Options) => {
if (draft && !isV0OrBolt()) {
// try to get ref from cookies
try {
debugLog(
"[BaseHub Debug] Attempting to import cookies from next/headers in get-stuff-from-env.ts"
);
debugLog(
"[BaseHub Debug] Current execution context - draft:",
draft,
"isV0OrBolt():",
isV0OrBolt()
);
// @ts-ignore
const { cookies } = await import(/* @vite-ignore */ "next/headers");
debugLog(
"[BaseHub Debug] Successfully imported cookies, calling cookies()"
);
const cookieStore = await cookies();
const ref = cookieStore.get("bshb-preview-ref-" + resolvedRef.repoHash)
?.value as string | undefined;
debugLog("[BaseHub Debug] Successfully got cookie store");
const cookieName = "bshb-preview-ref-" + resolvedRef.repoHash;
debugLog("[BaseHub Debug] Looking for cookie:", cookieName);
const ref = cookieStore.get(cookieName)?.value as string | undefined;
if (ref) {
previewRef = ref;
debugLog("[BaseHub Debug] Found preview ref in cookies:", ref);
} else {
debugLog("[BaseHub Debug] No preview ref found in cookies");
}
} catch (error) {
debugLog(
"[BaseHub Debug] Error accessing cookies in get-stuff-from-env.ts:",
error
);
debugLog(
"[BaseHub Debug] Error name:",
(error as any)?.name,
"Error message:",
(error as any)?.message
);
// noop
}
}
Expand Down
19 changes: 19 additions & 0 deletions packages/basehub/src/debug-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const debugLog = (...args: any[]) => {
// Always log in this debug version
console.log(...args);
};

export const getDebugCallStack = () => {
try {
const stack = new Error().stack;
return (
stack
?.split("\n")
.slice(2, 6)
.map((line) => line.trim())
.join(" -> ") || "Unknown"
);
} catch {
return "Unknown";
}
};
58 changes: 52 additions & 6 deletions packages/basehub/src/next/toolbar/server-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as React from "react";
import { basehub } from "../../index.js";
import { getStuffFromEnv } from "../../bin/util/get-stuff-from-env.js";
import { isV0OrBolt } from "../../vibe.js";
import { debugLog } from "../../debug-utils.js";

// we use react.lazy to code split client-toolbar
const LazyClientConditionalRenderer = React.lazy(() =>
Expand All @@ -22,10 +23,24 @@ export const ServerToolbar = async ({
let isDraftMode = false;
if (!isV0OrBolt()) {
try {
debugLog(
"[BaseHub Debug] Attempting to import draftMode from next/headers in server-toolbar.tsx (initial check)"
);
// @ts-ignore
const { draftMode } = await import(/* @vite-ignore */ "next/headers");
debugLog(
"[BaseHub Debug] Successfully imported draftMode, calling draftMode() in server-toolbar.tsx"
);
isDraftMode = (await draftMode()).isEnabled;
debugLog(
"[BaseHub Debug] draftMode().isEnabled in server-toolbar.tsx =",
isDraftMode
);
} catch (err) {
debugLog(
"[BaseHub Debug] Error accessing draftMode in server-toolbar.tsx (initial check):",
err
);
// noop
}
}
Expand All @@ -36,6 +51,9 @@ export const ServerToolbar = async ({
) => {
"use server";
try {
debugLog(
"[BaseHub Debug] Attempting to import draftMode from next/headers in enableDraftMode_unbound"
);
// @ts-ignore
const { draftMode } = await import(/* @vite-ignore */ "next/headers");
const { headers, url } = await getStuffFromEnv(basehubProps);
Expand All @@ -60,7 +78,12 @@ export const ServerToolbar = async ({
return { status: 400, response: { error: "Bad request" } };
}
const response = await res.json();
if (res.status === 200) (await draftMode())?.enable();
if (res.status === 200) {
debugLog(
"[BaseHub Debug] Enabling draft mode in enableDraftMode_unbound"
);
(await draftMode())?.enable();
}
return { status: res.status, response };
} catch (error) {
return { status: 500, response: { error: "Something went wrong" } };
Expand All @@ -76,13 +99,20 @@ export const ServerToolbar = async ({
const { headers, url, isForcedDraft } =
await getStuffFromEnv(basehubProps);

debugLog(
"[BaseHub Debug] Attempting to import draftMode from next/headers in getLatestBranches_unbound"
);
// @ts-ignore
const { draftMode } = await import(/* @vite-ignore */ "next/headers");
if (
((await draftMode())?.isEnabled ?? false) === false &&
!isForcedDraft &&
!bshbPreviewToken
) {
debugLog(
"[BaseHub Debug] Checking draft mode status in getLatestBranches_unbound"
);
const draftModeEnabled = (await draftMode())?.isEnabled ?? false;
debugLog(
"[BaseHub Debug] Draft mode enabled in getLatestBranches_unbound:",
draftModeEnabled
);
if (draftModeEnabled === false && !isForcedDraft && !bshbPreviewToken) {
return { status: 403, response: { error: "Unauthorized" } };
}
const appApiEndpoint = getBaseHubAppApiEndpoint(
Expand Down Expand Up @@ -119,10 +149,15 @@ export const ServerToolbar = async ({
const disableDraftMode = async () => {
"use server";
try {
debugLog(
"[BaseHub Debug] Attempting to import draftMode from next/headers in disableDraftMode"
);
// @ts-ignore
const { draftMode } = await import(/* @vite-ignore */ "next/headers");
debugLog("[BaseHub Debug] Disabling draft mode");
(await draftMode()).disable();
} catch (err) {
debugLog("[BaseHub Debug] Error disabling draft mode:", err);
// noop
}
};
Expand Down Expand Up @@ -193,16 +228,27 @@ export const ServerToolbar = async ({
return { success: true, message: "No tags to revalidate" };
}

debugLog(
"[BaseHub Debug] Attempting to import revalidateTag from next/cache"
);
// @ts-ignore
const { revalidateTag } = await import(/* @vite-ignore */ "next/cache");
debugLog(
"[BaseHub Debug] Successfully imported revalidateTag, revalidating",
tags.length,
"tags"
);

await Promise.all(
tags.map(async (_tag: string) => {
const tag = _tag.startsWith("basehub-") ? _tag : `basehub-${_tag}`;
debugLog("[BaseHub Debug] Calling revalidateTag for tag:", tag);
await revalidateTag(tag);
})
);

debugLog("[BaseHub Debug] Successfully revalidated all tags");

return { success: true, message: `Revalidated ${tags.length} tags` };
} catch (error) {
console.error(error);
Expand Down
15 changes: 15 additions & 0 deletions packages/basehub/src/react/pump/server-pump.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { replaceSystemAliases } from "../../genql/runtime/_aliasing.js";
import { isV0OrBolt } from "../../vibe.js";
import { GraphQLExact, StripAllArgs } from "../../type-helpers.js";
import { GenqlError } from "../../genql/runtime/_error.js";
import { debugLog } from "../../debug-utils.js";

export interface PumpQuery extends QueryGenqlSelection {}

Expand Down Expand Up @@ -84,10 +85,24 @@ export const Pump = async <
if (!isV0OrBolt() && basehubProps.draft === undefined) {
// try to auto-detect (only if draft is not explicitly set by the user)
try {
debugLog(
"[BaseHub Debug] Attempting to import draftMode from next/headers in server-pump.tsx"
);
// @ts-ignore
const { draftMode } = await import(/* @vite-ignore */ "next/headers");
debugLog(
"[BaseHub Debug] Successfully imported draftMode, calling draftMode() in server-pump.tsx"
);
isNextjsDraftMode = (await draftMode()).isEnabled;
debugLog(
"[BaseHub Debug] draftMode().isEnabled in server-pump.tsx =",
isNextjsDraftMode
);
} catch (error) {
debugLog(
"[BaseHub Debug] Error accessing draftMode in server-pump.tsx:",
error
);
// noop, not using nextjs
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/basehub/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = "9.3.9-canary.1";
export const version = "9.5.1-debug-logs.1";
14 changes: 14 additions & 0 deletions playground/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# playground

## 0.0.259-debug-logs.1

### Patch Changes

- Updated dependencies
- basehub@9.5.1-debug-logs.1

## 0.0.259-debug-logs.0

### Patch Changes

- Updated dependencies
- basehub@9.5.1-debug-logs.0

## 0.0.258

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "playground",
"private": true,
"version": "0.0.258",
"version": "0.0.259-debug-logs.1",
"scripts": {
"dev": "next dev --port 3003",
"build": "next build",
Expand Down
Loading