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

onSSR causes injection error when container top-element is identical to content #2

Open
neopostmodern opened this issue Oct 8, 2016 · 2 comments

Comments

@neopostmodern
Copy link

I have a function that post-processes markdown text to inject images. It will only run correctly on the client, so I use placeholders on the server. This function is called htmlImageIdReplacementHack.

let post = <div dangerouslySetInnerHTML={{__html: htmlImageIdReplacementHack(Marked(content))}}
                style={{marginBottom: '4rem'}}/>;
return <NoSSR key={_id} onSSR={post}>{post}</NoSSR>

This code throws the following warning:

Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
 (client) ta-reactid="56"><p><a href="/cfs/files/i
 (server) ta-reactid="56"><p></p><div style="width

If I use onSSR={<i>Loading...</i>} instead everything is fine.

@neopostmodern
Copy link
Author

I found the cause of the issue:
Apparently the onSSR block is evaluated on the client too and it only works if the onSSR block yields the same result on the server and on the client. I added a weird flag to my htmlImageIdReplacementHack function and then use Meteor.isServer || simulateSSR in there, but that sounds far from ideal to me.

@lleaff
Copy link

lleaff commented Apr 18, 2017

To resolve this in a generic way, how about requiring that component props (onSSR), be wrapped in a callback so they aren't evaluated unless it's needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants