Fix slug rewriting for *.notion.site users#68
Merged
Conversation
Two issues prevented slugs from working on *.notion.site: 1. Server-side: slug matching triggered a 302 redirect to /<pageId>, which allowed Notion's client-side app to overwrite the URL with username-prefixed paths (e.g., /philipb/Page-Title-<id>). Now the Worker fetches the Notion page directly and serves it at the slug URL without a redirect. 2. Client-side: the MutationObserver that triggers updateSlug() only fires when .notion-topbar appears, but published *.notion.site pages may not have this element. Added a 2-second fallback timer to ensure slug rewriting and popstate handling are initialized. Closes #55 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/a-propos) triggered a 302 redirect to/<pageId>, which allowed Notion's client-side app to overwrite the URL with username-prefixed paths (e.g.,/philipb/Page-Title-<id>). Now the Worker internally rewrites the path and serves the page directly, keeping the browser URL at the clean slug.MutationObserveronly triggers when.notion-topbarappears, but published*.notion.sitepages may not have this element. The fallback ensuresupdateSlug()and theonpopstatehandler are initialized even without the topbar.Closes #55
Context
Reported by @Ph15 in #55 (comment). After the XHR domain fix (#62), the site loaded but slugs stopped working - URLs showed the full Notion path (e.g.,
vivrerelies.org/philipb/Vivre-reli-s-fe4785129e764baf85f54bb86cad7d1e) instead of clean slugs (e.g.,vivrerelies.org/).Test plan
*.notion.siteusers (URL stays at slug, not page ID)www.notion.sousers (backward compatibility)npm run build)