Framework for serverless Decentralized Applications using Ethereum, IPFS and other platforms https://framework.embarklabs.io/
Go to file
Michael Bradley, Jr a609035182 refactor(@cockpit): unregister the service worker
TL;DR
=====

Unregister (disable) the service worker in production builds of Cockpit. The
CRA dev server doesn't enable the service worker, so no changes are needed in
that context, i.e. `yarn start` in the monorepo.

**NOTE**: to effect these changes a user will need to load production Cockpit at
`localhost:55555` and then close all Cockpit tabs (or restart the
browser). This should be done for each browser that has been used to access
production Cockpit. See the *Step-by-Step* section below for more information.

Rationale
=========

There are a couple of factors:

* It's a bit confusing that after stopping `embark run` the production build of
  Cockpit is still accessible at `localhost:55555`. That's owing to CRA's
  [offline-first behavior][PWA] per the service worker it creates, which
  Cockpit [currently registers][current] (enables).

* It can be really confusing, if you don't know or forget about the service
  worker's behavior, that after a production rebuild of Cockpit the old build
  is still used in the browser, even after a page refresh. As [explained][ofb]
  in CRA's docs: *"users will end up seeing older content until they
  close (reloading is not enough) their existing, open tabs."* A similar effect
  is seen when switching between DApps, e.g. teller and embark_demo.

The CRA docs point to [some code][code] that could be adapted to an alert in
the UI prompting the user to close all tabs and reopen the app. That approach
definitely makes sense for DApps built with CRA that have opted-in to the
service worker. In fact, the service worker behavior would be critical in DApps
that make use of connected-/react-router because cold loads of routes that
don't actually correspond to static files couldn't otherwise work, i.e. if the
DApp is being served from ipfs/swarm.

But for Cockpit itself, when served from localhost with an express backend that
we control, little seems to be gained from offline-first behavior vs. a more
familiar behavior, i.e. when `embark run` isn't running then Cockpit isn't
accessible.

Step-by-Step
============

Flushing a site's service worker from cache can be tricky. The following steps
outline an approach to making sure the Cockpit in use is the one with service
worker disabled.

1. The first screenshot below shows the JavaScript console from a fresh load of
Cockpit with the service worker enabled, i.e. from a build on `master` at time
of writing and `embark run` running for the `embark_demo`. Note the messages
re: *"workbox"* and *"precaching"*.

![][step-1]

2. The next screenshot shows what happens when `embark run` is stopped and the
browser is refreshed. Service worker makes the page available offline, though
there are errors related to embark's API not being accessible.

![][step-2]

3. (a) Cockpit gets rebuilt on this PR's `refactor/cockpit-service-worker`
branch and `EMBARK_UI_STATIC=t embark run` is started; see [previous
commit][prevcom] re: `EMBARK_UI_STATIC`. (b) The browser is refreshed. Note the
message at the bottom re: *"New content is available"*.

![][step-3]

4. The Chrome browser is closed completely (command-Q), reopened and
`localhost:55555` is loaded again. Note there are *still* messages re:
*"workbox"* and *"precaching"*.

![][step-4]

5. The page is refreshed again and now the messages are completely gone.

![][step-5]

6. `embark run` is stopped and the page is reloaded, but there's a connection
error because no process is listening on `localhost:55555` — proof that
the service worker is no longer in play!

![][step-6]

Steps 3(b) to 6 will need to be repeated for each browser (Firefox, Safari,
etc.)  that visited `localhost:55555` when the service worker was enabled. And
they'll need to be repeated again if the browser is later used with a build of
Cockpit predating this PR.

[PWA]: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
[current]: 4d4704ac6f/packages/embark-ui/src/index.js (L39)
[ofb]: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app#offline-first-considerations
[code]: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/src/serviceWorker.js#L66-L93
[step-1]: https://user-images.githubusercontent.com/194260/54885199-adfa0900-4e47-11e9-830b-1b92816b2354.jpg
[step-2]: https://user-images.githubusercontent.com/194260/54885202-b3575380-4e47-11e9-9c1e-24817472d9c4.jpg
[step-3]: https://user-images.githubusercontent.com/194260/54885209-bb16f800-4e47-11e9-8e23-8fbc3b4f48fa.jpg
[prevcom]: https://github.com/embark-framework/embark/commit/322033cc
[step-4]: https://user-images.githubusercontent.com/194260/54885212-bfdbac00-4e47-11e9-9c8c-db90228d953a.jpg
[step-5]: https://user-images.githubusercontent.com/194260/54885214-c538f680-4e47-11e9-9963-58fd041675f0.jpg
[step-6]: https://user-images.githubusercontent.com/194260/54885217-ccf89b00-4e47-11e9-967a-7f8a523d4a92.jpg
2019-03-26 16:00:13 -04:00
.github chore: introduce issue and pull request templates 2018-11-07 17:31:17 +01:00
dapps chore(release): 4.0.0 2019-03-18 18:26:56 -05:00
packages refactor(@cockpit): unregister the service worker 2019-03-26 16:00:13 -04:00
scripts build: make DApp templates member packages of the monorepo 2019-03-05 10:20:57 -06:00
.editorconfig Add editor config 2018-10-22 19:25:16 +02:00
.eslintrc.json build: cleanup eslint configuration 2019-02-06 11:26:41 -06:00
.gitignore build: cleanup .gitignore 2019-02-05 18:08:14 -06:00
.npmrc build: introduce a `prepare` script in embark's package.json 2018-12-03 16:24:10 -06:00
.travis.yml build: make DApp templates member packages of the monorepo 2019-03-05 10:20:57 -06:00
.yarnrc build: specify a high network timeout in root .yarnc 2019-02-14 01:26:22 -06:00
CHANGELOG.md chore: ensure root CHANGELOG contains all previous releases 2019-03-19 21:03:46 +09:00
CODE_OF_CONDUCT.md chore(@embark) remove extra line 2018-12-24 16:14:01 -05:00
CONTRIBUTING.md docs(contributing): Update the syntax of the header and scope 2019-03-22 13:27:46 -04:00
LICENSE add license 2015-07-10 20:41:45 -04:00
README.md feature(embark): add coveralls integration 2019-02-08 17:07:05 -05:00
appveyor.yml build: make DApp templates member packages of the monorepo 2019-03-05 10:20:57 -06:00
babel.config.js build: implement a common babel config 2019-02-06 11:34:47 -05:00
header.png Update header 2018-09-27 10:23:03 -04:00
lerna.json chore(release): 4.0.0 2019-03-18 18:26:56 -05:00
package.json build: use package.json "files" instead of .npmignore 2019-03-12 07:50:25 -04:00
tsconfig.json fix(console): fix ENS tests not working with embark side by side 2019-03-08 08:54:30 -05:00
tslint.json refactor(@embark/embark-typings) move typings to its own module 2019-02-06 11:07:44 -05:00
yarn.lock refactor(@embark/api): catch-all route, fallback pages for Cockpit 2019-03-26 16:00:13 -04:00

README.md

Embark

npm Gitter Build Status Build status Open PRs Closed PRs GitHub commit activity the past week, 4 weeks, year Coverage Status

What is Embark

Embark is a framework that allows you to easily develop and deploy Decentralized Applications (DApps).

A Decentralized Application is a serverless html5 application that uses one or more decentralized technologies.

Embark currently integrates with EVM blockchains (Ethereum), Decentralized Storages (IPFS), and Decentralized communication platforms (Whisper and Orbit). Swarm is supported for deployment.

With Embark you can:

Blockchain (Ethereum)

  • Automatically deploy contracts and make them available in your JS code. Embark watches for changes, and if you update a contract, Embark will automatically redeploy the contracts (if needed) and the dapp.
  • Contracts are available in JS with Promises.
  • Do Test Driven Development with Contracts using Javascript.
  • Keep track of deployed contracts; deploy only when truly needed.
  • Manage different chains (e.g testnet, private net, livenet)
  • Easily manage complex systems of interdependent contracts.

Decentralized Storage (IPFS, Swarm)

  • Easily Store & Retrieve Data on the DApp through EmbarkJS. Including uploading and retrieving files.
  • Deploy the full application to IPFS or Swarm.
  • Import and deploy contracts hosted on Swarm.

Decentralized Communication (Whisper, Orbit)

  • Easily send/receive messages through channels in P2P through Whisper or Orbit.

Web Technologies

  • Integrate with any web technology including React, Foundation, etc..
  • Use any build pipeline or tool you wish, including grunt, gulp and webpack.
$ npm -g install embark

See Complete Documentation.