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
5 changes: 5 additions & 0 deletions .changeset/hip-memes-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hirasso/restore-scroll": patch
---

Check types during unit tests
5 changes: 5 additions & 0 deletions .changeset/mean-baboons-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hirasso/restore-scroll": patch
---

Resolve `<body>` to the root scrolling element
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Make sure the PR fulfills as many of the following requirements as possible

- [ ] The PR is submitted to the `main` branch
- [ ] The code was formatted before pushing (`pnpm run format`)
- [ ] All tests are passing (`pnpm run test`)
- [ ] New or updated tests are included
- [ ] The documentation was updated as required

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ jobs:
- name: Build
run: pnpm run build

- name: Typecheck
run: pnpm run typecheck

- name: Run tests
run: pnpm run test:unit
2 changes: 1 addition & 1 deletion .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
"**/*.{js,ts,mjs}": ["prettier --write"],
"**/*.{js,ts,mjs}": ["pnpm run format"],
"**/*.astro": ["astro check"],
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"test:unit:watch": "vitest --config ./tests/unit/vitest.config.ts",
"test:e2e": "pnpm exec playwright test --config ./tests/e2e/config.playwright.ts",
"test:e2e:dev": "PLAYWRIGHT_ENV=dev pnpm run test:e2e --ui",
"test:e2e:install": "pnpm exec playwright install --with-deps"
"test:e2e:install": "pnpm exec playwright install --with-deps",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@changesets/cli": "^2.28.1",
Expand Down
9 changes: 0 additions & 9 deletions src/env.ts

This file was deleted.

7 changes: 4 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function createContainerSelector(
/**
* Check if an element is a root element (<html> or <body>)
*/
export function isRootElement(element: Element): boolean {
export function isRootElement(element: unknown): boolean {
return (
element instanceof HTMLHtmlElement || element instanceof HTMLBodyElement
);
Expand Down Expand Up @@ -206,8 +206,9 @@ export function commitScrollState(state: ScrollState) {
* Resolve a target
*/
export function resolveTarget(target: Target | null): Element | null {
/** The window */
if (target === window) {
if (!target) return null;

if (target === window || isRootElement(target)) {
return document.scrollingElement ?? document.documentElement;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/tests/resolveTarget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ describe("resolveTarget", () => {
expect(resolveTarget(window)).toEqual(document.documentElement);
});

it("resolves the <body> to the document root", () => {
expect(resolveTarget(document.body)).toEqual(document.documentElement);
});

it("Returns either an element or nothing", () => {
const existing = document.querySelector(".foo");
const missing = document.querySelector(".waldo");
Expand Down
Loading