htmxpress icon indicating copy to clipboard operation
htmxpress copied to clipboard

Rewrite rules are not flushed on activation

Open jasalt opened this issue 2 years ago • 4 comments

Thought to try this out on a minimal client WP ajax-widget project and partially out of personal interest in django+htmx development. I didn't get it to run after half a day trying to run the demo however.

Testing log

I set up the suggested wp-env development environment on Debian stable (NodeJS v18.13.0, Docker version 24.0.2 rootless). wp-env start gets the stock WP installation up and running with htmxpress-plugin activated ok and not producing errors. Htmx javascript file loads globally on site (from unpkg.com).

When accessing demo urls I only get the classic Apache "Not Found" 404 page, access log:

"GET /htmxpress HTTP/1.1" 404 489 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"
"GET /htmx/ascii HTTP/1.1" 404 490 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"
"GET /html/partial-ascii HTTP/1.1" 404 490 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"
"GET /htmx/demo HTTP/1.1" 404 490 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"

Same results on Mac M1, Docker Desktop 4.19.0.

"GET /htmx/demo HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/114.0"

Another trial with Linux laptop and using VVV vagrant box which is personally more familiar tool. Installing htmxpress plugin as zip on the default "wordpress-one" site. Htmx script loads ok here as well. Accessing https://one.wordpress.test/htmx redirects to same url with ending slash and just shows the stock WP home page.

Access log:

192.168.56.1 - - [01/Jul/2023:14:21:26 +0000] "GET /htmx HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"
192.168.56.1 - - [01/Jul/2023:14:21:26 +0000] "GET /htmx/ HTTP/1.1" 200 13372 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"
192.168.56.1 - - [01/Jul/2023:14:33:58 +0000] "GET /htmx/ascii HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"
192.168.56.1 - - [01/Jul/2023:14:33:59 +0000] "GET /htmx/ascii/ HTTP/1.1" 200 13372 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"
192.168.56.1 - - [01/Jul/2023:14:38:24 +0000] "GET /htmx/partial-ascii HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"
192.168.56.1 - - [01/Jul/2023:14:38:25 +0000] "GET /htmx/partial-ascii/ HTTP/1.1" 200 13372 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"
192.168.56.1 - - [01/Jul/2023:14:38:50 +0000] "GET /htmx/demo HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"
192.168.56.1 - - [01/Jul/2023:14:38:51 +0000] "GET /htmx/demo/ HTTP/1.1" 200 13372 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"

Spent bit of time reading WP Rewrite Endpoints API docs and related code but didn't get any further yet...

jasalt avatar Jul 01 '23 14:07 jasalt

Hi sorry for the bad first impression. I noticed that wp env did not properly run the flush rewrite rules (part of the plug-in activation) for me, but haven’t looked more into it. As a result the endpoints aren’t activated. This is what you’re seeing.

Anyway if you go to Settings > Permalinks and press save it will flush them and everything will start working for you. Alternatively if the bug is not in the plug-in then deactivating and deactivating the plug-in should also work.

Let me know if I can help and apologies for the first run experience.

svandragt avatar Jul 02 '23 10:07 svandragt

Thank's, I got the demo working. Seems that plugin has trouble writing redirects with the default "Plain" permalink setting. Changed it to "Post type" and plugin started working. Seen this setting being a requirement in some plugins earlier.

Default TwentyTwentyThree block theme gives Deprecated: File Theme without header.php is deprecated since version 3.0.0 with no alternative available. but all the demo functionality works now as in video. Deprecation warning disappears with the Susty theme activated.

EDIT: tested on Mac with wp-env, but changing permalink setting does not seem to work on Debian with wp-env (rootless docker). The registered endpoint now shows up with wp rewrite list command but /htmx/ still gives 404 instead of the greeting and wp rewrite flush does not help. Works on Debian with VVV though.

On a side note, while trying to get it working with "Plain" permalink setting, there was some weird effects and differences between wp-env and VVV. While redirect path was not getting registered, I was able to get the demo page open from /?htmx=demo url. On wp-env I would only get 404 responses back to htmx doing queries from Serverside rendering partial and Live search tests. On VVV the Serverside rendering partial test gets the WP homepage HTML as response (not the ascii partial) and replaces the button with it. Live search seemed to work though while it didn't with wp-env. I was using it all the wrong way but though to make a note about it.

jasalt avatar Jul 03 '23 10:07 jasalt

Similar issue noted in another plugin doing same sort of thing https://github.com/TCattd/HTMX-API-WP/discussions/9.

jasalt avatar Oct 01 '24 13:10 jasalt

Cheers I’ll have another look

svandragt avatar Oct 01 '24 17:10 svandragt