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

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

Open
onemrkarthik opened this issue May 26, 2015 · 5 comments

Comments

@onemrkarthik
Copy link

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
Copy link
Contributor

maberer commented May 26, 2015

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

Please see: #16

@onemrkarthik
Copy link
Author

AAh. Thank you for pointing it out.

Will looking into it.

Karthik

@patrick-steele-idem
Copy link
Contributor

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
Copy link
Contributor

maberer commented May 26, 2015

👍 for moving it into the docs. thanks

@onemrkarthik
Copy link
Author

Awesome. Thanks guys :)

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

3 participants