|
1 |
| -import { Suspense, useId, useLayoutEffect } from "react"; |
| 1 | +import { |
| 2 | + forwardRef, |
| 3 | + Suspense, |
| 4 | + useId, |
| 5 | + useLayoutEffect, |
| 6 | + type ElementRef, |
| 7 | +} from "react"; |
2 | 8 | import { ErrorBoundary } from "react-error-boundary";
|
3 | 9 | import { ClientOnly } from "./shared/client-only";
|
4 | 10 | import { PolyfillLoader } from "./shared/scroll-polyfill";
|
@@ -165,29 +171,35 @@ type ScrollProps = {
|
165 | 171 | action: AnimationAction;
|
166 | 172 | };
|
167 | 173 |
|
168 |
| -export const Scroll = ({ debug = false, children, action }: ScrollProps) => { |
169 |
| - const nakedId = useId(); |
170 |
| - const id = escapeCssSpecifier(nakedId); |
171 |
| - |
172 |
| - return ( |
173 |
| - <> |
174 |
| - <ClientOnly fallback={<StylesBeforeAnimate id={id} action={action} />}> |
175 |
| - <Suspense fallback={<StylesBeforeAnimate id={id} action={action} />}> |
176 |
| - <ErrorBoundary |
177 |
| - fallback={null} |
178 |
| - onError={(error) => { |
179 |
| - console.error(`Polyfill loading error`, error); |
180 |
| - }} |
181 |
| - > |
182 |
| - <PolyfillLoader /> |
183 |
| - {debug && <DebugDelayLoader />} |
184 |
| - </ErrorBoundary> |
185 |
| - <Animate id={id} action={action} /> |
186 |
| - </Suspense> |
187 |
| - </ClientOnly> |
188 |
| - <div {...{ [componentAttributeId]: id }} style={{ display: "contents" }}> |
189 |
| - {children} |
190 |
| - </div> |
191 |
| - </> |
192 |
| - ); |
193 |
| -}; |
| 174 | +export const Scroll = forwardRef<ElementRef<"div">, ScrollProps>( |
| 175 | + ({ debug = false, children, action }, ref) => { |
| 176 | + const nakedId = useId(); |
| 177 | + const id = escapeCssSpecifier(nakedId); |
| 178 | + |
| 179 | + return ( |
| 180 | + <> |
| 181 | + <ClientOnly fallback={<StylesBeforeAnimate id={id} action={action} />}> |
| 182 | + <Suspense fallback={<StylesBeforeAnimate id={id} action={action} />}> |
| 183 | + <ErrorBoundary |
| 184 | + fallback={null} |
| 185 | + onError={(error) => { |
| 186 | + console.error(`Polyfill loading error`, error); |
| 187 | + }} |
| 188 | + > |
| 189 | + <PolyfillLoader /> |
| 190 | + {debug && <DebugDelayLoader />} |
| 191 | + </ErrorBoundary> |
| 192 | + <Animate id={id} action={action} /> |
| 193 | + </Suspense> |
| 194 | + </ClientOnly> |
| 195 | + <div |
| 196 | + ref={ref} |
| 197 | + {...{ [componentAttributeId]: id }} |
| 198 | + style={{ display: "contents" }} |
| 199 | + > |
| 200 | + {children} |
| 201 | + </div> |
| 202 | + </> |
| 203 | + ); |
| 204 | + } |
| 205 | +); |
0 commit comments