verbb / cp-nav

Control Panel Nav is a Craft CMS plugin to help manage your Control Panel navigation.
MIT License
129 stars 11 forks source link

Config files updating every time I push up #113

Closed JayBox325 closed 2 years ago

JayBox325 commented 2 years ago

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.

engram-design commented 2 years ago

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.

peerfischer commented 2 years ago

We experience exactly the same problems with CP NAv..

engram-design commented 2 years ago

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

peerfischer commented 2 years ago

@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.

JayBox325 commented 2 years ago

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
engram-design commented 2 years ago

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.

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?

JayBox325 commented 2 years ago

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

image

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

engram-design commented 2 years ago

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?

JayBox325 commented 2 years ago

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)

engram-design commented 2 years ago

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?

pimago commented 2 years ago

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

engram-design commented 2 years ago

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.

ursbraem commented 2 years ago

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

engram-design commented 2 years ago

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

ursbraem commented 2 years ago

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

Screenshot-11 10-002206

engram-design commented 2 years ago

@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 commented 2 years ago

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

ursbraem commented 2 years ago

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.

engram-design commented 2 years ago

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 commented 2 years ago

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.

ursbraem commented 2 years ago

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!

pimago commented 2 years ago

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.

engram-design commented 2 years ago

@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!

pimago commented 2 years ago

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.

ursbraem commented 2 years ago

Screenshot-12 10-002229

engram-design commented 2 years ago

@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.

ursbraem commented 2 years ago

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!

engram-design commented 2 years ago

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 commented 2 years ago

Fixed in 4.0.7

pimago commented 2 years ago

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.

engram-design commented 2 years ago

@pimago I that immediately after resetting the navigation, or when you've pushed to production?

pimago commented 2 years ago

Before pushing. I am still on the local machine

engram-design commented 2 years ago

@pimago This issue was in https://github.com/verbb/cp-nav/issues/116 FYI