elm-community / elm-time

A pure Elm date and time library.

Home Page:http://package.elm-lang.org/packages/elm-community/elm-time/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Time.TimeZones import unusable from elm-reactor v0.18.0

jm4games opened this issue · comments

Hi,
I'm running into an issue with importing Time.TimeZones within any elm module after the upgrade from elm v0.17.1 to v0.18.0. Basically if I import the module and not even use it, the elm project will compile. But if I try to run the project in elm-reactor and access the page from Chrome, I will see the following error:
"Uncaught RangeError: Maximum call stack size exceeded"

I have a minimal repro for this issue:
`
import Html exposing (..)

import Time.TimeZones

type alias Model = {}
type Msg = Msg2

main : Program Never Model Msg
main = beginnerProgram
{ model = {}
, update = \a b -> b
, view = _ -> div [] [h1 [] [text "Hello World"]]
}
`

Package imports are:

  • "Bogdanp/elm-time": "1.4.0 <= v < 2.0.0",
  • "elm-lang/core": "5.0.0 <= v < 6.0.0",
  • "elm-lang/html": "2.0.0 <= v < 3.0.0"

This is not an issue in 0.17.1.

Thanks!

I am having the same problem, but not in elm-rector but in regular app use. Once I add this line to any of the files:
import Time.TimeZones
the application won't load and browser will report: Uncaught RangeError: Maximum call stack size exceeded without specifying the source of the problem.

This basically means I am not able to use the ZonedDateTime as I cannot create an instance without Time.TimeZones.???… :(

OK, so I've found a workaround: replace
"elm-community/elm-time": "1.0.1 <= v < 2.0.0"
to this:
"Bogdanp/elm-time": "1.3.0 <= v < 1.4.0"

The 1.3.0 version of Bogdanp/elm-time is the last release which does not crash browser when using Time.TimeZones.

@witoldsz, @jm4games thanks, I'll take a look at this.

@jm4games, I modified your script above and was able to get it to run w/o the stack overflow problem.

Here are all my files:

Main.elm:

import Html exposing(Html, h1, text, div)

-- Following import works for me in this program:
import Time.TimeZones

type alias Model = {}
type Msg = Msg2

main = Html.beginnerProgram
    { model = {}
    , update = \a b -> b
    , view = render
    }

render m =
    div [] [h1 [] [text "Hello World"]]

elm-package.json:

{
    "version": "1.0.0",
    "summary": "Work out issue 13",
    "repository": "https://github.com/user/project.git",
    "license": "BSD3",
    "source-directories": [
        "."
    ],
    "exposed-modules": [],
    "dependencies": {
        "elm-community/elm-time": "1.0.1 <= v < 2.0.0",
        "elm-lang/core": "5.1.1 <= v < 6.0.0",
        "elm-lang/html": "2.0.0 <= v < 3.0.0"
    },
    "elm-version": "0.18.0 <= v < 0.19.0"
}

When I elm reactor the above and browse it, I see "Hello World" render in the appropriate style. You can see it run in Ellie.

Could you attach an Elm file that shows this problem?

@witoldsz Could you attach a small Elm program and related elm-package.json that demonstrates the problem?

No problem. All you need is an import statement and application crashes.

Done. Here you are: https://ellie-app.com/qwD8mkg9TTa1/0
Compile an see it works, then uncomment the import statement and see it crashes.

@oldfartdeveloper Now I can see the problem. When I run Ellie example of yours or mine, I can see it works on Chrome and Firefox. When I run it using Chromium (my default browser on the system at home), it crashes. There must be something wrong in that Chromium? Or maybe it's because my Chromium's version is little bit older compared to Chrome? I was sure it was crashing on Firefox, now I can see it works there, maybe it's because of an upgrade? Let me check some older version I use for end-to-end Selenium tests…

So, it works on:

  • Google Chrome Version 56.0.2924.87 (64-bit)
  • Firefox 51.0.1 (64-bit) Mozilla Firefox For Ubuntu
  • Firefox ESR 45.4.0

It does not work on:

  • Chromium Version 55.0.2883.87 Built on Ubuntu, running on Ubuntu 16.04 (64-bit)

All this crashed only on Chromium as of now… That's strange.
Or… maybe it's because I have many apps launched in Chromium and other browsers I have tested now do nothing but Ellie?

Bingo! In another instance of Chromium (private mode) with nothing but Ellie it also works…

Looking at the source code, I can see there are about 600 time zones passed to Dict.fromList. It looks like Dict.fromList is recursive function: https://github.com/elm-lang/core/blob/5.1.1/src/List.elm#L155

@witoldsz: Cool, thanks for sleuthing this out. I suppose it would be useful to provide a nicer diagnostic, or at least add documentation warning about this behavior if the browser involved is running short of resources.

Timezones are a conundrum for libraries. Everything else about managing time is easy; it's easy to forget how much "knowledge" is involved for managing timezones.

I think this is a serious issue with core library. Dict.fromList should not cause such a headache. I would escalate it to https://github.com/elm-lang/core.

I can confirm this running on google chrome (56.0.2924.87 (64-bit)) as well, using ellie. It still crashes when I run locally though.

So I might take a closer look at this myself if I can get some time today. I would find it strange that the recursive call is causing this issue. We are only talking like 600 elements, thats not too large of a stack. I suspect there is something deeper going on, possibly a combination of how insert works on dictionary, with a foldl?

So a workaround for this could be to possibly break the dictionary into smaller pieces (IE a data structure of smaller data structures containing time zones).

List literal with many items leads to "Maximum call stack size exceeded"
elm-lang/core#840
"Maximum call stack size exceeded" with large List #1521
elm/compiler/issues/1521

I think your approach to work around this problem is worthwhile until the Dict is fixed. Hence, merged your PR and am closing this issue. Thanks for your contribution; much appreciated.

I bumped the elm-community version to 1.0.2