@ssgoi/react 6.5.0 → 6.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +91 -22
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -45,6 +45,7 @@ pnpm add @ssgoi/react
45
45
  ```tsx
46
46
  import { Ssgoi } from "@ssgoi/react";
47
47
  import { fade } from "@ssgoi/react/view-transitions";
48
+ import { SsgoiTransitionBoundary } from "./ssgoi-transition-boundary";
48
49
 
49
50
  const config = {
50
51
  transitions: [fade({ paths: ["/", "/about"] })],
@@ -52,20 +53,25 @@ const config = {
52
53
 
53
54
  export default function App() {
54
55
  return (
55
- <Ssgoi config={config}>
56
- {/* relative + z-0 are required (see "Layout Requirements" below) */}
57
- <div className="relative z-0">{/* Your app */}</div>
58
- </Ssgoi>
56
+ <div className="relative z-0 min-h-dvh bg-white">
57
+ {/* Layout shell above: positioned ancestor + stacking context for the OUT clone. */}
58
+ <Ssgoi config={config}>
59
+ {/* Routed content marker. Layout positioning belongs to the outer wrapper. */}
60
+ <SsgoiTransitionBoundary className="min-h-full bg-white">
61
+ {/* Your app */}
62
+ </SsgoiTransitionBoundary>
63
+ </Ssgoi>
64
+ </div>
59
65
  );
60
66
  }
61
67
  ```
62
68
 
63
- ### 2. Mark your pages
69
+ ### 2. Keep pages unmarked
64
70
 
65
71
  ```tsx
66
72
  export default function HomePage() {
67
73
  return (
68
- <main data-ssgoi-transition="/">
74
+ <main>
69
75
  <h1>Welcome</h1>
70
76
  {/* Page content */}
71
77
  </main>
@@ -73,13 +79,59 @@ export default function HomePage() {
73
79
  }
74
80
  ```
75
81
 
82
+ Create one router-specific `SsgoiTransitionBoundary` utility in your layout.
83
+ It reads the current pathname internally, sets the transition boundary key, and
84
+ uses that pathname as a logical page id matched by config such as
85
+ `/products/*`. Use `/products/**` when the parent path itself should match too.
86
+
87
+ Next.js implementation:
88
+
89
+ ```tsx
90
+ "use client";
91
+
92
+ import { type ElementType, type ReactNode } from "react";
93
+ import { usePathname } from "next/navigation";
94
+
95
+ export function SsgoiTransitionBoundary({
96
+ children,
97
+ as,
98
+ className,
99
+ }: {
100
+ children: ReactNode;
101
+ as?: ElementType;
102
+ className?: string;
103
+ }) {
104
+ const pathname = usePathname();
105
+ const Component = as ?? "div";
106
+
107
+ return (
108
+ <Component
109
+ key={pathname}
110
+ data-ssgoi-transition={pathname}
111
+ className={className}
112
+ >
113
+ {children}
114
+ </Component>
115
+ );
116
+ }
117
+ ```
118
+
119
+ React Router and TanStack Router use the same component body with their own
120
+ pathname hook.
121
+
76
122
  **That's it!** Your configured pages now transition smoothly with a fade effect.
77
123
 
78
124
  ## Layout Requirements
79
125
 
80
- The element wrapping `<Ssgoi>` needs `position: relative` and `z-index: 0` (`relative z-0` in Tailwind).
126
+ The outer element wrapping the SSGOI provider / `<Ssgoi>` needs
127
+ `position: relative` and `z-index: 0` (`relative z-0` in Tailwind).
81
128
 
82
- When a page leaves, SSGOI clones it back into the DOM with `position: absolute` so it can animate out while the new page animates in. Without a positioned, stacking-context ancestor the clone jumps to the wrong place or falls behind the background. Add `overflow-x-clip` too if you use horizontal transitions (`slide`, `drill`).
129
+ When a page leaves, SSGOI clones it back into the DOM with `position: absolute`
130
+ so it can animate out while the new page animates in. Without a positioned,
131
+ stacking-context ancestor the clone jumps to the wrong place or falls behind the
132
+ background. Add `overflow-x-clip` too if you use horizontal transitions
133
+ (`slide`, `drill`). Keep these layout classes on the outer wrapper, not on the
134
+ route boundary marker.
83
135
 
84
136
  ## Advanced Transitions
85
137
 
@@ -233,9 +285,13 @@ function List() {
233
285
  ## Next.js App Router Example
234
286
 
235
287
  ```tsx
236
- // app/layout.tsx
288
+ // app/ssgoi-provider.tsx
289
+ "use client";
290
+
291
+ import { type ReactNode } from "react";
237
292
  import { Ssgoi } from "@ssgoi/react";
238
293
  import { drill, fade } from "@ssgoi/react/view-transitions";
294
+ import { SsgoiTransitionBoundary } from "./ssgoi-transition-boundary";
239
295
 
240
296
  const config = {
241
297
  transitions: [
@@ -244,17 +300,27 @@ const config = {
244
300
  ],
245
301
  };
246
302
 
247
- export default function RootLayout({
248
- children,
249
- }: {
250
- children: React.ReactNode;
251
- }) {
303
+ export function SsgoiProvider({ children }: { children: ReactNode }) {
304
+ return (
305
+ <Ssgoi config={config}>
306
+ <SsgoiTransitionBoundary className="min-h-full bg-white">
307
+ {children}
308
+ </SsgoiTransitionBoundary>
309
+ </Ssgoi>
310
+ );
311
+ }
312
+
313
+ // app/layout.tsx
314
+ import { type ReactNode } from "react";
315
+ import { SsgoiProvider } from "./ssgoi-provider";
316
+
317
+ export default function RootLayout({ children }: { children: ReactNode }) {
252
318
  return (
253
319
  <html>
254
320
  <body>
255
- <Ssgoi config={config}>
256
- <div className="relative z-0 min-h-screen">{children}</div>
257
- </Ssgoi>
321
+ <main className="relative z-0 min-h-screen bg-white">
322
+ <SsgoiProvider>{children}</SsgoiProvider>
323
+ </main>
258
324
  </body>
259
325
  </html>
260
326
  );
@@ -264,7 +330,7 @@ export default function RootLayout({
264
330
  ```tsx
265
331
  // app/page.tsx
266
332
  export default function Page() {
267
- return <main data-ssgoi-transition="/">{/* Your page content */}</main>;
333
+ return <main>{/* Your page content */}</main>;
268
334
  }
269
335
  ```
270
336
 
@@ -280,13 +346,16 @@ The provider component that manages transition context.
280
346
  <Ssgoi config={ssgoiConfig}>{children}</Ssgoi>
281
347
  ```
282
348
 
283
- #### `data-ssgoi-transition`
349
+ #### Route boundary
284
350
 
285
- Attribute for pages that should transition. Set it on the page boundary element
286
- inside `<Ssgoi>`.
351
+ Use one route boundary utility inside `<Ssgoi>`. It sets
352
+ `data-ssgoi-transition` from the current pathname internally, so individual page
353
+ components do not need transition markers.
287
354
 
288
355
  ```tsx
289
- <main data-ssgoi-transition="/page-id">{children}</main>
356
+ <SsgoiTransitionBoundary className="min-h-full bg-white">
357
+ {children}
358
+ </SsgoiTransitionBoundary>
290
359
  ```
291
360
 
292
361
  ### Hooks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssgoi/react",
3
- "version": "6.5.0",
3
+ "version": "6.6.4",
4
4
  "description": "React bindings for SSGOI - Native app-like page transitions for React applications",
5
5
  "private": false,
6
6
  "type": "module",
@@ -66,7 +66,7 @@
66
66
  "dependencies": {
67
67
  "unplugin": "^2.3.2",
68
68
  "@babel/core": "^7.26.10",
69
- "@ssgoi/core": "^6.5.0"
69
+ "@ssgoi/core": "^6.6.4"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@types/babel__core": "^7.20.5",