Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using {{ nocache }} around a form renders it once, but not on subsequent visits #10890

Closed
aaronbushnell opened this issue Oct 2, 2024 · 5 comments · Fixed by #10898
Closed

Comments

@aaronbushnell
Copy link
Contributor

Bug description

We have a Statamic 5.26.0 site that renders a form using code similar to the docs because we have enabled full static caching:

{{ nocache }}
    {{ form:create formset="contact" }}
        ...
    {{ /form:create }}
{{ /nocache }}

On page load the form is correctly AJAX'd in using the {{ nocache }} functionality.

However, when I bump the version to 5.27.0 the form renders the first time, but after subsequent visits the form never loads again.

I'm not certain if it's related but the {{ nocache }} JS was at the end of the </body> tag in 5.26.0, but moved to the <head> in 5.27.0.

How to reproduce

  • Create a form
  • Add the form to an Antlers template using the recommended caching setup
  • Turn on full page static caching
  • Load the page multiple times

Logs

No response

Environment

Environment
Application Name: Statamic Starter
Laravel Version: 11.26.0
PHP Version: 8.3.0
Composer Version: 2.8.0
Environment: production
Debug Mode: OFF
URL: [REDACTED]
Maintenance Mode: OFF
Timezone: America/Indiana/Indianapolis
Locale: en

Cache
Config: NOT CACHED
Events: CACHED
Routes: CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: redis
Session: file

Statamic
Addons: 9
Sites: 1
Stache Watcher: Disabled (auto)
Static Caching: full
Version: 5.26.0 PRO

Statamic Addons
mitydigital/statamic-scheduled-cache-invalidator: 2.1.0
rias/statamic-redirect: 3.8.1
statamic/seo-pro: 6.1.2
trendyminds/guide: dev-main
trendyminds/link: dev-main
trendyminds/nerf: 1.2.0
trendyminds/orbit-statamic: 2.0.0
trendyminds/statamic-palette: 1.2.1
trendyminds/tip: 1.0.0

Installation

Other (please explain)

Additional details

Uses a Statamic starter repo we developed in-house

@aaronbushnell
Copy link
Contributor Author

I'm assuming it's related to this PR, but I could be wrong: #10306

@duncanmcclean duncanmcclean changed the title [5.27.0+] Using {{ nocache }} around a form renders it once, but not on subsequent visits Using {{ nocache }} around a form renders it once, but not on subsequent visits Oct 3, 2024
@duncanmcclean
Copy link
Member

Yes, it'll be related to that PR.

Out of curiosity, why are you wrapping the form in the {{ nocache }} tag? It seems to work fine without it.

@ryanmitchell
Copy link
Contributor

We are seeing similar issues on sites with 5.27+... the issue is that the script is now being injected into the so its being run before anything in the has been rendered, therefore the query selector gets no nocache regions. This means nocache is basically broken on any full cached sites.

@jasonvarga
Copy link
Member

jasonvarga commented Oct 3, 2024

Ugh yeah. Sorry about that. I'll revert that PR.

@aaronbushnell
Copy link
Contributor Author

No problem! Yeah, we use {{ nocache }} on our forms because we want to show a success/error message @duncanmcclean. So we wind up using the approach noted here: https://statamic.dev/forms#caching

Happy to test anything you all need a hand with here—appreciate the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants