fix(graph): decode location.pathname before using it as the local-graph slug - #8
Closed
isle-blu wants to merge 1 commit into
Closed
fix(graph): decode location.pathname before using it as the local-graph slug#8isle-blu wants to merge 1 commit into
isle-blu wants to merge 1 commit into
Conversation
…ph slug
getSlugFromUrl() derived the slug from window.location.pathname without
decoding it. Browsers keep pathname percent-encoded for non-ASCII/reserved
characters, so any slug containing them (CJK, "{}", etc.) never matched the
already-decoded keys in the fetched content index or link list - causing the
local graph to show a garbled label for the current page and render it as an
isolated node with no edges.
Fixes quartz-community#2
Author
|
Closing in favor of #5, which fixes the same root cause. |
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.
Fixes #2
Root cause
getSlugFromUrl()derives the current page's slug fromwindow.location.pathnameviagetFullSlugFromUrl(), but never decodes it. Browsers keeppathnamepercent-encoded for non-ASCII/reserved characters, so for any slug containing them (CJK,{}, etc.) this local-graph-only seed slug never matches the already-decoded keys in the fetched content index / link list.Two visible symptoms follow from that single mismatch:
data.get(url)?.titlemisses for the current page's own node, so the label falls back to the raw, still-encodedurl— the garbled/mojibake-looking text reported in Local graph fails on pages with encoded characters in the URL #2.link.source/link.targetpairs ever match it — the node renders with no visible edges, even though it does have backlinks.The global graph is unaffected because its neighbourhood construction (
depth < 0) walks the already-normalized link keys directly instead of seeding from the current page's slug.Fix
Decode the pathname once, at the source, in
getSlugFromUrl(), guarded with try/catch so a malformed escape sequence (e.g. a literal%not part of a valid encoding) falls back to the raw value instead of throwing.Testing
npm run check(typecheck/lint/format/vitest) andnpm run buildpass locally;dist/in this PR matches a fresh build.{Foo}/{Foo}case from Local graph fails on pages with encoded characters in the URL #2Both now render the correct label and correct edges in the local graph.