Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Consider automatically pushing out a script tag that sets the checksum #48

Open
aickin opened this issue Mar 2, 2017 · 1 comment
Open

Comments

@aickin
Copy link

aickin commented Mar 2, 2017

I sent this in a tweet to @divmain but thought it was worth expanding on here.

The first version of react-dom-stream took the same checksum strategy you are using here in Rapscallion: have the checksum be an extra attribute on the stream which the API client can then read out into a script tag, and that script tag in turn sets the checksum on the react root. This strategy works, but it caused a lot of confusion with users; if my experience is any indication, you may end up spending a lot of time explaining and supporting this quirk in github issues/gitter.

I wanted to just render out the script tag that was needed at the end of the stream, but React complains when it renders into an element where there are siblings that weren't made by React. I realized later, though, that you could read out such a script tag at the end of the stream and have it set the checksum and then delete itself from the DOM before React client rendering happens. I tested this in all my supported browsers, and it worked. Its implementation is here, and you should feel free to use any part of it that is helpful in Rapscallion.

Cheers!

@divmain
Copy link
Contributor

divmain commented Mar 2, 2017

Thanks for expanding on this here! One thought is that this could be optional and explicit, by passing an option to the toStream method. Something like renderer.toStream({ autoInsertChecksum: true }).pipe(res);

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

No branches or pull requests

2 participants