Skip to content

fix: preserve canonical metadata after Notion hydration - #195

Closed
Vamsi-2581 wants to merge 4 commits into
classmethod:masterfrom
Vamsi-2581:codex/fix-client-canonical-meta-193
Closed

Vamsi-2581 wants to merge 4 commits into
classmethod:masterfrom
Vamsi-2581:codex/fix-client-canonical-meta-193

Conversation

@Vamsi-2581

Copy link
Copy Markdown

Summary

The generated Notion client overwrites the canonical link and social URL metadata after the Worker sets them. This can leave canonical URLs pointing at a Notion-generated path and make og:url relative.

The generated client now derives the canonical URL from the current route using the Worknot rules for the home page, mapped slugs, unmapped page IDs, and custom 404 pages. It reapplies the canonical link, og:url, and twitter:url after head mutations and history navigation.

The regression test executes the generated client script with a lightweight DOM stub and covers Notion metadata rewrites plus mapped and unmapped client-side navigation.

Fixes #193

Validation

  • Added a focused regression test to test/generated-worker.test.mjs.
  • Local tests were not run. The pull request CI runs npm run build and npm test.

AI assistance

Prepared with OpenAI Codex assistance.

@shigahi

shigahi commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks for working on #193 and for the detailed test.

We can't merge this one, for two reasons:

  1. Notion client overwrites canonical URL and og:url in the browser #193 was already fixed by Keep the canonical URL and og:url after the Notion client loads #194, which was merged before this PR was reviewed. The client script now keeps link[rel=canonical], og:url and twitter:url on the worker's canonical URL.
  2. getCanonicalUrl() references MY_DOMAIN inside the client script, where it isn't defined; the worker only interpolates it as ${MY_DOMAIN}. The top-level applyMeta() call then throws ReferenceError: MY_DOMAIN is not defined, and the rest of the client script never runs. In wrangler dev with our render-check page, pretty URLs were lost (/subpage became /Render-Check-Subpage-<id>), and the error was thrown hundreds of times per page load. The new test in this PR fails with the same error (npm test: 25 passed, 1 failed).

Running the generated client script in node:vm with a small DOM stub is a nice idea, since the client script has no unit tests today. If you'd like to contribute that as a separate PR against the current master, testing the behavior from #194, we'd be happy to review it.

Closing this as superseded by #194.

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.

Notion client overwrites canonical URL and og:url in the browser

2 participants