Repository navigation
fix(studio): open pages on sites with trailingSlash: 'always' - #109
Open
rubenkalath wants to merge 1 commit into
Open
rubenkalath wants to merge 1 commit into
rubenkalath wants to merge 1 commit into
Conversation
Studio sent the canvas to slashless routes (/about), which Astro's dev server answers with a 404 when the site sets trailingSlash: 'always', so every page but the home page stayed on "editor script has not answered". The container now redirects a slashless page navigation to the spelling Astro serves, and the ready check treats /about/ and /about as one page.
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.
Problem
On an Astro site with
trailingSlash: 'always', Studio opens the home page, but every other page (plain pages, collection templates) stays on "Your preview is taking a little longer to start… The page loaded, but its editor script has not answered."Two causes:
routeFor→/about). BothsendPreviewURL(studio/src/server/integration.ts) and the hostedpreviewEntryredirect (studio/src/cloudflare/worker.ts) send the canvas there as is. Under'always', Astro's dev server answers/aboutwith its 404 page, which has no editor script./about/,usePreviewLoadingcompares the path the client reports (/about/) withpagePath(url)(/about) using===, so the canvas keeps waiting.Desktop doesn't have the problem: it reads
trailingSlashand applies it inrouteToPath. Studio's project scan has notrailingSlash.To reproduce: install Studio into any site with
trailingSlash: 'always', runnpm --prefix studio run dev, open/studio, and pick any page except Home.Fix
studio/src/server/pageNavigation.ts(new):slashRedirect()returns the spelling Astro serves (/about→/about/, query kept) for a page navigation that is missing the slash on an'always'site. It only applies toSec-Fetch-Mode: navigatewith GET or HEAD./feed.xml), Studio paths (/studio/…,/__avb/…,/__studio-entry), Vite/Astro paths (/@…,/_astro/…), fetches and writes.'never'needs nothing, because Studio routes never end in a slash.integration.ts: thestudioRequestsmiddleware answers that navigation with a 302. The container is the one place that knows the site's setting in both hosts (local dev, and the Worker proxying the frame), so neitherpreview-urlnorpreviewEntryhas to learn it. The fragment (#avb-design) survives the redirect.previewHandshake.ts:samePage(reported, asked)treats/about/and/aboutas one page (the query must still match).PreviewLoading.tsxuses it for the ready check.studio/test/pageNavigation.test.ts: covers each setting, files, tooling paths, fetches and writes, the assertion, andsamePage.An alternative is the Desktop approach: add
trailingSlashto Studio's scan and applyrouteToPathin the client before asking forpreview-url. It touches more files (the scan, template entry routes, the switcher's comparisons) and still needssamePage. Happy to switch if you prefer it.Checks
tsc --noEmit, ESLint and Prettier on the changed files.tsx --test test/pageNavigation.test.ts test/previewHandshake.test.ts: 16 pass.trailingSlash: 'always'): a page, a second page, a blog post template and a case study template open on the canvas and save edits.I did not run the full
npm testgate.