Skip to content

Commit d5af80d

Browse files
committed
Seems to work
1 parent 9daa604 commit d5af80d

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

ember-primitives/src/polyfill/anchor-hash-targets.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable ember/no-runloop */
2+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
3+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
14
import { warn } from '@ember/debug';
25
import { isDestroyed, isDestroying, registerDestructor } from '@ember/destroyable';
36
import { getOwner } from '@ember/owner';
@@ -17,10 +20,10 @@ type TransitionWithPrivateAPIs = Transition & {
1720

1821
export function withHashSupport(AppRouter: typeof EmberRouter): typeof AppRouter {
1922
return class RouterWithHashSupport extends AppRouter {
20-
constructor(...args: RouterArgs) {
23+
constructor(...args: any[]) {
2124
super(...args);
2225

23-
setupHashSupport(this);
26+
void setupHashSupport(this);
2427
}
2528
};
2629
}
@@ -93,7 +96,7 @@ async function setupHashSupport(router: EmberRouter) {
9396
*
9497
*/
9598
requestAnimationFrame(() => {
96-
eventuallyTryScrollingTo(owner, initialURL);
99+
void eventuallyTryScrollingTo(owner, initialURL);
97100
});
98101

99102
const routerService = owner.lookup('service:router');
@@ -105,21 +108,21 @@ async function setupHashSupport(router: EmberRouter) {
105108
return;
106109
}
107110

108-
eventuallyTryScrollingTo(owner, url);
111+
void eventuallyTryScrollingTo(owner, url);
109112
}
110113

114+
// @ts-expect-error -- I don't want to fix this
111115
routerService.on('routeDidChange', handleHashIntent);
112116

113117
registerDestructor(router, () => {
114-
(routerService as any) /* type def missing "off" */
115-
.off('routeDidChange', handleHashIntent);
118+
routerService.off('routeDidChange', handleHashIntent);
116119
});
117120
}
118121

119122
const CACHE = new WeakMap<ApplicationInstance, MutationObserver>();
120123

121124
async function eventuallyTryScrollingTo(owner: ApplicationInstance, url?: string) {
122-
// Prevent quick / rapid transitions from continuing to observer beyond their URL-scope
125+
// Prevent quick / rapid transitions from continuing to observe beyond their URL-scope
123126
CACHE.get(owner)?.disconnect();
124127

125128
if (!url) return;
@@ -140,7 +143,11 @@ async function eventuallyTryScrollingTo(owner: ApplicationInstance, url?: string
140143
const TIME_SINCE_LAST_MUTATION = 500; // ms
141144
const MAX_TIMEOUT = 2000; // ms
142145

143-
// exported for testing
146+
/**
147+
* exported for testing
148+
*
149+
* @internal
150+
*/
144151
export async function uiSettled(owner: ApplicationInstance) {
145152
const timeStarted = new Date().getTime();
146153
let lastMutationAt = Infinity;

test-app/tests/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
<script type="module">
3434
import { start } from "./test-helper";
35-
import.meta.glob("./**/*.{js,ts,gjs,gts}", { eager: true });
35+
import.meta.glob("./**/**/*-test.{js,ts,gjs,gts}", { eager: true });
3636

3737
start();
3838
</script>

test-app/tests/polyfill/anchor-hash-targets-test.gts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { setupApplicationTest } from 'ember-qunit';
1212

1313
import { scrollToHash, uiSettled } from 'ember-primitives/polyfill/anchor-hash-targets';
1414

15-
import { setupRouter } from './-helpers';
15+
import { setupRouter } from './-helpers.ts';
1616

1717
import type RouterService from '@ember/routing/router-service';
1818

19-
module('Hash', function (hooks) {
19+
module('anchor-hash-target', function (hooks) {
2020
setupApplicationTest(hooks);
2121

2222
hooks.beforeEach(() => {

0 commit comments

Comments
 (0)