stereobooster / react-snap

👻 Zero-configuration framework-agnostic static prerendering for SPAs
MIT License
5.06k stars 394 forks source link

__PRELOADED_STATE__ set twice on window object after build #320

Closed RichardProf closed 5 years ago

RichardProf commented 5 years ago

Bug Report

Current Behavior I use react-snap to pre-render my pages and Redux to manage my state.

// Grab the state from a global variable injected into the server-generated HTML const preloadedState = window.__PRELOADED_STATE__ || {};

// Allow the passed state to be garbage-collected delete window.__PRELOADED_STATE__;

// Create Redux store with initial state const store = createStore(rootReducer, preloadedState, applyMiddleware(thunk));

// Tell react-snap how to save Redux state window.snapSaveState = () => ({__PRELOADED_STATE__: store.getState()});

And then once pre-rendered, in index.html there is 2 setting of PRELOADED_STATE which adds to our index.html size. We want the size of index.html as small as possible, there is no point in setting PRELOADED_STATE twice:

and then happens again on the same page:

Reproducible demo This is a private project

Expected behavior/code In the inline script only set __PREOADED_STATE__ once.

Possible Solution

Additional context/Screenshots Add any other context about the problem here. If applicable, add screenshots to help explain.

stereobooster commented 5 years ago

Last time I checked there was only one copy of data stored by reactSnap. Unless you provide reproducible example, nothing I can do about it. I'm not interested in your private project, the idea is to create repository where it is possible to reproduce bug

stereobooster commented 5 years ago

Can't proceed without details