Commit 47823a2
fix(engines): guard usePdfiumEngine success path against cancellation
The init effect only checked its `cancelled` flag on the error path, so
under React Strict Mode's dev mount/unmount/remount it created two engines
and called `setEngine` for both. The second engine identity remounts any
consumer keyed on the engine (e.g. `<EmbedPDF>`), abandoning an in-flight
document load, and the first engine leaks because the cleanup that ran saw
`engineRef.current === null`.
Guard the success path: if the effect was already torn down, destroy the
freshly created engine and return before touching state.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 07ed5fe commit 47823a2
2 files changed
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
47 | 61 | | |
48 | 62 | | |
49 | 63 | | |
| |||
0 commit comments