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

WP Customizer stopped working #1879

Closed
izlietnes opened this issue May 2, 2018 · 14 comments
Closed

WP Customizer stopped working #1879

izlietnes opened this issue May 2, 2018 · 14 comments
Labels
Milestone

Comments

@izlietnes
Copy link

After last update to Kirki v3.0.27 the WP Customize page stopped working (not loading the page and sidebar tools, but the customize framework is shown)

When I disable the Kirki plugin, the customize page is working again thou many customizing options are gone.

I'm using Unero theme from Drfuri & WPBakery.

I haven't touched any files that would ruin Kirki plugin's functionality.

@izlietnes
Copy link
Author

izlietnes commented May 2, 2018

screen shot 2018-05-02 at 16 30 54 2

Looks like this when the updated version is enabled.

@asilcetin
Copy link
Contributor

Can you open the developer tools on chrome and paste a screenshot of console tab if you see any errors there?

@izlietnes
Copy link
Author

console errors

@asilcetin
Copy link
Contributor

I've been trying hard to reproduce this error, since it's clearly related to e64b116, however even after making a fresh instance with the latest kirki version and trying out different combinations of select field inside repeaters I couldn't get this error.

Can you maybe share the config of your fields? Especially the select fields defined inside repeaters would be related. And maybe you can edit kirki/controls/php/class-kirki-control-repeater.php and add the following code at line 304:

<# console.log(field); #>

Then please paste here the output of this log from developer tools > console tab.

@asilcetin
Copy link
Contributor

asilcetin commented May 2, 2018

OK, I think I know what's going on here.

When you create a new select field in a repeater without any default values and save it without any selections field.default is [""]. In this case field.default.indexOf(i) is -1, as it should be. Then you select some values and save, then your field.default is ["1"] or ["1", "2"] or something like that and field.default.indexOf(i) will work again as expected.

However if you somehow manage to define your field.default as an integer (which cannot be achieved with a fresh theme install, but you can maybe have a previously saved integer value for this field from a different control with the same settings name) then the field.default.indexOf(i) will throw this error because indexOf() won't work with an integer.

To avoid this error we can first check if field.default is an array.

Option 1:
if ( field.default instanceof Array && field.default.indexOf(i) !== -1 )
This will return false both when field.default is an integer or undefined, as we would want.
Note: indexOf() isn't supported on IE8 and below.

Option 2:
if ( jQuery.inArray(i, field.default) !== -1 )
If we're willing to use a jQuery function here, then this may be a good option since it'll return false both when field.default is an integer or undefined and would work on vintage browsers.

What do you think @aristath?

@izlietnes
Copy link
Author

Hi, Asil,

Thank You for helping to find a solution.
I've added the code <# console.log(field); #> in class-kirki-control-repeater.php and console shows the following:
screen shot 2018-05-03 at 12 55 37

@izlietnes
Copy link
Author

And I apoligize - I'm a complete dum dum about coding ;)

@izlietnes
Copy link
Author

So It would be completely ok If you say i screwed up something & it's no problem in Kirki's plug-in

@izlietnes
Copy link
Author

I just did a rollback to v3.0.25 and the customizer is working again, without errors

@asilcetin
Copy link
Contributor

Thanks for the screenshot and reporting, no it's not your fault.

It's exactly what I expected, just look at the default value right before the Uncaught TypeError where it says "default: 1", which is an integer. It should have been default: ["1"], it's obviously a wrong type saved in the database.

For now a rollback to the previous version would solve the issue for you. And we should change the code in kirki to avoid such an error as I described in my previous comment. I'll make a new pull request soon.

@izlietnes
Copy link
Author

Now I understand.
Thanks!

@Spolaa
Copy link

Spolaa commented May 9, 2018

A temporary solution could be this. The problem is that filed.default is an integer.
class-kirki-control-repeater.php on line 259 add follow line:
<# field.default = field.default? field.default.toString (): ''; #>
The problem is that in turn, another error is generated: Maximum call stack size exceeded.

@aristath
Copy link
Contributor

Thank you all for the detailed debug info!
I'm marking this as a bug and it will be fixed in v3.0.28 as soon as I get some free time to push the changes.
Of course if someone can submit a PR that's always more than welcomed 👍

@aristath aristath added the bug label May 10, 2018
@aristath aristath added this to the 3.0.28 milestone May 10, 2018
@aristath
Copy link
Contributor

Since there's no problem using jQuery in there I pushed the 2nd solution from #1879 (comment)
This will be included in v3.0.28. 👍

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

No branches or pull requests

4 participants