statamic / ssg

The official Statamic Static Site Generator
229 stars 23 forks source link

Site breaks after each generate #90

Closed andylarkum closed 1 month ago

andylarkum commented 2 years ago

This may be more a support thing than an issue.

I'm using Laravel:Sail to manage a local site, against which I then use SSG. For full disclosure, I do this: cd site_directory ./vendor/bin/sail up -d

I then make edits at: localhost/cp

Then in site_directory, I run: php please ssg:generate --workers=4

I usually have to run ssh:generate several times to get a full version of the site due to random errors that make little sense to me! I'd give you one of those errors, but that's tricky right now for reasons below. After each SSG generate, the first visit back to localhost generates an error. A page refresh usually resolves.

However, this time when I revisited localhost/cp, it says that I have 8 pages, but none of them seem to exist anymore. Laravel logs say: local.ERROR: Call to a member function selectedQueryColumns() on null {"userId":"e20b6971-10b8-412c-966c-fd5605395d4f","exception":"[object] (Error(code: 0): Call to a member function selectedQueryColumns() on null at /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:60)

Visiting localhost generates a 404.

A similar thing happened the last time I ran SSG, but I assumed I'd done something else somewhere, and had only lost a couple of pages so I just rebuilt them. This time, I had a fully working site that appears to have been destroyed somehow - but I don't know why.

Pretty certain it's something I'm doing as nobody else is reporting this as an issue!

Any help much appreciated

Andy.

jackmcdade commented 2 years ago

Do you run into this same issue if you don't use 4 workers?

andylarkum commented 2 years ago

Good question. Disappointingly, I've tried rolling my site back (git) to the last good version, but I get the same content error. Without rebuilding the site, I can't give you an answer.

I'll rebuild tonight (unless someone can tell me how to recover it), and let you know...

jackmcdade commented 2 years ago

Are you committing the statically generated files?

andylarkum commented 2 years ago

No - am using the standard laravel .gitignore - but I have that content because I pushed it (to S3). Rebuild will be quick, but annoying, and I certainly don't want to have to do it every time!

jackmcdade commented 2 years ago

Oh, is the content being used to ssg stored on s3?

andylarkum commented 2 years ago

Full process I've been using:

php please ssg:generate --workers=4 && npm install && npm run production cd storage/app/static aws s3 sync . s3://my_site_s3_bucket

S3 hosts the static site behind Cloudfront.

andylarkum commented 2 years ago

OK, so happily simply running: php please cache:clear ...brought the pages back (see: https://benfurfie.co.uk/articles/how-to-fix-the-call-to-a-member-function-selectedquerycolumns-on-null-error-in-statamic-3)

Having got the content back, I did some tidying up to fix some bits I wanted to update, then ran: php please ssg:generate

...which produced this: `Error

Call to a member function hasStructure() on null

at vendor/statamic/cms/src/Stache/Stores/CollectionEntriesStore.php:138 134▕ } 135▕ 136▕ protected function removeEntryFromStructure($collection, $id) 137▕ { ➜ 138▕ if (! $collection->hasStructure()) { 139▕ return; 140▕ } 141▕ 142▕ $collection->structure()->trees()->each(function ($tree) use ($id) {

  +43 vendor frames

44 please:37 Illuminate\Foundation\Console\Kernel::handle()`

I ran it again - same error, but 3rd time's a charm, ran through fine.

I'm guessing that the error is something to do with a caching thingy?!

DoubleJ-G commented 2 years ago

I am also now getting

 Call to a member function handle() on null
  at vendor/statamic/ssg/src/Generator.php:384

All our builds in CI are failing today. I have even tried adding php please cache:clear into the build steps.

Things work on both my local desktop and building in a docker image on my desktop, but fails in the CI step which should be the same.

Also to note, it doesn't break on the same page every time, sometimes it will error at the start and others near the end

andylarkum commented 2 years ago

FWIW (and in case anyone else stumbles across this issue), for me, running

php please cache:clear

...before AND after running

php please ssg:generate

...solved the problem.