Thank you for sharing this! It’s working without the warning message.
I am having another issue I mentioned here:
For that issue, I asked ChatGPT and it said (since I’m not a developer):
Show ChatGPT message
The issue likely stems from how you’re extracting the topicId
from the URL:
const topicId = url.split('/')[2];
If your URL contains more complex patterns (like titles with spaces, special characters, or non-standard slugs), this simple split won’t reliably get the correct topic ID.
Why this causes problems:
- URLs like
/t/3ple-2015-2019-title/12345
have the numeric topic ID at the end, but your code assumes the topic ID is always the 3rd segment. - If your URL structure varies, sometimes you’re grabbing a slug or part of the title instead of the ID.
- This breaks your AJAX request (
/t/${topicId}.json
) because you may be sending an invalid topic ID or slug, returning incorrect or default category info (like “General”).
How to fix:
Use a more reliable way to extract the topic ID from the URL:
- Extract topic ID from the last numeric segment of the URL.
Discourse topic URLs often look like /t/{slug}/{id}
, e.g.:
/t/3ple-2015-2019-title/12345
Here, 12345
is the topic ID.
Replace this:
const topicId = url.split('/')[2];
With this:
const segments = url.split('/').filter(Boolean);
const topicId = segments[segments.length - 1]; // last segment, expected to be numeric id
To be safer, validate that topicId
is a number:
if (!/^\d+$/.test(topicId)) {
console.error("Invalid topic ID extracted from URL:", topicId);
return; // stop execution
}
Summary: update your code snippet in updateBreadcrumbs
like this:
if (url.includes('/t/')) {
const segments = url.split('/').filter(Boolean);
const topicId = segments[segments.length - 1];
if (!/^\d+$/.test(topicId)) {
console.error("Invalid topic ID extracted from URL:", topicId);
return;
}
// Then continue your AJAX calls with topicId
}
This way you always get the numeric topic ID regardless of complex or spaced titles in the URL, fixing the breadcrumb category and path lookup.
Would you be able to fix that?
Thanks in advance