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

Component parameters are ignored when doing backend-rendering with oc-client nodejs library #431

Closed
gtrias opened this issue Apr 3, 2017 · 7 comments
Assignees
Labels

Comments

@gtrias
Copy link
Member

gtrias commented Apr 3, 2017

I'm trying to send parameters to component in order to perform the backend rendering. Given the next component array:

[{"name":"some-component","parameters":{"apikey":"1234abcd"}}]

The component is rendered but not receiving the parameter apikey. By the other hand if I request the component using curl and passing the parameter as a querystring the widget is taking it properly.
Am I missing anything?

oc-client version: ^2.1.6
oc registry version: 0.36.15

My current implementation is the next:

Component server.js:

module.exports.data = function (context, callback) {
  callback(null, {
    staticPath: context.staticPath,
    params: context.params
  });
};

template.html

{{params.apikey}}

Server side rendering:

var Client = require('oc-client');

var client = new Client({
    registries: {
        serverRendering: 'http://myregistry.server',
        clientRendering: 'http://myregistry.public.server'
    }
});

var renderComponents = function (components, callback) {
  client.renderComponents(components, {}, function(err, html){
    if (err) {
      return callback(err);
    }

    callback(null, html);
  });
};
@matteofigus
Copy link
Member

matteofigus commented Apr 3, 2017

All seems correct on a first look.

What's the output of html? Can you console.log that and see what contains?

@gtrias
Copy link
Member Author

gtrias commented Apr 3, 2017

Given the next template:

<div id="widget-selector"></div>
<script src="{{staticPath}}build/static/js/main.js"></script>
<script>
  // Instantiating widget, passing the selector where
  // you want to render it, and som parameters to configure it
  Instance = SomeWidget.default.widget.new({
    selector: "#some-selector",
    apikey: '{{params.apikey}}'
  });
  Instance.render();
</script>

The otuput of server-rendering is (changing sensitive values):

<div id="widget-selector"></div>
<script src="//s3-eu-west-1.amazonaws.com/xxxxxxxx/components/xxxx-xxxxx/0.5.0/build/static/js/main.js"></script>
<script>
  // Instantiating widget, passing the selector where
  // you want to render it, and some parameters to configure it
  Instance = SomeComponent.default.widget.new({
    selector: "#widget-selector",
    apikey: ''
  });
  Instance.render();
</script>
<script>window.oc=window.oc||{};oc.renderedComponents=oc.renderedComponents||{};oc.renderedComponents["some-component"]="0.5.0";</script>

And using curl with querystring:

<oc-component href=\"https://xxxxxx/some-component?apikey=1234\" data-hash=\"97c8daed7d56f05aa163e0d67356c50c5631227b\" data-name=\"some-component\" data-rendered=\"true\" data-version=\"0.5.0\"><div id=\"widget-selector\"></div>\n<script src=\"//s3-eu-west-1.amazonaws.com/xxxxxxxx/components/some-component/0.5.0/build/static/js/main.js\"></script>\n<script>\n  // Instantiating widget, passing the selector where\n  // you want to render it, and som parameters to configure it\n  Instance = SomeCompnent.default.widget.new({\n    selector: \"#some-component\",\n    apikey: '1234'\n  });\n  Instance.render();\n</script>\n<script>window.oc=window.oc||{};oc.renderedComponents=oc.renderedComponents||{};oc.renderedComponents[\"some-component\"]=\"0.5.0\";</script></oc-component>

@mattiaerre
Copy link
Member

@gtrias try to add also { name: 'oc-client' } to your component's collection; the renderComponents method works well if you have more than one component to render; see if that fixes your issue.
happy to jump on Gitter if you need further assistance.

// cc @matteofigus

@matteofigus
Copy link
Member

Definitely looks like a bug.

@gtrias
Copy link
Member Author

gtrias commented Apr 3, 2017

@mattiaerre Adding oc-client to the components collections did the trick!! Now it works as expected :)
Tried to combine with other component but oc-client works as well. So it seems renderComponents doesn't support only one component...
Btw I'm loading components from a database and the components collection number depends on external configuration, so can be 1 or more.

@matteofigus
Copy link
Member

From what I see here, it may be related to #347

@mattiaerre
Copy link
Member

@gtrias it is even more than that tbf. If there is one component w/ parameters the output is empty. If there is one component w/o parameters it works. as per @matteofigus note, we will look into this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants