-
Notifications
You must be signed in to change notification settings - Fork 2
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
Make <Message> SSR-able #11
Comments
Hey @StephenTangCook, I have tried a few ways such as passing global data (users, channels, hooks) through prop drilling to remove useEffect and zustand (which uses useRef internally). That worked out but a few components such as plain_text_input, static_select_element, checkboxes_element, users_select_element can't work without react's useState. Just having two components like and use them based on the prop user has passed (example prop - renderingOnServer?:boolean) is not working because the useState is still in the build folder. So the final solution could be maintaining two copies of the library and then user would be able to import it like this
in the server we won't put useState and useEffect in the build/output folder. But having two copies of the library is little hard and would be hectic. I understand your concern/thought of choosing SSR over client rendering. SSR indeed gives your speed. But sadly, the solution for now is to use 'use client' in the message wrapper in the end user codebase. if you have any other idea/solution in your mind to solve this issue, let me know I would love to discuss. |
What exactly is not working? Please correct me if I'm not understanding the problem. Can we not just add The only issue I foresee there is that you can't pass functions (i.e. your |
@StephenTangCook Yeah we can add "use client" in the components where we are using the react hooks, but prop drilling will make the codebase a little bit dirty because I have a very deep nested components. I did not get it like why we can't pass my hooks from server to client could you please explain it?
|
When you pass props from a server component to a client component through the server-client boundary, the props must be serializable. Functions are not serializable, so your |
For my use case, we would want the
<Message>
component to be server-side renderable (SSR). Specifically, we use NextJS (info).I understand that if you want interactivity for certain blocks (e.g. buttons, inputs, etc), this won't be possible. We aren't targeting interactive blocks at the moment, but the larger majority of the components should be SSR-able. It is okay if react interactivity is isolated to those components, and those components should be marked with
'use client'
.This would require the following to be removed/refactored:
useEffect
inMessage
:slack-blocks-to-jsx/src/message.tsx
Lines 53 to 57 in 9d462ca
slack-blocks-to-jsx/src/message.tsx
Line 51 in 9d462ca
The text was updated successfully, but these errors were encountered: