saberland/saber

Do you want to work on this issue?

You can request for a bounty in order to promote it!

Display a compiling indicator in browser #442

egoist posted onGitHub

<!-- Please don't delete this template or we'll close your issue -->

<!-- Before creating an issue please make sure you are using the latest version of Saber. -->

Feature request

<!-- Please ask questions via following several ways. -->

<!-- https://chat.saber.land/ -->

<!-- https://stackoverflow.com/questions/ask?tags=saberjs -->

What problem does this feature solve?

Rebuilding can be slow, it's frustrating when you edit something but the page doesn't update right away, we can provide a better experience by adding an indicator to show the build progress.

In Next.js:

next.js

In Nuxt.js:

nuxt

What does the proposed API look like?

This should be on by default, but you should be able to turn it off by build: { browserIndicator: false } or CLI flag --no-browser-indicator

How should this be implemented in your opinion?

Hook into webpack compiler and send progress info to browser via webpack-hot-middleware.


No need to send progress data if we do it in Next.js style the following code will do the job

mounted () {
    this.isVisible = false
    this.isBuilding = false
    this.timeoutId = null
    this.sse = new window.EventSource('/__webpack_hmr')
    this.sse.addEventListener('message', event => this.onSseMessage(event))
  },
  methods: {
    onSseMessage (event) {
      // This is the heartbeat event
      if (event.data === '\uD83D\uDC93') {
        return
      }

      try {
        const obj = JSON.parse(event.data)
        switch (obj.action) {
          case 'building':
            this.timeoutId && clearTimeout(this.timeoutId)
            this.isVisible = true
            this.isBuilding = true
            break
          case 'built':
            this.isBuilding = false
            // Wait for the fade out transtion to complete
            this.timeoutId = setTimeout(() => {
              this.isVisible = false
            }, 100)
            break
        }
      } catch {}
    }
  }

What do you say @egoist should I do it in this way?

posted by MarchWorks over 5 years ago

@issuehunt has funded $40.00 to this issue.


posted by issuehunt-app[bot] over 5 years ago
posted by egoist over 5 years ago

@egoist got it but if I do that how I am supposed to pass the isBuilding variable to the component? or should I use a pure js solution document.createElement ...........?

posted by MarchWorks over 5 years ago

@MarchWorks It's a simple component so document.createElement is probably enough for this.

posted by egoist over 5 years ago

I decided to use a "command seal" I will use this one gilgamesh-command-spell

posted by MarchWorks over 5 years ago

still needs some tweaks https://jsfiddle.net/3h8vayjs/2/

posted by MarchWorks over 5 years ago

Interesting, is there an animated version? 😄

posted by egoist over 5 years ago

Not yet but I am thinking of animating it like when a "command" is used

posted by MarchWorks over 5 years ago

Fund this Issue

$40.00
Funded
Only logged in users can fund an issue

Pull requests

Recent activities

issuehunt funded 40.00 for saberland/saber# 442
over 5 years ago