Skip to content
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
6 changes: 3 additions & 3 deletions shared/generateKey.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function generateKey(depth) {
if(depth.length === 1) return 'application';
return 'n-' + depth.join('-');
export default function generateKey(node, depth) {
if (depth.length === 1) return 'application';
return node.type.name + '/' + depth.join('-');
}
2 changes: 1 addition & 1 deletion shared/generateTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function generateBranch(parent, node, depth, scope) {
}

if (isClass(node)) {
const key = node.attributes.key ? node.attributes.key : generateKey(depth) + (node.attributes.route ? scope.context.router.url : '')
const key = node.attributes.key ? node.attributes.key : generateKey(node, depth) + (node.attributes.route ? scope.context.router.url : '')
if (
scope.context.environment.client &&
scope.context.router._changed &&
Expand Down
4 changes: 2 additions & 2 deletions tests/src/InstanceSelf.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe('InstanceSelf', () => {
});

test('self key has route appended to depth if no key is declared', async () => {
await page.waitForSelector('[data-key="n-0-0-6/instance-self"]');
const element = await page.$('[data-key="n-0-0-6/instance-self"]');
await page.waitForSelector('[data-key="InstanceSelf/0-0-6/instance-self"]');
const element = await page.$('[data-key="InstanceSelf/0-0-6/instance-self"]');
expect(element).toBeTruthy();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/src/PersistentComponent.njs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PersistentComponent extends Nullstack {
}

render({ self, instances }) {
const aCount = instances['n-0-0-33/persistent-component/a']?.count
const aCount = instances['PersistentComponent/0-0-33/persistent-component/a']?.count
return (
<div data-count={this.count} data-key={self.key} data-a-count={aCount}>
<a href="/persistent-component/a"> a </a>
Expand Down
10 changes: 5 additions & 5 deletions tests/src/PersistentComponent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe('PersistentComponent instantiated', () => {
});

test('components should create a new instance when matching a dynamic segment', async () => {
await page.waitForSelector('[data-key="n-0-0-33/persistent-component/a"]');
const element = await page.$('[data-key="n-0-0-33/persistent-component/a"]');
await page.waitForSelector('[data-key="PersistentComponent/0-0-33/persistent-component/a"]');
const element = await page.$('[data-key="PersistentComponent/0-0-33/persistent-component/a"]');
expect(element).toBeTruthy();
});

Expand All @@ -33,7 +33,7 @@ describe('PersistentComponent terminated', () => {
await page.goto('http://localhost:6969/persistent-component/a');
await page.waitForSelector('[href="/persistent-component/b"]');
await page.click('[href="/persistent-component/b"]');
await page.waitForSelector('[data-key="n-0-0-33/persistent-component/b"]');
await page.waitForSelector('[data-key="PersistentComponent/0-0-33/persistent-component/b"]');
});

test('components should call terminate when leaving the dom', async () => {
Expand All @@ -59,9 +59,9 @@ describe('PersistentComponent reinstantiated', () => {
await page.goto('http://localhost:6969/persistent-component/a');
await page.waitForSelector('[href="/persistent-component/b"]');
await page.click('[href="/persistent-component/b"]');
await page.waitForSelector('[data-key="n-0-0-33/persistent-component/b"]');
await page.waitForSelector('[data-key="PersistentComponent/0-0-33/persistent-component/b"]');
await page.click('[href="/persistent-component/a"]');
await page.waitForSelector('[data-key="n-0-0-33/persistent-component/a"]');
await page.waitForSelector('[data-key="PersistentComponent/0-0-33/persistent-component/a"]');
});

test('components should not be prepared a second time', async () => {
Expand Down