Sitecore JSS: Development Modes

Featured image

Sitecore JSS is the new way of developing in and with Sitecore. The quickstart is pretty straightforward when it comes to the disconnected mode. This blog also focuses on the Code-First workflow and the Sitecore-First workflow.

Sitecore JSS: modes

When you want to start developing in Sitecore JSS you can choose beween four flavours. For only one of them Sitecore isn't required.

Setting up the connection

The JSS CLI is a great tool which takes a lot of work out of your hands like: setting up, running modes and deploying your app in several ways. After creating your app with jss create [appname] [app type] you have to set up the connection information. This can be done manually but it's easier to do it this way. Running jss setup will ask you some questions and generates the scjssconfig.json file which will be used for the connection to your Sitecore instance.

After creating this file make sure to check your configuration to see if there are no typo's and stuff ;-) Next, you deploy the configuration to Sitecore. Using the jss deploy config command two Sitecore configuration files will be added to the /App_Config/Include/zzz folder: a file with a secret token for deployment and the site configuration plus the GraphQl endpoint config. When you do not have a local instance of Sitecore you can always change the value of the instancePath in your scjssconfig.json file, point to a local folder and copy it afterwards to your Sitecore instance. You can also change the location where the files are copied changing the package.json property sitecoreConfigPath to something else.

Sitecore JSS Deployment

Now that we've configured the connections and deployed our configuration we can deploy our app. Before doing so you have to do some configuration in Sitecore to prepare usage and deployment of your app. There are some options to choose  from using the command jss deploy:

Sitecore JSS: connected mode

Now that you have deployed your app and also have some content imported it's time to kick off the development server in connected mode. Run the jss start:connected command, some magic happens in the console and suddenly your default browser opens a webpage pointing to your dev server on port 3000.

Not really what you expected but do not be alarmed! The 404 is normal behaviour. Let me explain why. I check the network tab to see what happens:

As you can see the call was executed which means we have a connection and we got data back. But it looks like somethin's missing and a quick check points to the workflow state of the item:

So I changed the workflow state of the item to published, refreshed the page of my dev server and this time I get an error saying that fields is undefined. Ugh!

The inspector (network tab / Response) shows me more data. I now can see Sitecore context data and route information. Also the main placeholder with my components (About and ContentBlock) is available.

As you can see we do not see the field values of the components. Reason for this is that they are also in the Development Mode workflow state.

Changing the states to Published gave me the result I needed. Also in the Published state I now can change content in the Content Editor. Changes will be visible in my development environment after I hit F5.

Sitecore JSS:  Development Workflow states

The JSS import process is designed to gracefully skip items to which the configured import user does not have write permission. This allows you to utilize Sitecore Security to prevent the import from overwriting content which should no longer be "developer-owned."
To further facilitate this, JSS includes a content workflow which is automatically applied to all generated templates. This workflow defines Development Mode and Content Mode states to designate the current "ownership" of a content item.

Notice that when publishing Sitecore content it is automatically  put into the Development Mode workflow state.
Items can be set in one of the three states: