rockiger / reactpress

Plugin that lets you easily create, build and deploy React apps into your existing WordPress sites.
https://rockiger.com/en/reactpress/
GNU General Public License v2.0
50 stars 6 forks source link

Can't get the react app to render on the WP page. #2

Closed oozie closed 3 years ago

oozie commented 3 years ago

Hey Marco,

I'm using

Whether I create the react app within the instance (running CRA in /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/reactpress/apps) and build - development mode - or copy pre-built build directory to /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/reactpress/myappbuild - deployment mode, the assigned slug (under /app1/) does render the root div as follows:

<!-- Please don't change. Block is needed for React app. -->
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

but doesn't include the related CSS/JS, which results in a blank page.

Can you please help me troubleshoot what goes wrong? I followed the instructions as well as youtube video to the T, and verified that shell_exec is available.

rockiger commented 3 years ago

Thanks for reporting this.

First, just to be sure, however you create the app on your Lightsail instance the built directory needs to be in /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/reactpress/apps/[appname]/build.

Second, you created a react app in your localhost inside WordPress and gave it a name and a page slug and it worked? It is located in [path/to/devserver]/htdocs/wp-content/plugins/reactpress/apps/[appname]/build?

Now in the page source you refered to are there any html tags with an id starting with rp-react-app-asset? If yes, could you please post them here?

oozie commented 3 years ago

I appreciate your quick response.

1) I believe the answer is yes:

bitnami@ip-172-26-5-97:/opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/reactpress/apps/app1$ ls
build  node_modules  package.json  package-lock.json  public  README.md  src

2) I created the react app on a WP instance (not localhost), gave it the name app1 / slug app1 and when I go to the /app1/ URL and view source, I see the root div, but no other assets. I created an app2 by copying the build directory from app1, to /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/reactpress/apps/app2/build. Going to /app2/ gives the same behavior as /app1/: root div present, no assets.

3) As per above, no assets in view-source.

Screen Shot 2021-04-28 at 12 18 57 AM

rockiger commented 3 years ago

Yeah this look good. I don't know what the problem is. This seems very odd.

Do have a debug log in WP instance?

oozie commented 3 years ago

I added log statements to the code and stepped through it. The code expects entrypoints in asset-manifest.json: https://github.com/rockiger/reactpress/blob/86d2c5170ccb740043a24cdf3211e37fc26b6d2e/public/class-reactpress-public.php#L150-L151

but my asset-manifest.json looks like this:

{
  "main.css": "static/css/main.40b4a62f.css",
  "main.css.map": "static/css/main.40b4a62f.css.map",
  "main.js": "static/js/main.b55ed1a8.js",
  "main.js.map": "static/js/main.b55ed1a8.js.map",
  "static/media/logo.svg": "static/media/logo.5d5d9eef.svg"
}
oozie commented 3 years ago

I must have used an old version of CRA. A rebuild on the more recent version is starting to work, but my SVG is missing.

Screen Shot 2021-04-28 at 9 28 30 AM

oozie commented 3 years ago

Essentially, it's working though - I'll replace it with a static asset from somewhere else.

Thanks for this awesome plugin, @rockiger.

rockiger commented 3 years ago

Glad it works for you.

It seems to me, that something with your PUBLIC_URL is of. ReactPress changes the build command in the package.json in every React app.

The build line should looke like:

"build": "PUBLIC_URL=/wp-content/plugins/reactpress/apps/[app-name]/build react-scripts build",