magento / pwa-studio

🛠Development tools to build, optimize and deploy Progressive Web Applications for Magento 2.
https://developer.adobe.com/commerce/pwa-studio/
Open Software License 3.0
1.07k stars 683 forks source link

[bug]: Workaround for react ssr #2650

Closed amaankulshreshtha closed 3 years ago

amaankulshreshtha commented 4 years ago

Is there a workaround to adding react as a templating engine?

In my server.js file, I have the following code:

const { createUpwardServer } = require('@magento/upward-js');

createUpwardServer({
    upwardPath: 'spec.yml',
    bindLocal: true,
    logUrl: true,
    port: 8080,
    before: (app) => {
        app.set('view engine', 'jsx')
        app.engine('jsx', require('express-react-views').createEngine());
        console.log(app);
    }
});

And in the spec file i have the following code

 body:
          resolver: template
          engine:
              resolver: inline
              inline: 'jsx'
          template:
            resolver: file
            file:
              resolver: inline
              inline: './templates/hello-world.jsx'
          provide:
              title:
                  resolver: inline
                  inline: 'This is the page title'

Yet I am facing TemplateResolver issue

Error: Template engine 'jsx' unsupported

Can you tell me what is it that I am missing here as well

PS: I already went through this part of the readme and it didn't help

Please let us know what packages this bug is in regards to:

m2-assistant[bot] commented 4 years ago

Hi @AmaanKulshreshtha. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.

Please, add a comment to assign the issue: @magento I am working on this


sirugh commented 4 years ago

Is jsx a valid template engine?

https://github.com/expressjs/express/wiki#template-engines

amaankulshreshtha commented 4 years ago

I installed express-react-views, and got the jsx template engine from there

amaankulshreshtha commented 4 years ago

any updates on this?

sirugh commented 4 years ago

Have you tried asking in the slack channel? You may find help there :)

amaankulshreshtha commented 4 years ago

I actually did, but no luck there as well...

evan-burrell commented 4 years ago

The engine that its referring to I believe comes from https://github.com/magento/pwa-studio/blob/develop/packages/upward-js/lib/resolvers/TemplateResolver.js#L6, where mustache is the only resolve supported by upward out of the box

amaankulshreshtha commented 4 years ago

I am trying to add react as a templating engine, by creating ReactTemplate.js inside https://github.com/magento/pwa-studio/tree/develop/packages/upward-js/lib/compiledResources. Feel free to float any ideas regarding the implementation as well 😄

sirugh commented 3 years ago

Closing as Stale