marko-js-archive / marko-widgets

[LEGACY] Module to support binding of behavior to rendered UI components rendered on the server or client
http://v3.markojs.com/docs/marko-widgets/
MIT License
141 stars 40 forks source link

Duplicate widget ID when manually initializing server side rendered widgets #40

Open onemrkarthik opened 9 years ago

onemrkarthik commented 9 years ago

Hello, Was trying out manually initializing server side rendered widgets (https://github.com/raptorjs/marko-widgets#manually-initializing-server-side-rendered-widgets) and have run into an issue.

Say there exists a parent widget. <div w-bind="./parent_widget"></div>

The above widget would get an ID "w0".

Now, if parent_widget makes an ajax call that renders a child_widget on the server side and we manually try to initialize the widget on the browser with:

require('marko-widgets').initWidgets(widgetIds), the child widget fails to get initialized because the child_widget also comes back with the same ID 'w0'.

I put a break point on the initWidgets function and noticed that the child widget also comes back with widget id "w0" (same as the parent widget). Ideally, the client_widget should have come back with "w1".

Was wondering if i am missing something ?

Regards, Karthik

maberer commented 9 years ago

This "problem" has been reported before and @patrick-steele-idem already proposed a fix. Thanks for pointing it out.

Please see: https://github.com/raptorjs/marko-widgets/issues/16

onemrkarthik commented 9 years ago

AAh. Thank you for pointing it out.

Will looking into it.

Karthik

patrick-steele-idem commented 9 years ago

What @tindli pointed out should solve your problem. The Marko Widgets server code is stateless so it doesn't know how to generate unique widget IDs for a given client if additional widgets are being rendered on the server after the initial page rendering. Therefore, it is up to your app code to tell Marko Widgets what to use as the starting widget ID to keep widget IDs unique. This needs to be moved into the docs since it has come up a few times for teams that want to do all of the rendering on the server. I'll keep this issue as a reminder to update the docs.

maberer commented 9 years ago

:+1: for moving it into the docs. thanks

onemrkarthik commented 9 years ago

Awesome. Thanks guys :)