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

Uncaught Error Thrown in Routed Elmish Applications #30

Closed
Johnnybu opened this issue Dec 28, 2019 · 5 comments
Closed

Uncaught Error Thrown in Routed Elmish Applications #30

Johnnybu opened this issue Dec 28, 2019 · 5 comments

Comments

@Johnnybu
Copy link

Johnnybu commented Dec 28, 2019

Description

The Fable-Compiler v2.4.12 update changed the way Substring works. It now throws an error.
The parseHash method relies on the JS substring behavior that returns an empty string when the index is greater than the input string length. This error prevents routed, browser-based Elmish apps from loading when a base URL is used for the first request.

Repro code

Line 352 of parser.fs:
let hash = location.hash.Substring 1

Throws this error:

Uncaught Error: Invalid startIndex and/or length
    at substring (webpack-internal:///./.fable/fable-library.2.4.12/String.js:935)
    at parseHash (webpack-internal:///./.fable/Fable.Elmish.Browser.3.0.2/parser.fs:313)
    at parser (webpack-internal:///./src/App.fs:178)
    at init (webpack-internal:///./.fable/Fable.Elmish.Browser.3.0.2/navigation.fs:142)
    at Elmish_Program.eval [as init] (webpack-internal:///./.fable/fable-library.2.4.12/Util.js:988)
    at traceInit (webpack-internal:///./.fable/Fable.Elmish.3.0.6/program.fs:90)
    at init (webpack-internal:///./.fable/Fable.Elmish.Debugger.3.0.3/debugger.fs:92)
    at eval (webpack-internal:///./.fable/fable-library.2.4.12/Util.js:988)
    at Elmish_Program.eval [as init] (webpack-internal:///./src/App.fs:379)
    at ProgramModule$$$runWith (webpack-internal:///./.fable/Fable.Elmish.3.0.6/program.fs:151)

When the application is accessed without a hash segment in the URL (e.g. the root url)

Expected and actual results

Application successfully loads without error when requested using the root URL

Related information

  • elmish version: 3.0.6
  • fable-compiler version: 2.4.12
  • fable-core version: 3.1.4
  • Operating system: Windows x64-10
@et1975
Copy link
Member

et1975 commented Dec 31, 2019 via email

@et1975
Copy link
Member

et1975 commented Dec 31, 2019 via email

@Johnnybu
Copy link
Author

Johnnybu commented Jan 3, 2020

Wow, that was fast! :)

Sorry I took so long to get back to this. Also, Happy New year!
I gave 3.0.3 a spin, and I can confirm parseHash now works for top-level url access. While I was at it, I took a look at the fix (curiosity), and noticed that parsePath may also be problematic - so I flipped my app over to that and got this:

Uncaught Error: Invalid startIndex and/or length
    at substring (webpack-internal:///./.fable/fable-library.2.4.12/String.js:935)
    at parseParams (webpack-internal:///./.fable/Fable.Elmish.Browser.3.0.3/parser.fs:299)
    at parsePath (webpack-internal:///./.fable/Fable.Elmish.Browser.3.0.3/parser.fs:309)
    at parser (webpack-internal:///./src/App.fs:180)
    at init (webpack-internal:///./.fable/Fable.Elmish.Browser.3.0.3/navigation.fs:142)
    at Elmish_Program.eval [as init] (webpack-internal:///./.fable/fable-library.2.4.12/Util.js:988)
    at traceInit (webpack-internal:///./.fable/Fable.Elmish.3.0.6/program.fs:90)
    at init (webpack-internal:///./.fable/Fable.Elmish.Debugger.3.0.3/debugger.fs:92)
    at eval (webpack-internal:///./.fable/fable-library.2.4.12/Util.js:988)
    at Elmish_Program.eval [as init] (webpack-internal:///./src/App.fs:381)

I wish I had got that in my initial report, but I am only using the hash parser right now, so I admittedly didn't think to try the path parser until now... :-\

@et1975
Copy link
Member

et1975 commented Jan 3, 2020 via email

@Johnnybu
Copy link
Author

Johnnybu commented Jan 3, 2020

That fixed it.

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