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

4.0 HTMLHelper - lazyloading #30615

Closed
HaJuSi-23 opened this issue Sep 11, 2020 · 16 comments
Closed

4.0 HTMLHelper - lazyloading #30615

HaJuSi-23 opened this issue Sep 11, 2020 · 16 comments

Comments

@HaJuSi-23
Copy link

Steps to reproduce the issue

on call an error on line 693 is the result.
Looks like "lazy" dosn't exist.screen shot 2020-09-11 at 13 41 21
MfG HaJuSi

Expected result

Actual result

System information (as much as possible)

Additional comments

@HLeithner
Copy link
Member

can you post the complete error message please?

@SharkyKZ
Copy link
Contributor

My guess it's referring to Warning: illegal string offset 'loading' because $attribs can be a string. Don't rush fixing this because the PR that added this code should just be reverted.

@HaJuSi-23
Copy link
Author

Warning: Illegal string offset 'loading' in /mnt/web101/....../htdocs/ligatest/libraries/src/HTML/HTMLHelper.php on line 693


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30615.

@dgrammatiko
Copy link
Contributor

because the PR that added this code should just be reverted

Any reason why? I'm really curious to know why Joomla shouldn't support something that magically improves perforrmance

@HaJuSi-23
Copy link
Author

Joomla! Version 4.0.0-beta4-dev
PHP Version 7.4.9
Identity user
Response 200
Template atum
Database
ServermysqlVersion5.6.42-logCollationutf8_general_ciConn Collationutf8mb4_general_ci
'------------------------'
$_GET
array:2 [ "option" => "com_joomleague" "view" => "projects" ]
$_POST
[]
$_SESSION
array:2 [ "PHPDEBUGBAR_STACK_DATA" => [] "joomla" => "TzoyNDoiSm9vbWxhXFJlZ2lzdHJ5XFJlZ2lzdHJ5Ij...
$_COOKIE
array:3 [ "wf_browser_dir" => "" "554c794a85683f20e9080da206be01cf" => "av7picjj52tsnv0ehigliege...
$_SERVER
array:46 [ "HTTP_HOST" => "www.ligatest.ksv-nesselblatt.de" "REMOTE_ADDR" => "31.18.238.55" "T...
'--------------'
session
array:4 [ "timer" => array:3 [ "start" => 1599887952 "last" => 1599888711 "now" => 159...
registry
array:3 [ "data" => array:1 [ "com_joomleaguesportstypes" => "1" ] "initialized" => false ...
user
array:20 [ "id" => 290 "name" => "Administrator" "username" => "admin" "email" => "webmaster...
application
array:1 [ "queue" => [] ]


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30615.

@SharkyKZ
Copy link
Contributor

Any reason why? I'm really curious to know why Joomla shouldn't support something that magically improves perforrmance

Supporting it and forcing it by default are different things.

@dgrammatiko
Copy link
Contributor

dgrammatiko commented Sep 12, 2020

forcing it by default

You do realize that all browsers support it and it’s a platform feature, right? So yeah you re right why force it when you can be the the worst (in terms of performance) cms out there...

PS. Just to be clear here I'm talking about loading=lazy for the content images (eg editor images and intro/fulltext), about HTMLHelper::image I guess since there is an option to pass any attribute the default forcing of the attribute is probably wrong, so in this case I will agree on reverting the forced attribute there

@HaJuSi-23
Copy link
Author

Dump HTMLHelper Line 691
"path-> " int(0)
"file-> " "/administrator/components/com_joomleague/assets/images/projects.png"
"attributes-> " NULL

All requested images exist at the requested place.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30615.

@schultz-it-solutions
Copy link
Contributor

schultz-it-solutions commented Sep 15, 2020

Sorry, I somehow did not see this issue here, when I opened
#30647

My approach for solving this would probably be to change the methods parameters from
public static function image($file, $alt, $attribs = null, $relative = false, $returnPath = 0)
to
public static function image($file, $alt, $attribs = array(), $relative = false, $returnPath = 0)

@SharkyKZ
Copy link
Contributor

Some more tinkering would be needed because $attribs can be a string. Anyways, if there's no objection to removing forced loading attribute, let's do that instead.

@HLeithner
Copy link
Member

Would it make sense to deprecate string support in the future?

@HaJuSi-23
Copy link
Author

I changed it to "$attribs=array()", but no improvement.
I'm now dump backward, to find out what's happen with "$attribs", why it's "NULL"


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30615.

@schultz-it-solutions
Copy link
Contributor

Together with the change of the methods parameters, this should do the trick (might be optimized code-wise):

	// Default to lazy you can disable lazyloading by passing $attribs['loading'] = 'eager';
	if (is_array($attribs) )
	{
		if (!isset($attribs['loading']))
		{
			$attribs['loading'] = 'lazy';
		}
	}
	else
	{
		$loading = stripos($attribs, 'loading');
		if ($loading === false) {
			$attribs .= " loading='lazy' ";
		}
	}
	return '<img src="' . $file . '" alt="' . $alt . '" ' . trim((\is_array($attribs) ? ArrayHelper::toString($attribs) : $attribs)) . '>';

@schultz-it-solutions
Copy link
Contributor

As per the discussion about "forcing" this, you would have to invoke yet another configuration parameter to give the site owner the possibility to decide. I am not sure the additional complexity (new config field and language strings. Probably "active" information about this new feature to all Joomla webmasters - otherwise this might be overlooked easily) is worth the trouble.

I had a similar discussion three years ago (see #17827 ) where it was decided to NOT INVOKE additional configuration settings.

@zero-24
Copy link
Contributor

zero-24 commented Sep 23, 2020

Would it make sense to deprecate string support in the future?

That would be the way to go in my opinion given that the options array allow us to extend the code without breaking anything.

For now I'm closing this issue here as this is also fixed with #30748 by adding an is_array check for now :)

@richard67
Copy link
Member

New PR is #30790. Please test.

@zero-24 zero-24 removed their assignment Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants