Skip to content

Improve error logging and fix relative URL resolution in Overview docs loader#226

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/log-html-instead-of-markdown-error
Draft

Improve error logging and fix relative URL resolution in Overview docs loader#226
Copilot wants to merge 2 commits intomainfrom
copilot/log-html-instead-of-markdown-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 30, 2026

Silent failures and a subtle URL resolution bug in the Overview documentation drawer made debugging difficult and could cause relative markdown links to resolve incorrectly.

Changes

  • HTML-instead-of-markdown detection — log console.warn with the full doc path before throwing, so the fallback trigger is visible in devtools
  • Localized doc fallback — log console.warn (with error) when falling back to the default doc, surfacing the root cause that was previously swallowed
  • URL parsing failure — log console.warn with the offending href in the catch block instead of silently setting isGitHubLink = false
  • Relative URL base — change window.location.originwindow.location.href so relative links in markdown (e.g. ./other.md) resolve against the current page path, not just the origin
  • Unused node param — remove from the a component destructor
// Before: relative links always resolved from origin root
const parsedUrl = new URL(href, window.location.origin);

// After: relative links resolve from current page path
const parsedUrl = new URL(href, window.location.href);
Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"The error message 'Got HTML instead of markdown' is not user-facing and the actual error handling sets drawer content to a translated error. Consider logging this specific error message for debugging purposes or making it more descriptive for developers.","fixFiles":[{"filePath":"src/Pages/Overview.jsx","diff":"diff --git a/src/Pages/Overview.jsx b/src/Pages/Overview.jsx\n--- a/src/Pages/Overview.jsx\n+++ b/src/Pages/Overview.jsx\n@@ -41,12 +41,19 @@\n \t\t\t\tif (response.ok) {\n \t\t\t\t\tmarkdown = await response.text();\n \t\t\t\t\tif (/<!doctype\\s+html\\b|<html(?=[\\s>/])/i.test(markdown)) {\n+\t\t\t\t\t\tconsole.warn(\n+\t\t\t\t\t\t\t`Localized documentation returned HTML instead of markdown: /docs/${currentLanguage}/${fileName}`\n+\t\t\t\t\t\t);\n \t\t\t\t\t\tthrow new Error(\"Got HTML instead of markdown\");\n \t\t\t\t\t}\n \t\t\t\t} else {\n \t\t\t\t\tthrow new Error(\"Localized file not found\");\n \t\t\t\t}\n \t\t\t} catch (error) {\n+\t\t\t\tconsole.warn(\n+\t\t\t\t\t`Failed to load localized documentation (/docs/${currentLanguage}/${fileName}); falling back to default documentation.`,\n+\t\t\t\t\terror\n+\t\t\t\t);\n \t\t\t\tresponse = await fetch(`/docs/${fileName}`);\n \t\t\t\tif (!response.ok) {\n \t\t\t\t\tthrow new Error(\"Documentation file not found\");\n"}]},{"message":"The 'node' parameter is declared but never used in the component. Remove it to avoid confusion and keep the code clean.","fixFiles":[{"filePath":"src/Pages/Overview.jsx","diff":"diff --git a/src/Pages/Overview.jsx b/src/Pages/Overview.jsx\n--- a/src/Pages/Overview.jsx\n+++ b/src/Pages/Overview.jsx\n@@ -143,7 +143,7 @@\n \t\t\t\t\t) : (\n \t\t\t\t\t\t<ReactMarkdown\n \t\t\t\t\t\t\tcomponents={{\n-\t\t\t\t\t\t\t\ta: ({ node, href, children, ...props }) => {\n+\t\t\t\t\t\t\t\ta: ({ href, children, ...props }) => {\n \t\t\t\t\t\t\t\t\tlet isGitHubLink = false;\n \t\t\t\t\t\t\t\t\tconst getNodeText = (value) => {\n \t\t\t\t\t\t\t\t\t\tif (typeof value === \"string\" || typeof value === \"number\") {\n"}]},{"message":"Using window.location.origin as the base URL for parsing relative links may cause incorrect URL resolution for relative hrefs in markdown. If the markdown contains relative links like './file.md', they will resolve relative to the application's origin rather than the documentation path. Consider using the documentation file's location as the base URL instead.","fixFiles":[{"filePath":"src/Pages/Overview.jsx","diff":"diff --git a/src/Pages/Overview.jsx b/src/Pages/Overview.jsx\n--- a/src/Pages/Overview.jsx\n+++ b/src/Pages/Overview.jsx\n@@ -161,7 +161,7 @@\n \n \t\t\t\t\t\t\t\t\tif (href) {\n \t\t\t\t\t\t\t\t\t\ttry {\n-\t\t\t\t\t\t\t\t\t\t\tconst parsedUrl = new URL(href, window.location.origin);\n+\t\t\t\t\t\t\t\t\t\t\tconst parsedUrl = new URL(href, window.location.href);\n \t\t\t\t\t\t\t\t\t\t\tconst host = parsedUrl.hostname.toLowerCase();\n \t\t\t\t\t\t\t\t\t\t\tisGitHubLink = host === \"github.com\" || host.endsWith(\".github.com\");\n \t\t\t\t\t\t\t\t\t\t} catch (error) {\n"}]},{"message":"The catch block silently swallows URL parsing errors. Consider logging these errors for debugging purposes, especially since URL parsing failures might indicate malformed hrefs in the documentation.","fixFiles":[{"filePath":"src/Pages/Overview.jsx","diff":"diff --git a/src/Pages/Overview.jsx b/src/Pages/Overview.jsx\n--- a/src/Pages/Overview.jsx\n+++ b/src/Pages/Overview.jsx\n@@ -165,6 +165,7 @@\n \t\t\t\t\t\t\t\t\t\t\tconst host = parsedUrl.hostname.toLowerCase();\n \t\t\t\t\t\t\t\t\t\t\tisGitHubLink = host === \"github.com\" || host.endsWith(\".github.com\");\n \t\t\t\t\t\t\t\t\t\t} catch (error) {\n+\t\t\t\t\t\t\t\t\t\t\tconsole.warn(\"Failed to parse markdown link URL in Overview:\", href, error);\n \t\t\t\t\t\t\t\t\t\t\tisGitHubLink = false;\n \t\t\t\t\t\t\t\t\t\t}\n \t\t\t\t\t\t\t\t\t}\n"}]}]

Copilot AI changed the title [WIP] Log error for HTML received instead of markdown Improve error logging and fix relative URL resolution in Overview docs loader Apr 30, 2026
Copilot AI requested a review from PromiseFru April 30, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants