cp-nav icon indicating copy to clipboard operation
cp-nav copied to clipboard

Config files updating every time I push up

Open JayBox325 opened this issue 1 year ago • 28 comments

Describe the bug

Even though I don't update the CP Nav, it looks like I have a full reset of config files every time I come around to pushing work up. Is this normal?

image

I believe it's also lead me to an issue where it's getting proper confused with SEOMatic as seen here. He one labelled 'SEO' is the one I curated, the rest just keep appearing.

image

Steps to reproduce

Honestly, don't know. It's just happening every time I've made a change elsewhere and these files are appearing as different in git.

Craft CMS version

4.2.3

Plugin version

4.0.6

Multi-site?

no

Additional context

Does only seem to be happening when I deploy to my Fortrabbit production server.

JayBox325 avatar Sep 07 '22 14:09 JayBox325

Hmm, I wonder if your project config may have gotten out of sync? If you download your database from production, to your local dev environment, then run ./craft project-config/rebuild that should rebuild the project config as according to your production database. I'd be interested if you see any diffs in your project after this.

If there are any changes, I would push that immediately to production (which should do nothing), and then continue development from there.

If there are no changes, something else must be going on. It certainly shouldn't be re-generating like that, which is also leading to duplicates that you're seeing. From what I can see in your screenshot, items are getting new UIDs, so they're definitely being re-created when they shouldn't.

engram-design avatar Sep 07 '22 22:09 engram-design

We experience exactly the same problems with CP NAv..

peerfischer avatar Sep 11 '22 08:09 peerfischer

@peerfischer can you comment on any of my directions above? Are you also on Fortrabbit?

engram-design avatar Sep 11 '22 08:09 engram-design

@engram-design hello, yes we tried downloading production database and rebuilding everything. We can't really narrow down when its happening, bit it happens on all of our locale environments. We've also installed SEOmatic.

Craft CMS version 4.2.3

Plugin version 4.0.6

Multi-site? no

We deploy via DeployHQ.

peerfischer avatar Sep 12 '22 05:09 peerfischer

I downloaded the production DB, rebuilt locally and it doesn't seem to have resolved it. May have to uninstall :(

image

EDIT: Should also add that locally it's working fine, except for SEOMatic appearing at the bottom again and not being where I set it to be a week or so ago.

image

JayBox325 avatar Sep 15 '22 08:09 JayBox325

Still struggling to reproduce this, sorry! I've been at it all day making changes, messing around with the CP Nav items themselves, and messing around as much as I can.

  • Is there a sure-fire way you can reproduce the navigation items re-generating? I've gone through everything from changing general settings, Site settings, Email settings, Adding/Deleting sections, category groups, fields and more. Even just an example where you can recall making a change would be a good starting point
  • Was this an upgrade from Craft 3, or a fresh Craft 4 install?
  • Do you have any additional layouts?
  • Is the currently-logged in user an admin, or assigned to a specific layout?

Re-generating the nav is a last-ditch effort (you have to build it again), so only worth doing at the end, but it may still be happening after that.

There's only a few scenarios where the nav is re-built in this fashion. As for SEOmatic, it should be comparing the URL for each nav item (https://github.com/nystudio107/craft-seomatic/blob/5b30a0997989c524ea97d9bc8f910ca41ee6fbbe/src/Seomatic.php#L1144) with the value in the prevUrl column in your cpnav_navigation columns. So it seems strange that there's duplicate for this simple check.

I don't suppose you can shoot through your cpnav_* database tables?

engram-design avatar Sep 16 '22 05:09 engram-design

I have reset the nav to default and it just does this...

image

Think I'll have to uninstall and not use it unfortunately.

JayBox325 avatar Sep 22 '22 21:09 JayBox325

Would love to have a response to some of those questions, particularly if this is an upgrade from Craft 3 or a fresh install of Craft 4? And that's on local or production?

Are you using multiple layouts?

engram-design avatar Sep 23 '22 00:09 engram-design

Oh yeah, of course. Sorry about that!

Is there a sure-fire way you can reproduce the navigation items re-generating? Nope, happens every time.

I've gone through everything from changing general settings, Site settings, Email settings, Adding/Deleting sections, category groups, fields and more. Even just an example where you can recall making a change would be a good starting point Honestly haven't been able to identify anything. It just seems to happen every time I have made changes and pushed up.

Was this an upgrade from Craft 3, or a fresh Craft 4 install? It's on a fresh Craft 4 project

Do you have any additional layouts? Nope, just the default layout

Is the currently-logged in user an admin, or assigned to a specific layout? It's happening for me (admin) and my client (custom user group called Moderators)

JayBox325 avatar Sep 23 '22 16:09 JayBox325

Thanks for the clarification, I'll keep diving into what's going on here. The hardest part seems to be reproducing it for me, but with at least 2 people having this issue, I must be missing something obvious.

Final thing - can you shoot through your composer.lock and composer.json files, or at least a list of installed plugins, in case something might be conflicting?

engram-design avatar Sep 23 '22 21:09 engram-design

I have the same issue. Also only on the live server. I tried importing the db locally. And fully removing CP Nav. It keep on happening.

Craft 4.2.5.1 CP Nav 4.0.6

pimago avatar Sep 24 '22 15:09 pimago

If anyone can send their database or composer.lock and composer.json files to web at verbb.io hopefully that will give me some clues as to how your install is different.

engram-design avatar Sep 24 '22 21:09 engram-design

We have the same issue. And a lot of commits with the message cp-nav doing things on it's own 😄

Screenshot-10 10-002183

Here are the composer files @engram-design https://gist.github.com/ursbraem/7df01e4b579ced28bdeacca2466b4ba1

ursbraem avatar Oct 10 '22 11:10 ursbraem

Thanks @ursbraem still trying to figure out how it's happening to you all, but not with my several test installs!

engram-design avatar Oct 10 '22 23:10 engram-design

It seems to be updating the parent and prevParent Hashes whenever something changes:

Screenshot-11 10-002206

ursbraem avatar Oct 10 '22 23:10 ursbraem

@ursbraem That would make sense as the entire nav seems to be re-generated. And for subnav items that have a parent, they would be referring to the new parent.

engram-design avatar Oct 10 '22 23:10 engram-design

@ursbraem Are there any sort of changes you're making that seem to be triggering the navigation re-generation?

engram-design avatar Oct 10 '22 23:10 engram-design

I was just checking for that. Actually, it's hard to find a pattern. Mostly after project.yaml related changes. Should also happen when installing a plugin and I thought on composer actions. But it doesn't happen all the time!

I found one way I think I can reproduce it: by syncing in a fresh copy of the database from production. As soon as I've done that:

Screenshot-11 10-002211

Above we see it also renames files.

ursbraem avatar Oct 10 '22 23:10 ursbraem

Yeah, the sporadic nature of this change is pretty frustrating. I can't seem to figure out how to trigger it. A project-config/rebuild doesn't seem to trigger it for me either (which I assume you mean by rebuilding from the production database).

engram-design avatar Oct 11 '22 00:10 engram-design

Okay, I think I may have gotten to the bottom of this. CP Nav was running too early in the process, before an authenticated user was available, which meant a lot of checks in getCpNavItem() functions is plugins, which rely on a user to check for permissions was failing. This was also leading to duplicates due to my incorrect handling - so a two-fold issue.

I'd love to get some testers to test this out to be extra sure. To get this fix early, change your verbb/cp-nav requirement in composer.json to:

"require": {
  "verbb/cp-nav": "dev-craft-4 as 4.0.6",
  "...": "..."
}

Then run composer update.

You'll still need to clear out the duplicates manually, but hopefully it's the last time you'll need to.

engram-design avatar Oct 11 '22 03:10 engram-design

Fantastic, thank you so much!! I'm testing.

I found one way I think I can reproduce it: by syncing in a fresh copy of the database from production.

I've done that again and cp-nav remained silent in git. Let's see how it holds on over time!

ursbraem avatar Oct 11 '22 07:10 ursbraem

I tested the dev version. Deleted my old navs and created a new one. After pushing it to production I am still getting the duplicates. And I still have these weird rubber band behavior when I reorder items.

pimago avatar Oct 11 '22 07:10 pimago

@pimago I would just ensure that you pull down the database from production, then run ./craft project-config/rebuild locally, just to ensure you're local files are all okay.

So the duplicates only happen after pushing to production? Not beforehand, before you push up to production?

As for the "rubber band" issue, that's quite interesting. I'm testing with your database and not having an issue with that!

engram-design avatar Oct 11 '22 08:10 engram-design

Same thing. And I didn't even setup a custom navigation. After pushing to production it duplicates all navigation items, except for some plugin items.

pimago avatar Oct 11 '22 08:10 pimago

  • No "random" cp-nav behaviours so far when not changing the settings!
  • BUT 51 changed files with 67 additions and 50 deletions to commit after adding one new point to cp-nav, mostly sort-order:

Screenshot-12 10-002229

ursbraem avatar Oct 12 '22 08:10 ursbraem

@ursbraem Just wanted to check you did a project config rebuild from production before making a change? Just to ensure everything is in sync. The sortOrder changing when you add a new navigation item is normal, but not the additions and deletions - that sounds like its generating new navigation items again.

That's if we're talking about file being added/deleted. Not individual diffs in files. If we're talking about just individual additions and deletions inside files, that's totally normal - depending on where you're adding the new navigation item in your list. If you add it at the start or the middle, it's going to shift the order of all other items.

engram-design avatar Oct 12 '22 08:10 engram-design

project config rebuild

Can you give me the instructions to do it? What I normally do locally is apply config.yaml to database via cp. When we deploy to prod we do ./craft migrate/all and /craft project-config/sync. Is that it?

That's if we're talking about file being added/deleted

In my case, I added one new menu item and it only created that one new file for that. The rest are just diffs in files as you say. So still looking good on my side!

ursbraem avatar Oct 12 '22 10:10 ursbraem

Ah, gotcha - so diffs would be normal. No need to follow my instructions before (which was pulling the production database locally, then running ./craft project-config/rebuild to ensure your local project config files are up to date).

So far, this only now seems to be an issue unique to Fortrabbit, which I'm looking into.

engram-design avatar Oct 12 '22 11:10 engram-design

Fixed in 4.0.7

engram-design avatar Oct 27 '22 00:10 engram-design

I am not sure if it's fully fixed. I updated to 4.0.7 and reset my navigation. I added a few items and now my Commerce Item doesn't show the sub items anymore, except for the orders item.

pimago avatar Oct 27 '22 05:10 pimago