Skip to content

Increase logging around caching behaviour causing page crashes. #3182

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

Merged
merged 1 commit into from
Apr 23, 2025
Merged
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
6 changes: 6 additions & 0 deletions .changeset/sweet-schools-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"gitbook-v2": patch
"gitbook": patch
---

Increase logging around caching behaviour causing page crashes.
20 changes: 19 additions & 1 deletion packages/gitbook-v2/src/lib/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ export async function fetchSiteContextByIds(
): Promise<GitBookSiteContext> {
const { dataFetcher } = baseContext;

const DEBUG = ids.site === 'site_cu2ih';

const [{ site: orgSite, structure: siteStructure, customizations, scripts }, spaceContext] =
await Promise.all([
throwIfDataError(
Expand All @@ -232,6 +234,22 @@ export async function fetchSiteContextByIds(
fetchSpaceContextByIds(baseContext, ids),
]);

DEBUG && console.log('ids', JSON.stringify(ids));
DEBUG &&
console.log(
'siteStructure',
siteStructure
? JSON.stringify({
type: siteStructure.type,
structure: siteStructure.structure.map((s) => {
// @ts-ignore
const { siteSpaces, urls, ...rest } = s;
return rest;
}),
})
: 'null'
);

// override the title with the customization title
// TODO: remove this hack once we have a proper way to handle site customizations
const site = {
Expand Down Expand Up @@ -407,7 +425,7 @@ export function checkIsRootSiteContext(context: GitBookSiteContext): boolean {
function parseSiteSectionsAndGroups(structure: SiteStructure, siteSectionId: string) {
const sectionsAndGroups = getSiteStructureSections(structure, { ignoreGroups: false });
const section = parseCurrentSection(structure, siteSectionId);
assert(section, 'A section must be defined when there are multiple sections');
assert(section, `couldn't find section "${siteSectionId}" in site structure`);
return { list: sectionsAndGroups, current: section } satisfies SiteSections;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/gitbook/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,9 @@ async function lookupSiteByAPI(
}
);

alternative.url.includes('minas-tirith') &&
console.log(`resolved ${alternative.url} -> ${JSON.stringify(data)}`);

if ('error' in data) {
if (alternative.primary) {
// We only return an error for the primary alternative (full URL),
Expand Down
Loading