Skip to content

Commit d162b70

Browse files
Windvisjohanrd
authored andcommitted
[failing test] @model should be stable when transitioning out of route
When transitioning between routes, the @model argument on a Glimmer component becomes unstable during willDestroy - the model value changes before the component is properly destroyed. Requires @glimmer/component Vite alias to resolve in tests. Based on PR emberjs#20959 by @Windvis.
1 parent 96427a6 commit d162b70

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

packages/@ember/-internals/glimmer/tests/integration/application/rendering-test.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { service } from '@ember/service';
66
import { Component } from '@ember/-internals/glimmer';
77
import { tracked } from '@ember/-internals/metal';
88
import { set } from '@ember/object';
9+
import GlimmerComponent from '@glimmer/component';
910
import { backtrackingMessageFor } from '../../utils/debug-stack';
1011
import { runTask } from '../../../../../../internal-test-helpers/lib/run';
1112
import { template } from '@ember/template-compiler';
@@ -398,6 +399,98 @@ moduleFor(
398399
});
399400
}
400401

402+
async ['@test @model should be stable when transitioning out of the route']() {
403+
let assert = this.assert;
404+
405+
this.router.map(function () {
406+
this.route('a', function () {
407+
this.route('b');
408+
this.route('c');
409+
});
410+
this.route('d', function () {
411+
this.route('e');
412+
});
413+
this.route('f');
414+
});
415+
416+
this.addComponent('foo', {
417+
ComponentClass: class extends GlimmerComponent {
418+
willDestroy() {
419+
assert.step(this.args.model);
420+
}
421+
},
422+
});
423+
this.add(
424+
'route:a',
425+
class extends Route {
426+
model() {
427+
return 'a';
428+
}
429+
}
430+
);
431+
this.add(
432+
'route:a.b',
433+
class extends Route {
434+
model() {
435+
return 'b';
436+
}
437+
}
438+
);
439+
this.addTemplate('a.b', '<Foo @model={{@model}} @controller={{this}} />');
440+
this.add(
441+
'route:a.c',
442+
class extends Route {
443+
model() {
444+
return 'c';
445+
}
446+
}
447+
);
448+
this.add(
449+
'route:d',
450+
class extends Route {
451+
model() {
452+
return 'd';
453+
}
454+
}
455+
);
456+
this.add(
457+
'route:d.e',
458+
class extends Route {
459+
model() {
460+
return 'e';
461+
}
462+
}
463+
);
464+
this.add(
465+
'route:f',
466+
class extends Route {
467+
model() {
468+
return 'f';
469+
}
470+
}
471+
);
472+
473+
await this.visit('/a/b');
474+
await this.visit('/a');
475+
476+
await this.visit('/a/b');
477+
await this.visit('/a/c');
478+
479+
await this.visit('/a/b');
480+
await this.visit('/d');
481+
482+
await this.visit('/a/b');
483+
await this.visit('/d/e');
484+
485+
await this.visit('/a/b');
486+
await this.visit('/f');
487+
488+
this.assert.verifySteps(
489+
['b', 'b', 'b', 'b', 'b'],
490+
'The @model property of the Foo component should be stable in the willDestroy hook'
491+
);
492+
}
493+
401494
['@test it should produce a stable DOM when the model changes']() {
402495
this.router.map(function () {
403496
this.route('color', { path: '/colors/:color' });

vite.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ export default defineConfig(({ mode }) => {
4646
viteResolverBug(),
4747
version(),
4848
],
49+
resolve: {
50+
alias: {
51+
'@glimmer/component': resolve(
52+
dirname(fileURLToPath(import.meta.url)),
53+
'./packages/@glimmer/component/dist/index.js'
54+
),
55+
},
56+
},
4957
optimizeDeps: { noDiscovery: true, include: ['expect-type'] },
5058
publicDir: 'tests/public',
5159
build,

0 commit comments

Comments
 (0)