Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Android/Fabric] setPageWithoutAnimation from useLayoutEffect is ignored when targeting a newly added page

Aperta
#1,196 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
android, react-native, typescript
Ambito
mobile

Direzione di ricerca

Start with the reproduction source’s App.tsx and the Android implementation of PagerView’s setPageWithoutAnimation command; trace how the command is handled when children are added. Compare the reported retry behavior with the command-only deferred patch in the archive. Done means the first request selects page D after adding pages, without a retry, and the existing pager behavior remains intact.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

Calling setPageWithoutAnimation(3) from useLayoutEffect immediately after expanding the pager from one page to four can leave the pager on page 0.

I reproduced this on a physical Android device using a standalone app with synthetic pages. The pager remains on page A for more than five seconds after requesting page D. Repeating the same command afterward switches to D successfully.

Environment
  • react-native-pager-view: 9.0.7
  • React Native: 0.88.0
  • React: 19.3.0
  • Architecture: Fabric
  • Device: V2509A, physical device, arm64-v8a
  • Android: 16 / API 36
  • Build: Android debug native build with bundled JS (dev=false), developer support disabled, no Metro connection

The baseline uses pager-view 9.0.7 with diagnostic logging only, without behavior-changing pager patches.

Steps to reproduce
  1. Render a PagerView containing only page A, with initialPage={0}.
  2. Wait for a nonzero layout and the initial onPageSelected event reporting index 0.
  3. Press Add pages & select D. This appends pages B, C, and D.
  4. In the useLayoutEffect associated with that update, call setPageWithoutAnimation(3).
  5. Observe that the pager remains on A.
  6. Wait several seconds, then press Retry select D, which repeats the same command without changing the children.
  7. The pager now switches to D and reports index 3.

The relevant update logic is:

const pager = useRef<PagerView>(null);
const [count, setCount] = useState(1);

useLayoutEffect(() => {
  if (count === 4) {
    pager.current?.setPageWithoutAnimation(3);
  }
}, [count]);

// "Add pages & select D"
setCount(4);

// "Retry select D"
pager.current?.setPageWithoutAnimation(3);

The rendered children are PAGES.slice(0, count), with stable keys and collapsable={false}. The pager has a fixed positive height. No artificial mounting delays are introduced.

Expected behavior

The command selects the newly added page D once the corresponding child update has mounted, without requiring another command.

Actual behavior and device recording

https://github.com/user-attachments/assets/e859a058-98a2-4598-9d10-8374c806d5b8

In the baseline recording:

  • At approximately 3.10 seconds, the React child count becomes 4 and the requested index is 3 (D), but the visible page and last onPageSelected value remain A / 0.
  • This mismatch persists for approximately 5.5 seconds.
  • After pressing Retry select D, the visible page changes to D at approximately 8.58 seconds, and onPageSelected reports index 3 at approximately 8.60 seconds.

The “React children” counter reflects the React render state; it does not measure the number of children already mounted natively.

Command-only comparison

https://github.com/user-attachments/assets/77a4eb37-794d-4da9-ba99-dcec21c77830

I also tested a local change that defers command processing with View.post and validates the target index when the deferred command runs.

With that change, the same operation on the same device reaches D without pressing Retry. The comparison does not include measurement, page identity, or reattachment changes.

This supports a possible command-versus-child-mount timing issue. However, I could not obtain useful native logs from the device, so the exact native dispatch order has not been directly confirmed. The comparison demonstrates a fix for this reproduction, rather than establishing a complete solution for all command-ordering cases.

These recordings specifically test setPageWithoutAnimation; animated setPage was not tested on the device.

Reproduction source

repro-source.zip

The archive includes the tested App.tsx, build instructions, and the command-only comparison patch. Its README documents the build setup and verification scope.

Lingua principale
TypeScript
Stelle
3.4k
Fork
490
Merge medio
2g 5h
PR unite (30g)
34

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di callstack/react-native-pager-view

Tutte le issue di callstack/react-native-pager-view

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.