Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMR results in duplicate elements #4

Open
svicalifornia opened this issue Nov 26, 2018 · 1 comment
Open

HMR results in duplicate elements #4

svicalifornia opened this issue Nov 26, 2018 · 1 comment
Assignees

Comments

@svicalifornia
Copy link

Steps to reproduce:

  1. Clone repo from current master branch commit
  2. yarn and npm start
  3. Edit src/App.tsx
  4. Cut line 13 (Logo element) and save file
  5. Observe that logo disappears in browser
  6. Paste to restore Logo element back at line 13 and save file
  7. Observe duplicate logo elements in browser

screen shot 2018-11-26 at 5 33 29 am

(Strangely, after saving the file a third time, the duplicate logos disappear, and the app looks right again.)

@joseluisq
Copy link
Owner

According to this thread the code below works for me:

main.tsx

import { app } from 'hyperapp'
import { actions, state, view } from '@app/app'
import moisturize from 'hyperapp-moisturize'

function makeHotReloader (updateApp) {
  return (fileName, updateAs) => {
    return module.hot.accept(`./${fileName}`, () => {
      import(`./${fileName}?${Date.now()}`)
        .then((imported) => {
          updateApp({
            [updateAs]: imported.default
          })
        })
    })
  }
}

const main = moisturize(app)(state, actions, view, document.body)
const hotReloader = makeHotReloader(main.updateApp)

hotReloader('state.js', 'newState')
hotReloader('actions.js', 'newActions')
hotReloader('view.js', 'newView')

Example taken from okwolf/srvs

@joseluisq joseluisq self-assigned this Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants