Code Monkey home page Code Monkey logo

elm-msg-bug's Introduction

Elm Msg mapping issue

A basic multi-page SPA app SSCCE

What's happening here?

I think Elm is mapping a Msg from the Home page into the Settings page.
The compiler would recognize this as invalid, but the Elm runtime is allowing this.

Something very relevant here: This is only reproducable in Chrome due to how the focusout event is fired off once the DOM element is removed. Other browsers do not behave this way. preventDefaultOn "mousedown" is very important as this prevents the textfield from losing focus when mousedown hits the "Go to Settings" link.

Here is what I think the flow is:

  1. Focusing input element causes Note.Msg (EditorFocused True).
  2. Mousedown on "Go to Settings" link causes Note.Msg NoOp to fire. Input still has focus.
  3. Mouseup on link causes the page to change to /settings.
  4. The input is removed from the DOM on page change and the focusout event is fired (only in Chrome).
  5. EditorFocused False is fired but caught by Settings.Msg
  6. The settings update function does not recognize the EditorFocused Msg, but the way the Elm compiler generates the final match in a case statements results in the Msg being caught in the default case, aka TheDefaultCase { wat : { hereIsAnElmException : Int } }
  7. The code attempts to access constructorValue.wat.hereIsAnElmException. constructorValue is actually a Boolean off of EditorFocused so an exception is thrown.

image

Note: If you disable the offending code in Settings under Msg.TheDefaultCase, you an invalid Msg type propagating to Settings.update Screen Shot 2021-05-26 at 1.28.36 PMimage

Run

  1. Install deps and start dev server
yarn install
yarn dev
  1. Open http://localhost:1234 in Chrome
  2. Click into textfield.
  3. Click "Go to Settings" link.
  4. Look at console for the exception.

elm-msg-bug's People

Contributors

cmditch avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.