diegomura / diegomura/react-pdf
Library conflicts with libraries that uses `useSyncExternalStore` React 18 API
- Dominant language
- TypeScript
- Stars
- 16.8k
- Forks
- 1.3k
- Avg merge
- 5h 6m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
I tried to add `@react-pdf/renderer` library to my project that uses `import "@preact/signals-react"` and received the next error:
```
dispatcher.useSyncExternalStore is not a function
```
**To Reproduce**
1. Generate react project with CRA or VITE
2. Add `@react-pdf/renderer` and `@preact/signals-react` dependencies
3. Add next code
4. Observe error
```
import "@preact/signals-react";
import { createRoot } from "react-dom/client";
import { PDFViewer, Document, View, Text, Page } from "@react-pdf/renderer";
function SeparateComponent() {
return Hello, World!;
}
createRoot(document.getElementById("root")).render(
Hello, World!
{/* if you comment next line everything will work properly */}
);
```
Link to codesandbox:
https://codesandbox.io/s/heuristic-worker-o55gp4?file=/src/index.js:0-542
**Expected behavior**
Should work properly
UPDATE:
I was able to solve this problem from my side. My actions:
- downgrade library version to @react-pdf/renderer@3.0.3
- override library dependencies with npm overrides feature to latest verion:
```
"overrides": {
"@react-pdf/renderer": {
"react-reconciler": "$react-reconciler",
"scheduler": "$scheduler",
"react": "$react"
}
}
```
- polyfill 'events' module
It still displays an error in the browser console but the PDF view itself works.
Contributor guide
Assessment
This issue has not been assessed yet.