Skip to content

Commit 8426d2f

Browse files
authored
Merge pull request #7706 from QwikDev/v2-popstate-scroll-events
fix: adding popstate and scroll event for SPA navigation
2 parents 9849dcf + 92ef2f8 commit 8426d2f

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

.changeset/better-shrimps-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik.dev/router': patch
3+
---
4+
5+
fix: adding popstate and scroll event for SPA navigation

packages/qwik-router/src/runtime/src/spa-init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ export default event$((_: Event, el: Element) => {
198198
win[scrollEnabled] = true;
199199

200200
setTimeout(() => {
201-
addEventListener('popstate', win[initPopstate]!);
202-
addEventListener('scroll', win[initScroll]!, { passive: true });
201+
win.addEventListener('popstate', win[initPopstate]!);
202+
win.addEventListener('scroll', win[initScroll]!, { passive: true });
203203
document.body.addEventListener('click', win[initAnchors]!);
204204

205205
if (!(win as any).navigation) {

packages/qwik/src/core/tests/render-api.spec.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,15 +699,19 @@ describe('render api', () => {
699699
containerTagName: 'div',
700700
debug: true,
701701
});
702-
expect(cleanupAttrs(result.html)).toContain('<script id="qwikloader" async>debug</script>');
702+
expect(cleanupAttrs(result.html)).toContain(
703+
'<script id="qwikloader" async type="module">debug</script>'
704+
);
703705
});
704706

705707
it('should emit qwik loader without debug mode', async () => {
706708
const result = await renderToStringAndSetPlatform(<Counter />, {
707709
containerTagName: 'div',
708710
debug: false,
709711
});
710-
expect(cleanupAttrs(result.html)).toContain('<script id="qwikloader" async>min</script>');
712+
expect(cleanupAttrs(result.html)).toContain(
713+
'<script id="qwikloader" async type="module">min</script>'
714+
);
711715
});
712716
});
713717
describe('snapshotResult', () => {

packages/qwik/src/server/ssr-container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
835835
debug: this.renderOptions.debug,
836836
});
837837
// async allows executing while the DOM is being handled
838-
const scriptAttrs = ['id', 'qwikloader', 'async', true];
838+
const scriptAttrs = ['id', 'qwikloader', 'async', true, 'type', 'module'];
839839
const nonce = this.renderOptions.serverData?.nonce;
840840
if (nonce) {
841841
scriptAttrs.push('nonce', nonce);

0 commit comments

Comments
 (0)