Skip to content

Commit 4318992

Browse files
chore: fix build in CI (#4790)
1 parent be7a578 commit 4318992

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.17.0
1+
24.4.1

e2e/solid-router/basic-scroll-restoration/src/main.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,59 @@ function ByElementComponent() {
191191
)
192192
}
193193

194+
const fooRoute = createRoute({
195+
getParentRoute: () => rootRoute,
196+
path: '/foo',
197+
loader: () => new Promise((r) => setTimeout(r, 500)),
198+
component: FooComponent,
199+
})
200+
201+
function FooComponent() {
202+
return (
203+
<div data-testid="foo-route-component" class="p-2">
204+
<h3 id="greeting">Hello from Foo!</h3>
205+
<Link to="/bar" data-testid="go-to-bar-link">
206+
Go to Bar
207+
</Link>
208+
<div class="space-y-2">
209+
{Array.from({ length: 50 }).map((_, i) => (
210+
<div class="h-[100px] p-2 rounded-lg bg-gray-200 dark:bg-gray-800 border">
211+
Foo Item {i + 1}
212+
</div>
213+
))}
214+
</div>
215+
</div>
216+
)
217+
}
218+
219+
const barRoute = createRoute({
220+
getParentRoute: () => rootRoute,
221+
path: '/bar',
222+
loader: () => new Promise((r) => setTimeout(r, 500)),
223+
component: BarComponent,
224+
})
225+
226+
function BarComponent() {
227+
return (
228+
<div data-testid="bar-route-component" class="p-2">
229+
<h3 id="greeting">Hello from Bar!</h3>
230+
<div class="space-y-2">
231+
{Array.from({ length: 50 }).map((_, i) => (
232+
<div class="h-[100px] p-2 rounded-lg bg-gray-200 dark:bg-gray-800 border">
233+
Bar Item {i + 1}
234+
</div>
235+
))}
236+
</div>
237+
</div>
238+
)
239+
}
240+
194241
const routeTree = rootRoute.addChildren([
195242
indexRoute,
196243
aboutRoute,
197244
byElementRoute,
245+
fooRoute,
246+
barRoute,
198247
])
199248

200249
const router = createRouter({

e2e/solid-router/basic-scroll-restoration/tests/app.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ test('restore scroll positions by page, home pages top message should not displa
2121
expect(scrollPosition).toBe(targetScrollPosition)
2222

2323
await expect(page.locator('#top-message')).not.toBeInViewport()
24+
await page.waitForTimeout(1000)
2425

2526
// Step 3: Navigate to the about page
2627
await page.getByRole('link', { name: 'About', exact: true }).click()
@@ -80,3 +81,34 @@ test('restore scroll positions by element, first regular list item should not di
8081
// )
8182
// expect(restoredScrollPosition).toBe(targetScrollPosition)
8283
})
84+
85+
test('scroll to top when not scrolled, regression test for #4782', async ({
86+
page,
87+
}) => {
88+
await page.goto('/foo')
89+
90+
await expect(page.getByTestId('foo-route-component')).toBeVisible()
91+
92+
let scrollPosition = await page.evaluate(() => window.scrollY)
93+
expect(scrollPosition).toBe(0)
94+
95+
// do not scroll, just navigate to /bar
96+
await page.getByTestId('go-to-bar-link').click()
97+
await expect(page.getByTestId('bar-route-component')).toBeVisible()
98+
99+
const targetScrollPosition = 1000
100+
await page.evaluate(
101+
(scrollPos: number) => window.scrollTo(0, scrollPos),
102+
targetScrollPosition,
103+
)
104+
scrollPosition = await page.evaluate(() => window.scrollY)
105+
expect(scrollPosition).toBe(targetScrollPosition)
106+
107+
// navigate back to /foo
108+
await page.goBack()
109+
await expect(page.getByTestId('foo-route-component')).toBeVisible()
110+
111+
// check if scroll position is restored to 0 since we did not scroll on /foo
112+
const restoredScrollPosition = await page.evaluate(() => window.scrollY)
113+
expect(restoredScrollPosition).toBe(0)
114+
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "git",
66
"url": "https://github.com/TanStack/router.git"
77
},
8-
"packageManager": "pnpm@9.15.5",
8+
"packageManager": "pnpm@10.13.1",
99
"type": "module",
1010
"scripts": {
1111
"cleanNodeModules": "pnpm -r exec rm -rf node_modules",

0 commit comments

Comments
 (0)