Comments (7)
Oh, wow, oops, sorry @shurcooL ! And thank you!
I tagged you but it seems I didn't fully understand the issue at hand. I had (very wrongly) thought that gopherjs run markdown.go
somehow left out another Go file like when using go run a.go
with b.go
in the same directory -- and that GopherJS somehow tried to 'best-effort' run it (I was surprised it got past compilation). I see now it was purely due to the runtime js
calls -- not due to missing Go code -- as you said.
I imagine to prevent users from running into this by accident I could add a panic if js.Global.Get("document") == undefined
, similar to what I've done in https://github.com/gopherjs/vecty/blob/master/gopherjs_only.go -- that might be better than just documenting the package as such.
from vecty.
We already do some environment checks such as https://github.com/gopherjs/vecty/blob/master/gopherjs_only.go so I don't think environment checks are bad. I've already proven they can work properly with unit tests, as well (haven't pushed this code yet, though). For sure, if/when we support server side rendering we'd have to relax the constraints.
I think this would be as simple as placing a check for document == null
(psuedocode) inside init
.
from vecty.
Try gopherjs serve
and then navigate to http://localhost:8080/github.com/gopherjs/vecty/examples/markdown/
Does that work? (I presume gopherjs run
is like go run
and hence doesn't do what you expect -- it runs only that one file without dependencies or something..)
from vecty.
Awesome. That worked. Thanks for speedy response.
from vecty.
@hemantasapkota awesome :)
@shurcooL would you expect gopherjs to provide a better error message here? or no? I can file an issue if so
from vecty.
What would be a better error?
The error happens on this line:
js.Global.Get("document").Set("title", title)
node's global object doesn't have document
and returns undefined
. Setting title
on undefined
causes:
TypeError: Cannot set property 'title' of undefined
It looks like the problem here was a misunderstanding of environments where a Go program compiled to JavaScript can run. That Go package was meant to be run inside of a browser, not in the terminal via node. I usually document such packages to say that.
from vecty.
This particular error occurred on SetTitle
, but not everyone will call this function when they're getting started. They might jump straight to RenderBody
, or the planned RenderInto
, etc.
Package-level init
is one place to do this, perhaps the only place. Alternatively, you might have some kind of new function, vecty.BrowserInit
, but then everyone would need to call this.
FWIW, I might caution against adding environment checks like this in vecty. If you have a goal to be able to run unit tests against vecty code in a non-browser environment, or do server side rendering, it may not be possible to do these kinds of environment checks in a way that works for every use case, existing or planned.
from vecty.
Related Issues (20)
- Add a basic example on usage HOT 5
- allow global panic handler HOT 2
- removeChild crashes if parent node is nil HOT 1
- [feature request] static HTML/CSS components HOT 6
- Examples go.mod file conflict HOT 1
- Add snake videogame example. HOT 4
- question: What is this prop vs. state idea HOT 3
- Instrumenting panic messages HOT 8
- question: initializing rendered HTML nodes via javascript HOT 4
- Porting gopherjs js calls to use with vecty HOT 2
- Document the availability of vecty project template generator HOT 1
- Return type of If function
- prop.Value("") does not produce the correct html on first render
- Vecty needs an official website HOT 10
- The slack invite link in readme is broken
- vecty docs HOT 1
- How to update a rendered element? HOT 10
- Failed Running The Example HOT 8
- Todo MVC example has misleading usage of p.Items HOT 2
- Rerendering List Replaces First ListItem HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vecty.