0

I was under the impression that when viewing a sitecore site locally it would render on the client if not being viewed in the experience editor. I'm trying to read/write from a cookie in one of my components and I'm getting the following exception. Any thoughts?

Component function:

    createUserInfo(props) {
        let userInfo;
        if (!props.sitecoreContext.pageEditing) {
            if (!document.cookie.includes('Id')) {
                let href = window.location.href;
                const url = this.parseUrl(href);
                this.createCookie(url);
                userInfo = this.getUserInfoFromCookie()
            } else {
                userInfo = this.getUserInfoFromCookie()
            }
        } else {
            userInfo = {
                Id: `Dynamic Content`,
                email: `Dynamic Content`,
            }
        }

        this.setState({userInfo: userInfo})
    };

Log:

2448 12:13:55 ERROR Failed to render rendering
Exception: Sitecore.JavaScriptServices.ViewEngine.NodeServices.HostingModels.NodeInvocationException
Message: document is not defined
ReferenceError: document is not defined
    at _class.createUserInfo (C:\inetpub\wwwroot\pub.grange.local\dist\grange-agent-scanner-jss\server.bundle.js:50013:13)
    at _class.componentWillMount (C:\inetpub\wwwroot\pub.grange.local\dist\grange-agent-scanner-jss\server.bundle.js:49999:16)
    at c (C:\inetpub\wwwroot\pub.grange.local\dist\grange-agent-scanner-jss\server.bundle.js:18698:337)
    at Ga (C:\inetpub\wwwroot\pub.grange.local\dist\grange-agent-scanner-jss\server.bundle.js:18700:1)
    at a.render (C:\inetpub\wwwroot\pub.grange.local\dist\grange-agent-scanner-jss\server.bundle.js:18705:367)
    at a.read (C:\inetpub\wwwroot\pub.grange.local\dist\grange-agent-scanner-jss\server.bundle.js:18704:450)
    at renderToString (C:\inetpub\wwwroot\pub.grange.local\dist\grange-agent-scanner-jss\server.bundle.js:18716:82)
    at process (C:\inetpub\wwwroot\pub.grange.local\dist\grange-agent-scanner-jss\server.bundle.js:37965:20)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
Source: Sitecore.JavaScriptServices.ViewEngine.NodeServices
   at Sitecore.JavaScriptServices.ViewEngine.NodeServices.HostingModels.Http.HttpNodeInstance.InvokeExport[T](NodeInvocationInfo invocationInfo)
   at Sitecore.JavaScriptServices.ViewEngine.NodeServices.HostingModels.OutOfProcessNodeInstance.InvokeExport[T](String moduleName, String exportNameOrNull, Object[] args)
   at Sitecore.JavaScriptServices.ViewEngine.NodeServices.DefaultNodeServices.InvokeExportWithPossibleRetry[T](String moduleName, String exportedFunctionName, Object[] args, Boolean allowRetry)
   at Sitecore.JavaScriptServices.ViewEngine.NodeServices.DefaultNodeServices.InvokeExport[T](String moduleName, String exportedFunctionName, Object[] args)
   at Sitecore.JavaScriptServices.ViewEngine.Node.NodeRenderEngine.Invoke[T](String moduleName, String functionName, Object[] functionArgs)
   at Sitecore.JavaScriptServices.ViewEngine.Presentation.JssRenderer.PerformRender(TextWriter writer, IRenderEngine renderEngine, String moduleName, String functionName, Object[] functionArgs)
   at Sitecore.JavaScriptServices.ViewEngine.Presentation.JssRenderer.Render(TextWriter writer)
   at Sitecore.Mvc.Pipelines.Resp
  • The first request is always server side rendered. Any subsequent request are SPA and render client side. This allows search engines to crawl the site, for example. – jammykam Sep 16 at 17:27
  • @jammykam, how can I know its the first request? Is it in the sitecoreContext? Also, any idea where that is in the documentation? I'm trying to find it but with little success, atm. – Jonny B Sep 16 at 17:38
  • NM, found it. jss.sitecore.com/docs/fundamentals/architecture. – Jonny B Sep 16 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.