SalesforceCommerceCloud / pwa-kit

React-based JavaScript frontend framework to create a progressive web app (PWA) storefront for Salesforce B2C Commerce.
https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/pwa-kit-overview.html
BSD 3-Clause "New" or "Revised" License
283 stars 131 forks source link

[FEATURE] Add build process for CSR only for use in hybrid apps #420

Open nx-andreashabermann opened 2 years ago

nx-andreashabermann commented 2 years ago

Is your feature request related to a problem? Please describe. PWA kit is currently designed to be used with SRR, which is good for website scenarios, but leads to some problems when you want to use it in hybrid app as with Cordova.

Describe the solution you'd like A second way to build pwa kit so both client and server js get complied for CSR only use (with an index.html file that can be used as starting point for hybrid app). Main problem is the reliance on server side rendered data to be always present in the current setup. Best would be to have the basic implementation for CSR in SDK and based on this a working example in PWA. It should be possible to switch between SSR and CSR builds by configuration. The solution should not be a complete hybrid app setup, including the example pwa into a wrapper like cordova could be a readme example.

Describe alternatives you've considered Create native app version using ReactNative

Additional context I created a prove of concept that PWA kit can be adjusted to render on client side only using an index.html file as starting point. This POC uses PWA as base without adjusting the SDK, calls to SDK code sometimes need to overriden by custom code. Problems faced during implementation of the POC:

drewzboto commented 2 years ago

I wanted to confirm your approach here, as we have done some similar work in the past, but didn't carry that forward into PWA Kit.

Are you looking to take your PWA Kit code and bundle it directly in a hybrid cordova-based native app, which doesn't require any additional downloading of files/assets from PWA Kit and Managed Runtime>? Or are you trying to embed a PWA kit site into a cordova-based webview (say use the existing cart/checkout pages from PWA Kit within a hybrid native app webvview)?

We've done the 2nd approach in the past, but we haven't focused on the 1st approach at all, and that does reflect in the SSR setup and build setup

drewzboto commented 2 years ago

@nx-andreashabermann tagging you here to make sure you saw my clarification questions. Thank you!

johnboxall commented 2 years ago

Making assumptions about what you're asking for, if you'd like to use Managed Runtime to host a "vanilla" React client side rendered app, you can use "Hello World" template as a starting point:

https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/hello-world

There is also a experimental version of this template in our upcoming major version:

https://github.com/SalesforceCommerceCloud/pwa-kit/tree/black-friday-hackathon/packages/hello-world

nx-andreashabermann commented 2 years ago

Basically the final goal should be the 1st approach. Using hello-world would mean to start at 0, at least it should be possible to set up nearly anything from that starting point, but the development time will much higher that way.

Here are the problems I got to when trying to use pwa-kit as base implementation with client side code in the hybrid app bundle:

  1. Routing: would be easier to have hash based routing for this approach
  2. Proxying/Development setup: The setup for development especially proxying the requests to the apis can make different problems, e.g. CORS and building the proxy server URLs.
  3. Some Commerce API endpoints do not support OPTIONS requests, so CORS preflight requests will cause errors if they get proxied to these APIs

Clientside rendering itself works as expected, as PWA is a react app.

johnboxall commented 1 year ago

Quick update, we're continuing to evaluate SSG/CSR on Managed Runtime but at this time it is not on the committed roadmap.

git2gus[bot] commented 11 months ago

This issue has been linked to a new work item: W-14515712