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
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ An unofficial add-on for the Next.js App Router. It draws slide transitions betw
- Slide transition between routes; vertical slide for routes in `modalRoutes`.
- Edge-swipe Back (`swipeBack`) with a preview of the previous screen.
- Scroll offset restored per history entry (`preserveScroll`).
- Document scrolling by default (`window.scrollTo`, `window.scrollY` keep working), with a custom vertical scrollbar; an independent scroll container also works (`scrollTarget`).
- Document scrolling by default (`window.scrollTo`, `window.scrollY` keep working); an independent scroll container also works (`scrollTarget`).
- A vertical scrollbar drawn with [OverlayScrollbars](https://github.com/KingSora/OverlayScrollbars): its track stays between fixed headers, footers and tab bars, follows whichever scroller is moving, and can be dragged or clicked.
- `edgeBounce`: optional touch bounce at scroll boundaries on non-Apple touch devices.
- `skipSlideQueryKeys`: skip the page slide when only a popup query parameter changes.
- `fixedTargets` keeps chosen elements still during the slide.
Expand All @@ -52,22 +53,27 @@ An unofficial add-on for the Next.js App Router. It draws slide transitions betw
- Next.js below 16.4.6 and React below 19.3.1 are untested.
- No benchmarks against other libraries.
- No physics or spring animation. Motion is CSS and the Web Animations API.
- No horizontal custom scrollbar. Horizontal overflow keeps native scrolling without a drawn bar.
- The drawn scrollbar no longer shrinks during elastic overscroll; `edgeBounce` still compresses it.

## Where it stands

| | `@uiwwsw/stackflow-next` | `@stackflow/react` |
| --- | --- | --- |
| npm downloads, week of 2026-11-18 | 271 | 38,535 |
| Maintainers | one | Daangn team |
| Status | unofficial | official |

- Usage is close to zero. No known production users.
- It is a visual layer over Next.js. Stackflow is a full navigation stack with its own router and activity model; this package does not replace it.
- Versions 3.0.0 to 3.1.0 were published to npm from a branch before they reached `main`; `main` now matches 3.1.0. Eight releases in one day (3.0.0 to 3.1.0 on 2026-11-17) mean the API is still moving.
- Next.js documents its own View Transitions support ([guide](https://nextjs.org/docs/app/guides/view-transitions)). If a plain page transition is enough, use that and skip this package.
- For animation work, Motion is the common choice (about 40 million weekly downloads).
- For a native-style navigation stack with an official maintainer, use Stackflow.
- Use this package only if you need the swipe-back gesture and per-entry scroll restoration on the Next.js App Router, and accept an unproven, single-maintainer dependency.
One maintainer, no known production users, not tested on real devices. Compared with the libraries people use for the same job on the Next.js App Router (checked against each project's docs or source, November 2026):

| | stackflow-next | [SSGOI](https://github.com/meursyphus/ssgoi) | [next-view-transitions](https://github.com/shuding/next-view-transitions) | [Stackflow](https://github.com/daangn/stackflow) |
| --- | --- | --- | --- | --- |
| Keeps App Router routes and server components | yes | yes | yes | no; its README marks the Next.js example "Not Recommended" |
| Back/Forward plays the reverse direction | yes, from history position | yes, per saved entry | same animation both ways | yes, with its own router |
| Swipe Back with a preview of the previous screen | yes | browser's own gesture only | no | yes (cupertino theme) |
| Scroll position per history entry | yes | yes | no | not applicable |
| Draggable scrollbar kept clear of fixed bars | yes | no | no | no |
| Animation engine | View Transitions API | Web Animations API | View Transitions API | CSS transitions |
| Framework range | Next.js 16.4.6+ | React, Vue, Svelte, Solid, Angular, Qwik; Next.js 13.4–16 | Next.js App Router | React, single page |

- If you need effects beyond slides, older Next.js versions or browsers without View Transitions, SSGOI covers more and is more widely used.
- If a crossfade on link clicks is enough, Next.js's own `<ViewTransition>` or next-view-transitions is smaller.
- This package fits an app-like Next.js site that wants swipe Back, per-entry scroll and a scrollbar that respects its fixed header and tab bar together.
- iOS Safari uses the same left edge for its own Back gesture; how the two interact has not been checked on a device.

## Install

Expand Down
6 changes: 4 additions & 2 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ library.
| Package | Kind | Used for |
| --- | --- | --- |
| `@stackflow/core` | dependency | `aggregate` and `makeEvent` in `src/next/engine.ts`, to build the `Stack` returned by `useStack()`. |
| `overlayscrollbars` | dependency | Draws the vertical scrollbar in `src/next/scroll.ts` (drag, click, auto-hide; handle moved by a `ScrollTimeline` where supported). Its base CSS is bundled into `dist/style.css` by `scripts/build-css.mjs`. |
| `next` | peer | `next/link`, `next/navigation` (`useRouter`, `usePathname`, `useSearchParams`) and the `NextConfig` type. |
| `react`, `react-dom` | peer | Components and hooks (`useSyncExternalStore`, `useLayoutEffect`, `Suspense`). |

Expand Down Expand Up @@ -107,8 +108,9 @@ The `./dom` entry has no dependencies.
ready.
- **`scroll.ts`** Scroll handling for the two modes. Window mode keeps document
scrolling and measures the visible area; container mode scrolls an element.
Both draw the custom vertical scrollbar thumb and help the engine save and
restore offsets.
Both place the scrollbar track (between fixed bars, fitted to the target's
content box) and hand the active scroller to an OverlayScrollbars instance
that draws the handle. They also help the engine save and restore offsets.
- **`swipe.ts`** `attachSwipeBack`. Pointer-event gesture starting in the left
24 px. Moves the live content, reveals a cloned preview of the previous
screen, and on release either calls `router.back()` or settles back.
Expand Down
18 changes: 11 additions & 7 deletions docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,12 @@ hash, or another query key also changes, the usual transition rules apply.
The document scrolls by default. Existing calls to `window.scrollTo()` and
`window.scrollBy()`, reads of `window.scrollY`, and window `scroll` listeners
work with this package. It hides the browser's document scrollbar and
draws a vertical thumb beside the content box of `scrollTarget`, excluding
draws a vertical scrollbar with [OverlayScrollbars](https://github.com/KingSora/OverlayScrollbars)
beside the content box of `scrollTarget`, excluding
its margins, borders and padding. The track starts at the content's top edge
as seen at the start of scrolling and ends at its bottom edge as seen at
the end of scrolling, within the visible viewport. Its length stays steady
as the content moves and the thumb follows the full native scroll range.
as the content moves and the handle follows the full native scroll range.
No header or footer settings are needed.

When a sticky provider slot or a fixed bar covers the track, the track stops
Expand All @@ -262,8 +263,9 @@ height between any recognized bars.

If existing CSS makes the selected area an independent native scroller,
the scrollbar follows that element while it scrolls and switches to the
document when document scrolling takes over. The thumb fades shortly after
vertical scrolling stops.
document when document scrolling takes over. The scrollbar appears while the
pointer moves or the page scrolls and hides 0.8 seconds later. Drag the handle
or click the track to scroll; keyboard, wheel and touch scrolling stay native.

```tsx
<StackflowProvider scrollTarget="[data-app-scroll]">
Expand All @@ -274,9 +276,11 @@ vertical scrolling stops.
Let the provider and content grow with the page. The header sticks to the
top, and `persistent` and `footer` stick together at the bottom. The browser
handles wheel and touch input, momentum, and elastic overscroll where
supported. The thumb compresses at the edge when the browser reports an
elastic offset. Set `--stackflow-scrollbar-color` on the provider to set its
color.
supported. Set `--stackflow-scrollbar-color` and
`--stackflow-scrollbar-active-color` (hover and drag) on the provider to set its
colors. The scrollbar uses the `os-theme-stackflow` OverlayScrollbars theme, so
its CSS variables (`--os-size`, `--os-handle-min-size` and others) can be
overridden too.

If the app positions its own bars with CSS `position: fixed`, reserve their
heights in the layout so the first and last content remain reachable.
Expand Down
2 changes: 1 addition & 1 deletion examples/next-app/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import path from 'node:path';
import {fileURLToPath} from 'node:url';
import { withStackflow } from '../../dist/config.js';
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'../..');
export default withStackflow({ distDir:process.env.STACKFLOW_NEXT_BUILD_DIR||'.next', webpack(config){config.resolve.alias['@uiwwsw/stackflow-next/style.css']=path.join(root,'src/next/style.css');config.resolve.alias['@uiwwsw/stackflow-next$']=path.join(root,'dist/index.js');return config;} });
export default withStackflow({ distDir:process.env.STACKFLOW_NEXT_BUILD_DIR||'.next', webpack(config){config.resolve.alias['@uiwwsw/stackflow-next/style.css']=path.join(root,'dist/style.css');config.resolve.alias['@uiwwsw/stackflow-next$']=path.join(root,'dist/index.js');return config;} });
13 changes: 10 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uiwwsw/stackflow-next",
"version": "3.1.1",
"version": "3.2.0",
"type": "module",
"description": "Unofficial slide transitions, swipe-back and scroll restoration for the Next.js App Router, built on Next.js Cache Components, @stackflow/core and the View Transitions API",
"keywords": [
Expand All @@ -22,7 +22,7 @@
},
"./style.css": {
"types": "./src/style.d.ts",
"default": "./src/next/style.css"
"default": "./dist/style.css"
},
"./dom": {
"types": "./src/index.d.ts",
Expand Down Expand Up @@ -50,7 +50,7 @@
"scripts": {
"test": "node --import tsx --test test/*.test.js test/next/*.test.ts",
"check": "tsc --noEmit",
"build": "tsc",
"build": "tsc && node scripts/build-css.mjs",
"prepack": "npm run build"
},
"devDependencies": {
Expand All @@ -66,7 +66,8 @@
},
"license": "MIT",
"dependencies": {
"@stackflow/core": "^3.1.0"
"@stackflow/core": "^3.1.0",
"overlayscrollbars": "^2.17.1"
},
"peerDependencies": {
"next": "^16.4.6",
Expand Down
13 changes: 13 additions & 0 deletions scripts/build-css.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Bundle OverlayScrollbars' base styles (MIT, license header kept) with the
// package styles so applications import a single `style.css`.
import { readFile, writeFile, mkdir } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const require = createRequire(import.meta.url);
const overlay = await readFile(require.resolve('overlayscrollbars/overlayscrollbars.css'), 'utf8');
const own = await readFile(resolve(root, 'src/next/style.css'), 'utf8');
await mkdir(resolve(root, 'dist'), { recursive: true });
await writeFile(resolve(root, 'dist/style.css'), `${overlay.trim()}\n\n${own.trim()}\n`);
13 changes: 8 additions & 5 deletions src/next/edge-bounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export function attachEdgeBounce(content: HTMLElement, thumb: HTMLElement | unde
|| !content.animate) return;

const reducedMotion = win.matchMedia('(prefers-reduced-motion: reduce)');
const indicator = thumb?.firstElementChild;
// The handle of the visible drawn scrollbar inside the slot, if any.
const indicator = () => thumb?.querySelector<HTMLElement>('.os-scrollbar-vertical.os-scrollbar-visible .os-scrollbar-handle') ?? undefined;
let gesture: Gesture | undefined;
let frame = 0;
let latest: Touch | undefined;
Expand Down Expand Up @@ -119,9 +120,10 @@ export function attachEdgeBounce(content: HTMLElement, thumb: HTMLElement | unde
bodyAnimation = surface.animate([{translate: '0 0px'}, {translate: `0 ${edge * maxPull}px`}],
{ ...added, duration: maxPull });
bodyAnimation.pause();
if (indicator && thumb && !thumb.hidden) {
const handle = indicator();
if (handle && thumb && !thumb.hidden) {
const transformOrigin = edge > 0 ? 'center top' : 'center bottom';
thumbAnimation = indicator.animate([{scale: '1 1', transformOrigin}, {scale: '1 .55', transformOrigin}],
thumbAnimation = handle.animate([{scale: '1 1', transformOrigin}, {scale: '1 .55', transformOrigin}],
{ duration: maxPull, fill: 'both' });
thumbAnimation.pause();
}
Expand All @@ -146,8 +148,9 @@ export function attachEdgeBounce(content: HTMLElement, thumb: HTMLElement | unde
stop();
const settling = surface.animate([{translate: `0 ${pull}px`}, {translate: '0 0px'}], { ...returnTiming, composite: 'add' });
bodyAnimation = settling;
if (indicator && thumb && !thumb.hidden) {
thumbAnimation = indicator.animate([{scale: `1 ${scale}`, transformOrigin}, {scale: '1 1', transformOrigin}], returnTiming);
const handle = indicator();
if (handle && thumb && !thumb.hidden) {
thumbAnimation = handle.animate([{scale: `1 ${scale}`, transformOrigin}, {scale: '1 1', transformOrigin}], returnTiming);
thumb.setAttribute('data-stackflow-bouncing', '');
}
settling.onfinish = () => {
Expand Down
4 changes: 1 addition & 3 deletions src/next/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ export function StackflowProvider({children,header,footer,persistent,animation='
{header && <div className="stackflow-next-header">{header}</div>}
<div className="stackflow-next-viewport">
<div ref={viewport} className="stackflow-next-content">{children}</div>
<div ref={scrollbar} className="stackflow-next-scrollbar" aria-hidden="true" hidden>
<div className="stackflow-next-scrollbar-thumb" />
</div>
<div ref={scrollbar} className="stackflow-next-scrollbar" aria-hidden="true" hidden />
</div>
{scrollMode === 'window' ? <div className="stackflow-next-bottom">{bottom}</div> : bottom}
</div>
Expand Down
Loading
Loading