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

Avoid duplicating assets when they have params #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

erikn69
Copy link
Contributor

@erikn69 erikn69 commented Mar 8, 2022

BUG 1: If you do

Bonsai::add('example.js');
Bonsai::add('example.js?param=1');
Bonsai::add('example.js#param');

You get

<script type="text/javascript" src="/example.js"></script>
<script type="text/javascript" src="/example.js?param=1"></script>
<script type="text/javascript" src="/example.js#param"></script>

@kaidesu @thekanbo this PR avoid duplicating the same file on assets


BUG 2: ! in_array($assets, $collection) is always false because in_array('test', ['test'=>[]])) is false, array_keys is needed, Demo Link

bonsai/src/Assets.php

Lines 173 to 175 in 466603f

$collection = $this->collection->get($type);
if (! in_array($assets, $collection)) {

BUG 3: There is a bug because if you do something like this

Bonsai::add('example.js');
Bonsai::add('test.js','namespace');
Bonsai::add('example.js')->dependsOn('namespace');

as 'example.js' already exists, $this->lastAddedAsset is 'test.js', so dependsOn put namespace as dependency on 'test.js' instead of 'example.js', that is why $this->lastAddedAsset must be out of ! in_array($assets, $collection)
(it's currently working because always false makes replace the key all the time, when you fix the condition ! in_array($assets, $collection) with array_keys the bug pop up)

bonsai/src/Assets.php

Lines 65 to 72 in 466603f

if ($path === $this->lastAddedAsset) {
$collection[$path] = array(
'namespace' => $item['namespace'],
'dependency' => $dependency
);
$this->collection->put($this->lastAddedType, $collection);
}

@erikn69 erikn69 force-pushed the patch-1 branch 2 times, most recently from 7674516 to 474f8b3 Compare March 9, 2022 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant