Skip to content

fix redirect with google canonical#1797

Merged
tgberkeley merged 3 commits intomainfrom
fix-canonical-redirect
Mar 31, 2026
Merged

fix redirect with google canonical#1797
tgberkeley merged 3 commits intomainfrom
fix-canonical-redirect

Conversation

@tgberkeley
Copy link
Copy Markdown
Collaborator

No description provided.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 30, 2026

Greptile Summary

This PR adds a <link rel="canonical"> tag to blog post pages to help Google identify the canonical URL and resolve redirect/duplicate content issues. However, the tag is injected into the page body (inside rx.el.section) rather than the HTML <head>, which is where canonical tags must reside to be valid and reliably processed by search engines.

  • Canonical tag placement is incorrect: rx.el.link(rel="canonical", href=page_url) at line 219 is a child of rx.el.section, rendering as a <link> element in the document body. The HTML spec and Google's crawler require canonical hints to be in <head> — body placements are not guaranteed to be recognized and may be silently ignored.
  • Intent vs. implementation mismatch: The fix targets a real SEO problem (Google treating redirected/duplicate blog URLs as separate pages), but the chosen placement is unlikely to achieve the goal without being moved to the <head> via app.add_page(head_components=...) or an equivalent per-page head injection mechanism.

Confidence Score: 3/5

  • Safe to merge from a runtime stability perspective, but the canonical tag placement in the body means the SEO fix will likely have no effect.
  • The change introduces no crashes or data issues, but the primary goal of the PR — fixing Google canonical for blog pages — will not be achieved because the <link rel="canonical"> tag is placed in the page body rather than <head>. Since the fix won't work as intended, the P1 finding warrants a reduced score.
  • pcweb/pages/blog/page.py — canonical tag needs to be moved to the HTML <head> via a head_components injection mechanism

Important Files Changed

Filename Overview
pcweb/pages/blog/page.py Adds rx.el.link(rel="canonical", href=page_url) to the blog page template, but places it inside rx.el.section (body), not in the HTML <head> where canonical tags are required to function.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Blog page() called"] --> B["Compute page_url\nREFLEX_URL + route"]
    B --> C["rx.el.link canonical\n⚠️ placed in body section"]
    B --> D["blog_jsonld script\nin body - valid for JSON-LD"]
    C --> E["Rendered HTML\n&lt;section&gt;\n  &lt;link rel=canonical&gt; ❌\n  ...body content...\n&lt;/section&gt;"]
    D --> E
    F["Expected HTML\n&lt;head&gt;\n  &lt;link rel=canonical&gt; ✅\n&lt;/head&gt;"] -. "should be" .-> E
    E --> G["Google crawler\nmay ignore body canonical"]
Loading

Reviews (1): Last reviewed commit: "Merge branch 'main' into fix-canonical-r..." | Re-trigger Greptile

)

return rx.el.section(
rx.el.link(rel="canonical", href=page_url),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Canonical tag placed in <body>, not <head>

<link rel="canonical"> must be in the HTML <head> to be reliably recognized by search engines. Placing it inside rx.el.section renders it as a child of a <section> body element, which is not valid HTML and may be ignored by Google's canonical URL parser.

The PR's stated goal is to fix redirect handling via Google canonical — but this placement makes it unlikely to take effect. According to Google's documentation, canonical tags should appear in the <head> of the page.

The correct approach would be to inject the canonical URL into the <head> via Reflex's app.add_page() head_components parameter (or equivalent), rather than embedding it in the body component tree. For example, at the point where blog routes are registered in pcweb/pcweb.py, a head_components=[rx.el.link(rel="canonical", href=page_url)] argument could be passed.

@tgberkeley tgberkeley merged commit d538949 into main Mar 31, 2026
7 of 10 checks passed
@tgberkeley tgberkeley deleted the fix-canonical-redirect branch March 31, 2026 01:20
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