Skip to content

Commit

Permalink
add Setting to defer js bundles
Browse files Browse the repository at this point in the history
so if we have a bundle or bundles that fail due to DOM-ready
race conditions exacerbated by Chrome 96, we can defer them
without a deploy while we fix the code

test plan:
 - Setting.set('deferred_js_bundles', 'foo,bar') will cause
   js_bundles `foo` and `bar` to be deferred
 - Setting.set('deferred_js_bundles', '*') will cause all
   js_bundles to be deferred
 - Setting.set('deferred_js_bundles', '*,!foo') will cause
   all js_bundles except for `foo` to be deferred

refs FOO-2597

Change-Id: Ie976608a869e576c9eb2e2da0bf89b73cbe68b4a
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/281060
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: Charley Kline <[email protected]>
Product-Review: Charley Kline <[email protected]>
QA-Review: Charley Kline <[email protected]>
  • Loading branch information
jstanley0 committed Dec 13, 2021
1 parent f01fdbb commit 129f6c2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,20 @@ def include_js_bundles
# execution is delayed until the DOM is ready.
if new_js_bundles.present?
concat javascript_tag new_js_bundles.map { |(bundle, plugin, defer)|
defer ||= defer_js_bundle?(bundle)
container = defer ? "window.deferredBundles" : "window.bundles"
"(#{container} || (#{container} = [])).push('#{plugin ? "#{plugin}-" : ""}#{bundle}');"
}.join("\n")
end
end
end

def defer_js_bundle?(bundle)
@deferred_js_bundles ||= Setting.get("deferred_js_bundles", "").split(",")
@deferred_js_bundles.include?(bundle.to_s) ||
(@deferred_js_bundles.include?("*") && @deferred_js_bundles.exclude?("!#{bundle}"))
end

def include_css_bundles
@rendered_css_bundles ||= []
new_css_bundles = css_bundles - @rendered_css_bundles
Expand Down

0 comments on commit 129f6c2

Please sign in to comment.