Skip to content

Commit 29c4de3

Browse files
committed
fix: move the cache invalidation to custom.js
1 parent 42b7d9a commit 29c4de3

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

apify-docs-theme/src/theme/Layout/index.jsx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,13 @@ import { useLocation } from '@docusaurus/router';
44
import Layout from '@docusaurus/theme-classic/lib/theme/Layout/index';
55
import useBaseUrl from '@docusaurus/useBaseUrl';
66
import { usePluginData } from '@docusaurus/useGlobalData';
7-
import React, { useEffect } from 'react';
7+
import React from 'react';
88

99
export default function LayoutWrapper(props) {
1010
const { options: { subNavbar } } = usePluginData('@apify/docs-theme');
1111
const baseUrl = useBaseUrl('/');
1212
const currentPath = useLocation().pathname.replace(new RegExp(`^${baseUrl}`), '');
1313

14-
// Silent cache busting for mcp.apify.com redirects
15-
useEffect(() => {
16-
// Only run on the MCP documentation page
17-
if (currentPath.includes('integrations/mcp')) {
18-
// Always clear cache when on MCP page to help with redirect issues.
19-
// Background: Previously, mcp.apify.com had a 301 redirect to this docs page, which was wrong.
20-
// Many users have this redirect cached in their browsers, so they can't access the new MCP UI.
21-
// This helps with their cached redirect, allowing them to access mcp.apify.com
22-
fetch('https://mcp.apify.com/', { method: 'get', cache: 'reload' }).then(() => {
23-
console.log('MCP cache cleared successfully');
24-
}).catch((error) => {
25-
console.warn('Failed to clear MCP cache:', error);
26-
});
27-
}
28-
}, [currentPath]);
29-
3014
return (
3115
<>
3216
<Head>

apify-docs-theme/static/js/custom.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,30 @@ window.addEventListener('load', () => {
125125

126126
// docusaurus-openapi-docs plugin: scroll sidebar into viewport, no need for a large timeout here
127127
setTimeout(() => scrollOpenApiSidebarItemIntoView(), 200);
128+
129+
// MCP cache clearing - run after page is fully loaded
130+
setTimeout(() => clearMcpRedirectCache(), 200);
128131
});
129132

130133
window.addEventListener('popstate', () => {
131134
setTimeout(() => redirectOpenApiDocs(), 50);
132135
setTimeout(() => scrollOpenApiSidebarItemIntoView(), 50);
133136
});
137+
138+
// MCP redirect cache-busting
139+
// Background: Previously, mcp.apify.com had a 301 redirect to the docs page
140+
// This clears cached redirects so users can access the new MCP configuration interface
141+
function clearMcpRedirectCache() {
142+
// Only run on the MCP documentation page
143+
if (window.location.pathname.includes('integrations/mcp')) {
144+
// Clear cached redirects to mcp.apify.com
145+
fetch('https://mcp.apify.com/', {
146+
method: 'get',
147+
cache: 'reload',
148+
}).then(() => {
149+
// Cache cleared successfully
150+
}).catch(() => {
151+
// Failed to clear cache - silent fail
152+
});
153+
}
154+
}

0 commit comments

Comments
 (0)