Glitching in a Material World
Tags: javascript, node, frontend
Published: 2020-05-11 16:32:51

---
title: Glitching in a Material World
published: true
description: How the Material Design team uses Glitch and how we collaboratively built one tricky feature.
tags: javascript, node, frontend
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/0htkyh8o03hc7txtq399.png
---

{% youtube 15HpQBvvHS8 %}

Last fall, I was fortunate to be able to attend the Chrome Developer Summit in San Francisco. In addition to all the sessions, there was a demo and exhibition floor showing off all sorts of web tech. The [Material Design team](https://material.io/) was there, showing off a booth where attendees could snap a photo of themselves and use the colors from the image to customize their own version of the Material Design theme. It was a great example of a [live demo](https://glitch.com/~material-theme-generator?utm_medium=weblink&utm_source=dev.to&utm_campaign=blog&utm_content=dev) that draws people in and leaves them with a digital souvenir that they'll want to tinker with later. Of course, I was also excited to see that it was powered by [Glitch](https://glitch.com?utm_medium=weblink&utm_source=dev.to&utm_campaign=blog&utm_content=dev)!

{% glitch material-theme-generator app %}

I'm consistently impressed with how the Material Design team has embraced and pushed the capabilities of Glitch on [their team page](http://glitch.com/@material?utm_medium=weblink&utm_source=dev.to&utm_campaign=blog&utm_content=dev "Material Design on Glitch"), so I was thrilled to help them figure out how to make one small aspect of their theme generator work.

The challenge was this&mdash;let a booth visitor tweak the settings to see what the design system can do, and then "save" their changes to their own copy so they can get back to it later and keep playing! We could save a user's changes to the project filesystem, but then multiple users would be overwriting each other at the booth. The solution takes advantage of the ability to send custom environment variables to a project remix when it's created.

For example, if you wanted to remix `hello-express` and set the environment variable SECRET when making a remix, you can go to the following URL:

```
https://glitch.com/edit/#!/remix/hello-express?SECRET=message
```

Once the remix is finished, you'll have your own copy of `hello-express`. In it will be a secrets file called `.env`, and in that will be a line `SECRET=message`. Variables in that file are available as environment variables, so you can access them from the server's code, e.g. `process.env.SECRET` in Node.js.

The material design team wanted to send a larger payload, with all the customized component styles. It's not a great idea to put a large amount of data in a URL as browsers will handle it differently, and many will cut it off after a certain size. The solution was to instead temporarily store the customized styles in the server of the app, and then let the remix fetch them when it first loads.

So when the user hits "Remix to Save Theme", it sends the custom styles to the app's server, and is given a unique ID number. We pass the unique ID to the remix, and when the remix first starts up it messages our app "hey, do you have any data for me?" and we can send back the larger data. Once the remix has the data, we can delete it.

The whole flow looks something like this (in glorious ascii):

![An ASCII-art diagram depicting the data transfer flow described above](https://dev-to-uploads.s3.amazonaws.com/i/5497z4nbwzrumou9k1w2.png)

If you'd like to experiment with the flow yourself, you can try out this simplified demo:

{% glitch data-provider-example app %}

Please check out the [Material Design Team on Glitch](http://glitch.com/@material?utm_medium=weblink&utm_source=dev.to&utm_campaign=blog&utm_content=dev) and leave a comment if you build anything using their fantastic resources!

_[Give your Glitch apps superpowers - keep them awake, lift rate limits, and get more memory and disk space.](https://glitch.com/pricing?utm_medium=weblink&utm_source=dev.to&utm_campaign=handbook&utm_content=dev)_