Skip to content

Commit d0cc2bc

Browse files
milanmajchrakclaude
andcommitted
JCU/fix(ssr): serve a reloaded comcol search tab from the page it belongs to
Opening a community or collection moves the address bar to its /search tab, and #1424 put that path in ssr.excludePathPatterns. Reloading there returned the 1113-byte CSR shell, so the visitor got a white page for 0.6s on a fast desktop and up to 3.4s on a slow one. Both URLs render ComcolSearchSectionComponent and the comcol page itself is server-rendered, so a GET for the bare tab URL is redirected to it; the client puts /search back in the address bar as it did before. A URL carrying a query is left alone, which is the point of the exclusion: what saturated SSR on mendelu (#1402) is the Discovery facet parameter space, and those URLs all carry f. parameters. The redirect turns itself off if the tab stops being excluded, or if the comcol page ever becomes excluded. Doing this in ComcolPageBrowseByComponent instead, by not redirecting to the default tab, looks tidier and does not work: getSearchLink() returns currentPath(router) for an in-place search, so every facet link would move to /collections/<uuid>?f. , which no pattern matches, and the trap reopens. Also fixes the robots.txt comment claiming the SSR-side rule is not configured, wrong since #1424. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 28388bb commit d0cc2bc

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

server.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,43 @@ export function app() {
221221
return server;
222222
}
223223

224+
/**
225+
* A community or collection moves the address bar to its /search tab as soon as the client boots,
226+
* and that path is in ssr.excludePathPatterns, so a reload there returns the empty CSR shell. Both
227+
* URLs render the same ComcolSearchSectionComponent, so a bare reload is sent back to the page
228+
* itself, which is server-rendered; the client puts /search back in the address bar.
229+
*
230+
* Only for a URL with no query: /search?f.author=... keeps its query and stays excluded, which is
231+
* what the exclusion is there for.
232+
*
233+
* @param req current request
234+
* @returns the path to redirect to, or null to handle the request normally
235+
*/
236+
function comcolSearchTabRedirect(req): string {
237+
if (!environment.ssr.enabled || req.method !== 'GET' || req.originalUrl.includes('?')) {
238+
return null;
239+
}
240+
const match = /^(\/(?:collections|communities)\/[0-9a-f-]{36})\/search\/?$/i.exec(req.path);
241+
if (match === null) {
242+
return null;
243+
}
244+
const patterns = environment.ssr.excludePathPatterns;
245+
// Nothing to gain when the tab is server-rendered anyway, or when the page itself is not.
246+
if (!isExcludedFromSsr(req.path, patterns) || isExcludedFromSsr(match[1], patterns)) {
247+
return null;
248+
}
249+
return req.baseUrl + match[1];
250+
}
251+
224252
/*
225253
* The callback function to serve server side angular
226254
*/
227255
function ngApp(req, res, next) {
256+
const comcolPath = comcolSearchTabRedirect(req);
257+
if (comcolPath !== null) {
258+
res.redirect(302, comcolPath);
259+
return;
260+
}
228261
if (environment.ssr.enabled && req.method === 'GET' && (req.path === '/' || !isExcludedFromSsr(req.path, environment.ssr.excludePathPatterns))) {
229262
// Render the page to user via SSR (server side rendering)
230263
serverSideRender(req, res, next);

src/robots.txt.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Disallow: /communities/*/search
3131
Disallow: /*?f.
3232
Disallow: /*&f.
3333
# NOTE: robots.txt is advisory only; it does not stop crawlers that ignore it.
34-
# The SSR-side enforcement (ssr.excludePathPatterns) is not configured here.
34+
# ssr.excludePathPatterns in config.yml enforces the facet part server-side, for any user agent.
3535

3636
# Heavy Discovery facet queries on browse pages
3737
Disallow: /collections/*?f

0 commit comments

Comments
 (0)