rehydrate: true option gives error
See original GitHub issueOperating System: Manjaro Linux 17.0.5 Kernel: 4.9.51-1-MANJARO Node: 8.5.0 NPM: 5.4.2 Browser: Chromium 61.0.3163.91 Angular: 4.4.3 ngrx/store: 4.0.3 ngrx-store-localstorage: 0.2.2 zone.js: 0.8.17
My app works fine, but when I add the rehydrate: true
option, I get the error below when I try to refresh the page after I’ve logged in. I can provide more code or information if required.
Sample reducer
import * as OrganizationActions from '../actions/organization';
const initialState = '';
export function reducer(state: string = initialState, action: OrganizationActions.Actions): string {
switch (action.type) {
case OrganizationActions.ActionTypes.SET_ORGANIZATION:
return action.payload;
default:
return state;
}
}
Sample action
import { Action } from '@ngrx/store';
export const ActionTypes = {
SET_ORGANIZATION: 'SET_ORGANIZATION'
};
export class SetOrganizationAction implements Action {
readonly type = ActionTypes.SET_ORGANIZATION;
constructor(public payload: string) { }
}
export type Actions = SetOrganizationAction;
Main reducer file
import * as Assessment from '../reducers/assessment';
import * as Organization from '../reducers/organization';
import * as Person from '../reducers/person';
import * as Team from '../reducers/team';
import * as Token from '../reducers/token';
import { ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store';
import { State } from './../../models/state';
import { localStorageSync } from 'ngrx-store-localstorage';
export const appReducers: ActionReducerMap<State> = {
token: Token.reducer,
organization: Organization.reducer,
team: Team.reducer,
person: Person.reducer,
assessment: Assessment.reducer
};
const localStorageSyncReducer = localStorageSync({
keys: ['token', 'organization', 'team', 'person', 'assessment'],
rehydrate: true
});
export function localStorageSyncMetaReducer(reducer: ActionReducer<any>): ActionReducer<any> {
return localStorageSyncReducer(reducer);
}
export const metaReducers: MetaReducer<any>[] = [localStorageSyncMetaReducer];
Error
Unhandled Promise rejection: Unexpected token c in JSON at position 0 ; Zone: <root> ; Task: Promise.then ; Value: SyntaxError: Unexpected token c in JSON at position 0
at Object.parse (<anonymous>)
at vendor.bundle.js:10876
at Array.reduce (<anonymous>)
at Object.webpackJsonp.../../../../ngrx-store-localstorage/dist/index.js.exports.rehydrateApplicationState (vendor.bundle.js:10835)
at vendor.bundle.js:10961
at localStorageSyncMetaReducer (main.bundle.js:3238)
at vendor.bundle.js:7072
at Array.reduceRight (<anonymous>)
at vendor.bundle.js:7072
at new ReducerManager (vendor.bundle.js:7170) SyntaxError: Unexpected token c in JSON at position 0
at Object.parse (<anonymous>)
at http://localhost:4200/vendor.bundle.js:10876:28
at Array.reduce (<anonymous>)
at Object.webpackJsonp.../../../../ngrx-store-localstorage/dist/index.js.exports.rehydrateApplicationState (http://localhost:4200/vendor.bundle.js:10835:17)
at http://localhost:4200/vendor.bundle.js:10961:54
at localStorageSyncMetaReducer (http://localhost:4200/main.bundle.js:3238:12)
at http://localhost:4200/vendor.bundle.js:7072:66
at Array.reduceRight (<anonymous>)
at http://localhost:4200/vendor.bundle.js:7072:21
at new ReducerManager (http://localhost:4200/vendor.bundle.js:7170:39)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
browser.hydrate: false breaks client-side router #4382 - GitHub
The first problem is that hydrate: true is unconditionally set in the code (where root.svelte is generated). Setting this to false for testing ......
Read more >react-hydration-error - Next.js
In general this issue is caused by using a specific library or application code that is relying on something that could differ between...
Read more >How to solve react hydration error in Nextjs - Stack Overflow
in Nextjs react-hydration-error occurs when the SSR content not match in the browser or the the third party library altering the state in ......
Read more >The Perils of Rehydration - Josh W Comeau
When this value is true , the "real" content gets rendered. The difference from our earlier solution: useEffect only fires after the component ......
Read more >Rehydrating from Archives - Datadog Docs
Log Rehydration* enables you to capture log events from customer-owned storage-optimized archives back into Datadog's search-optimized Log Explorer, so that you ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m taking a look into this
Publishing a new release now 👍