I am doing my first Custom Web Component. All went well until the component registration (during the build). During the actual service, the
Composite.register("nheader", {
view: view,
viewModel: viewModel,
metadata: JSON.parse(metadata)
});
call in the loader.ts failed with a JSON parse error:
Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
I tried modifying the above code with the following:
Composite.register("nheader", {
view: view,
viewModel: viewModel,
metadata: JSON.parse(JSON.stringify(metadata))
});
Now the error is gone and the page gets served without issues. Most possibly a scripting engine issue. I am using the Firefox Dev edition.
I see some changes in the component generation and documentation:
Please rename the metadata import as rawmetadata (for clarity) in the loader.ts
Please consider the stringification done as above, so that code works on all browsers. Or my understanding could be corrected. Please comment.
The component registration (along with its version) both as a standalone or as part of a pack happens automatically at build time. Can this fact be added to the CCA documentation please? There seems to be some disconnect here because I spent two days understanding how this wiring happens. Perhaps here?