pdf / vectyx

3 stars 2 forks source link

Link and LinkWithParam error #3

Open tbruyelle opened 6 years ago

tbruyelle commented 6 years ago
Uncaught Error: vecty: next child render must not equal previous child render 
(did the child Render illegally return a stored render variable?)

If I understood well Vecty doesn't let you return stored variable on Render, you have to return a new element on each call.

Because Link and LinkWithParam accepts a content for the anchor, this content is stored inside the struct and so causes the Vecty error.

One fix could be to not use a component but just a wrapper around the anchor :

func Link(path string, content vecty.ComponentOrHTML) vecty.ComponentOrHTML {
  return elem.Anchor(
    vecty.Markup(
      prop.Href(`javascript:;`),
      event.Click(onClick).PreventDefault().StopPropagation(),
    ),
    content,
  )
}
// The fix is not complete...

But it's sad to not be able to use a component here...

WDYT?

pdf commented 6 years ago

That panic may go away in vecty soonTM as there are a few reasons re-using HTML should be valid, though with a cursory search I can't find the exact discussion we had on that.

In the mean time, you can either use a component as content, or just avoid Link and use a regular element in your code, then hook event.Click to call router.Go to navigate.

I also have an inline router that I started work on that supports link interception, so that regular anchors can be used, and the router will intercept clicks and navigate by either pushState or hash routes, depending on the router config. The interception code should be extractable, but again, I'm afraid I'm really short on time right now.

tbruyelle commented 6 years ago

use a regular element in your code

That's what I did.

I also have an inline router that I started work on that supports link interception, so that regular anchors can be used, and the router will intercept clicks and navigate by either pushState or hash routes, depending on the router config.

This is neat. If it can help, as soon as #2 is merged I can submit an other PR on history/pushState support (see https://github.com/tbruyelle/vectyx/commit/4bb01923598871b289db3d9b2bf23a20d266280c)

But maybe that's something you already handle in your inline router.