Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Handle skipped segments #663

Merged
merged 2 commits into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions runtime/src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
14 changes: 14 additions & 0 deletions test/apps/basics/src/routes/skipped/[one]/[two].svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script context="module">
export function preload({ params }) {
return params;
}
</script>

<script>
export let one;
export let two;
</script>

<h1>{one}:{two}</h1>

<a href="skipped/y/1">skipped/y/1</a>
22 changes: 18 additions & 4 deletions test/apps/basics/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();
Expand All @@ -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: {
Expand All @@ -324,4 +324,18 @@ describe('basics', function() {

assert.ok(html.body.indexOf('<h1>HTML</h1>') !== -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'
);
});
});