Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
refreshless
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
refreshless
Commits
aa0ab207
Commit
aa0ab207
authored
6 months ago
by
ambient.impact
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3414538
: Enabled aggregation for our own JS if core patched:
See core issue
#3232810
for explicit JS aggregation group patch.
parent
947b0044
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!9
Issue #3414538: Turbo: Implement additive JavaScript aggregation to prevent multiple evaluation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/refreshless_turbo/refreshless_turbo.libraries.yml
+24
-19
24 additions, 19 deletions
modules/refreshless_turbo/refreshless_turbo.libraries.yml
modules/refreshless_turbo/src/Hooks/Javascript.php
+34
-0
34 additions, 0 deletions
modules/refreshless_turbo/src/Hooks/Javascript.php
with
58 additions
and
19 deletions
modules/refreshless_turbo/refreshless_turbo.libraries.yml
+
24
−
19
View file @
aa0ab207
...
...
@@ -3,25 +3,24 @@ refreshless:
theme
:
css/turbo.css
:
{}
js
:
js/drupal_settings.js
:
{
attributes
:
{
defer
:
true
},
preprocess
:
false
}
js/behaviours.js
:
{
attributes
:
{
defer
:
true
},
preprocess
:
false
}
js/scroll.js
:
{
attributes
:
{
defer
:
true
},
preprocess
:
false
}
js/stylesheet_sorter.js
:
{
attributes
:
{
defer
:
true
},
preprocess
:
false
}
js/refreshless.js
:
{
attributes
:
{
defer
:
true
,
# Causes Turbo to do a full page load if the query string for this
# changes, e.g. on a cache clear.
#
# @todo Should this be configurable?
data-turbo-track
:
'
reload'
,
},
# This should be excluded from aggregation for now.
#
# @see https://www.drupal.org/project/refreshless/issues/3414538
# JavaScript aggregation issue.
preprocess
:
false
,
}
# The explicit aggregation group should not be changed or removed as it's
# used to group our JavaScript into a separate aggregate if/when core
# supports it; if we detect that core supports this, the preprocess: false
# is changed to preprocess: true; if core does not support aggregation
# groups, the preprocess: false set here is left as-is to prevent our
# JavaScript potentially being downloaded and evaluated more than once since
# aggregation is not additive by default.
#
# @see https://www.drupal.org/project/drupal/issues/3232810
# Core issue with a patch to enable setting explicit aggregation groups.
#
# @see https://www.drupal.org/project/refreshless/issues/3414538
# RefreshLess issue implementing JavaScript aggregation support.
js/drupal_settings.js
:
{
attributes
:
{
defer
:
true
},
group
:
refreshless-turbo
,
preprocess
:
false
}
js/behaviours.js
:
{
attributes
:
{
defer
:
true
},
group
:
refreshless-turbo
,
preprocess
:
false
}
js/scroll.js
:
{
attributes
:
{
defer
:
true
},
group
:
refreshless-turbo
,
preprocess
:
false
}
js/stylesheet_sorter.js
:
{
attributes
:
{
defer
:
true
},
group
:
refreshless-turbo
,
preprocess
:
false
}
js/refreshless.js
:
{
attributes
:
{
defer
:
true
},
group
:
refreshless-turbo
,
preprocess
:
false
}
header
:
true
dependencies
:
-
core/drupal
...
...
@@ -81,6 +80,12 @@ js-cookie:
turbo
:
version
:
8.0.10
js
:
# Note that at the time of writing, Turbo does not cope well with being
# aggregated (and/or minified?), so the lack of a group here is intentional
# to prevent our hook picking this up and setting preprocess: true if core
# supports setting explicit aggregation groups.
#
# @see https://www.drupal.org/project/refreshless/issues/3414538
vendor/@hotwired/turbo/dist/turbo.es2017-umd.js
:
{
attributes
:
{
defer
:
true
},
preprocess
:
false
}
header
:
true
remote
:
https://turbo.hotwired.dev/
...
...
This diff is collapsed.
Click to expand it.
modules/refreshless_turbo/src/Hooks/Javascript.php
+
34
−
0
View file @
aa0ab207
...
...
@@ -76,6 +76,40 @@ class Javascript implements ContainerInjectionInterface {
}
#[Alter('js')]
/**
* Enable aggregation for our JavaScript if core supports naming groups.
*
* If core does not support named aggregation groups, the 'group' value will
* never be our string but a numeric value that core sets; if it's the numeric
* value, we don't do anything and allow the preprocess: false in our library
* definition to be used as a fallback.
*
* Note that \hook_library_info_alter() seems to be too early to detect this
* as it'll always have our string group; core seems to override the group
* value sometime between invoking that hook and \hook_js_alter().
*
* @see \hook_js_alter()
*/
public
function
refreshLessTurboGroupPreprocess
(
array
&
$javascript
,
AttachedAssetsInterface
$assets
,
LanguageInterface
$language
,
):
void
{
foreach
(
$javascript
as
$path
=>
&
$values
)
{
if
(
$values
[
'group'
]
!==
'refreshless-turbo'
)
{
continue
;
}
// Named aggregation groups are supported, so enable aggregation for all
// files in our group.
$values
[
'preprocess'
]
=
true
;
}
}
#[Hook('js_settings_build')]
public
function
outputPageState
(
array
&
$settings
,
AttachedAssetsInterface
$assets
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment