From d51e1a0af8d5f089bb703a28351a18ce7f89df6f Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 5 May 2019 10:49:38 -0400 Subject: [PATCH 1/2] failing test for skipped segments --- .../src/routes/skipped/[one]/[two].svelte | 14 ++++++++++++ test/apps/basics/test.ts | 22 +++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 test/apps/basics/src/routes/skipped/[one]/[two].svelte diff --git a/test/apps/basics/src/routes/skipped/[one]/[two].svelte b/test/apps/basics/src/routes/skipped/[one]/[two].svelte new file mode 100644 index 000000000..31b10d236 --- /dev/null +++ b/test/apps/basics/src/routes/skipped/[one]/[two].svelte @@ -0,0 +1,14 @@ + + + + +

{one}:{two}

+ +y/1 \ No newline at end of file diff --git a/test/apps/basics/test.ts b/test/apps/basics/test.ts index 45e02cd3f..53cced390 100644 --- a/test/apps/basics/test.ts +++ b/test/apps/basics/test.ts @@ -282,7 +282,7 @@ describe('basics', function() { assert.equal(await title(), 'bar'); }); - it('navigates to ...rest', async () => { + it('navigates to ...rest', async () => { await page.goto(`${base}/abc/xyz`); await start(); @@ -298,8 +298,8 @@ describe('basics', function() { await page.evaluate(() => document.body.textContent), 'xyz,abc,qwe' ); - }); - + }); + it('navigates between dynamic routes with same segments', async () => { await page.goto(`${base}/dirs/bar/xyz`); await start(); @@ -310,7 +310,7 @@ describe('basics', function() { await wait(50); assert.equal(await title(), 'B page'); }); - + it('runs server route handlers before page handlers, if they match', async () => { const json = await get(`${base}/middleware`, { headers: { @@ -324,4 +324,18 @@ describe('basics', function() { assert.ok(html.body.indexOf('

HTML

') !== -1); }); + + it('invalidates page when a segment is skipped', async () => { + await page.goto(`${base}/skipped/x/1`); + await start(); + await prefetchRoutes(); + + await page.click('a[href="skipped/y/1"]'); + await wait(50); + + assert.equal( + await title(), + 'y:1' + ); + }); }); From c0ada5c52f7ec65a57184e0ca2e5004642d7239e Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 5 May 2019 11:36:02 -0400 Subject: [PATCH 2/2] handle skipped segments --- runtime/src/app/app.ts | 14 +++++++++++--- .../basics/src/routes/skipped/[one]/[two].svelte | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/runtime/src/app/app.ts b/runtime/src/app/app.ts index 597ac9c7f..3056b3107 100644 --- a/runtime/src/app/app.ts +++ b/runtime/src/app/app.ts @@ -288,14 +288,22 @@ export async function hydrate_target(target: Target): Promise<{ let l = 1; try { + let segment_dirty = false; branch = await Promise.all(route.parts.map(async (part, i) => { + const segment = segments[i]; + + if (current_branch[i] && current_branch[i].segment !== segment) segment_dirty = true; + props.segments[l] = segments[i + 1]; // TODO make this less confusing - if (!part) return null; + if (!part) return { segment }; const j = l++; - const segment = segments[i]; - if (!session_dirty && current_branch[i] && current_branch[i].segment === segment && current_branch[i].part === part.i) return current_branch[i]; + if (!session_dirty && !segment_dirty && current_branch[i] && current_branch[i].part === part.i) { + return current_branch[i]; + } + + segment_dirty = false; const { default: component, preload } = await load_component(components[part.i]); diff --git a/test/apps/basics/src/routes/skipped/[one]/[two].svelte b/test/apps/basics/src/routes/skipped/[one]/[two].svelte index 31b10d236..14103592a 100644 --- a/test/apps/basics/src/routes/skipped/[one]/[two].svelte +++ b/test/apps/basics/src/routes/skipped/[one]/[two].svelte @@ -11,4 +11,4 @@

{one}:{two}

-y/1 \ No newline at end of file +skipped/y/1 \ No newline at end of file