Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: not render data with React Hook Form #6950

Closed
swotiendang opened this issue Jul 30, 2024 · 13 comments · Fixed by #6951 or leoo1992/GeradorQRCode#85 · May be fixed by mtech-31-quemistry/quemistry_client_web#20
Closed

Editor: not render data with React Hook Form #6950

swotiendang opened this issue Jul 30, 2024 · 13 comments · Fixed by #6951 or leoo1992/GeradorQRCode#85 · May be fixed by mtech-31-quemistry/quemistry_client_web#20
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@swotiendang
Copy link
Contributor

swotiendang commented Jul 30, 2024

Describe the bug

Cannot render data in Editor

2024-07-30_175903

Reproducer

https://stackblitz.com/edit/vitejs-vite-ccxqty?file=src%2FApp.jsx

System Information

  • quill 2.0.0
  • primereact 10.6.6, 10.8.0
  • Chrome v127 (latest)

Steps to reproduce the behavior

No response

Expected behavior

No response

@swotiendang swotiendang added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jul 30, 2024
@melloware melloware added Status: Needs Reproducer Issue needs a runnable reproducer and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jul 30, 2024
Copy link

Please fork the Stackblitz project and create a case demonstrating your bug report. This issue will be closed if no activities in 20 days.

@melloware melloware changed the title Editor not render data Editor: not render data Jul 30, 2024
@swotiendang
Copy link
Contributor Author

@melloware
Copy link
Member

@swotiendang it works outside of React Hook Form see my reproducer: https://stackblitz.com/edit/vitejs-vite-mdqney?file=package.json,src%2FApp.jsx

You might want to debug RHF.

@melloware melloware changed the title Editor: not render data Editor: not render data with React Hook Form Jul 30, 2024
@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Reproducer Issue needs a runnable reproducer labels Jul 30, 2024
@swotiendang
Copy link
Contributor Author

Hi @melloware , please take a look at this image:
image

the value is passed to Editor but it didn't display, in this case, I highly believe it's issue of Editor, not ReactFormHook

@melloware
Copy link
Member

But if you look at my example why does it work outside of RHF?

@swotiendang
Copy link
Contributor Author

@melloware I cannot tell, what I can see value props is passed to Editor successfully, but it renders nothing. My guess is: Editor in primereact handle shouldComponentUpdate incorrectly, I would browse into source code of Editor when having time to check.

Some other people faces the same issue: https://stackoverflow.com/questions/78421490/im-not-able-to-render-data-in-the-prime-react-editor

@melloware
Copy link
Member

@avasuro any thoughts you just recently made changes to editor...

@avasuro
Copy link
Contributor

avasuro commented Jul 30, 2024

No ideas for now, but I have more minimalistic reproduction, which shows that same bug reproduces also outside RHF:
https://stackblitz.com/edit/vitejs-vite-hssdna?file=src%2FApp.jsx

Here bug reproduces if input value changes in some useEffect immediately after first render. To make demo work as expected - comment setValue inside useEffect and uncomment setTimeout function to update input value with a little delay.

P.S.: I think it's because of closure to initQuill function, that contains reference to initial (empty) props.value instead of taking the most up to date, and useUpdateEffect doesn't called on first rerender, because quill is not initialized at that moment (quill.current is undefined).

P.P.S.: I think I have a fix for that (just, probably, a bit ugly)

@melloware
Copy link
Member

nice work @avasuro

@swotiendang
Copy link
Contributor Author

Thanks @melloware , @avasuro

@OldManMeta
Copy link

This issue is still present in 10.8.2

render={({ field, fieldState }) => {
        
                    // Debugging useEffect to check value passed to Editor
                    useEffect(() => {
                        console.log("Current value passed to Editor:", field.value);
                    }, [field.value]);
            
                    return(
                    <>                       
                            <Editor 
                                id={field.name}
                                value={field.value}                        
                                onTextChange={(e: EditorTextChangeEvent) => field.onChange(e.htmlValue)}  
                                headerTemplate={editorHeader} 
                                className={classNames({ 'p-invalid': fieldState.error })}
                            />
</>

@quoctienkt
Copy link

quoctienkt commented Aug 18, 2024

@OldManMeta make sure to remove node_modules and do npm install. It should my problem after upgrade to [email protected]
2024-08-18_142405

@OldManMeta
Copy link

Yeah tried several ways to try to get this to work - just couldn't. In the end reverted back to react-quill directly.

Thanks for the response - love primereact BTW.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment