Until recently, the only side-loaded resource was the HLJS library for
computing syntax highlighting. For this task, the gr-syntax-lib-loader
provided an interface to load the library whether or not PG is being
served from a CDN.
With this change, the component is refactored to allow loading resources
other than the syntax library. A method is added for loading the
"dark-theme" document independently of whether a CDN is configured.
Also, some documentation comments are added to the existing methods.
Change-Id: I9891539cd4cf76ac0fe430ff3988e3a9dfbb0ca3
These tags are preserved by the Closure compiler and vulcanize in order
to serve the license notices embedded in the outputs. In a standalone
Gerrit server, these license are also covered in the LICENSES.txt served
with the documentation. When serving PG assets from a CDN, it's less
obvious what the corresponding LICENSES.txt file is, since the CDN is
not directly linked to a running Gerrit server. Safer to embed the
licenses in the assets themselves.
Change-Id: Id1add1451fad1baa7916882a6bda02c326ccc988
Tapping the "Show Diffs" link in the change view to display all of a
change's diffs inline spawns several asynchronous syntax highlighting
processes. Sometimes (especially for long file lists and slower HLJS
download rates) multiple highlight processes would request HLJS before
it had been loaded, resulting in multiple load/definitions of the
library. Occasionally this would result in a JS exception.
With this change, the HLJS loader functionality of GR-SYNTAX-LAYER is
separated into the GR-SYNTAX-LIB-LOADER component. This component
employs a singleton property to track state across multiple lib requests
behind a promise interface.
Tests are updated.
Change-Id: I673998d406a33afa158e04c4dbb91fe31442d527
Previously, the absolute path HighlighJS loader did not work when served
from a CDN. With this change, the absolute path for the script considers
the domain that the GR-APP element is served from.
Change-Id: I024507aed175ce7000e3db0c711cbf559e3d2126
This causes issues when the app is vulcanized and the paths are
different as a result. The async/defer attributes will ensure
the script does not block parsing of the page.
Adds a flag to the Vulcanize rule that excludes HLJS. Confirmed that the
tag is ignored by Vulcanize phase in the compiled WAR file. Confirmed
that the `onload` case functions as expected via browser throttling.
Change-Id: Ie9603a5a07d4bae198ccc1ee56f408bfa0d37d49
Previously, the HighlightJS library (HLJS) was being Vulcanized into the
PolyGerrit build, even if the library was not being used (for example if
the user does not navigate to a diff or has syntax highlighting disabled
in preferences). Because HLJS is a substantial file -- ranging in size
from 47KB to more than 455KB (ungizpped) depending on the build
environment, this is not ideal.
In order to lazy load a JS library:
1) It needs to be copied into the built WAR file to be addressable, and
2) It should not be Vulcanized into the built gr-app.js file.
Previously, the PolyGerrit build system supported copying and
non-vulcanizing exactly one JS library: namely webcomponents-lite.js.
This change generalizes the mechanism by which webcomponents is copied
and adds HLJS to that list. This satisfies **1**.
Furthermore, the GR-SYNTAX-LAYER is rewritten to dynamically import HLJS
in the `process` step by crafting a SCRIPT element and attaching it to
the local DOM. (Syntax processing is invoked only after entire diff is
rendered.) Code that depends on the library awaits this load before
using it. Thus, the conventional JS import can be removed from the
element's HTML and will not be recognized by the Vulcanize phase. This
satisfies **2**.
Tests are updated accordingly.
Bug: Issue 4298
Change-Id: I9a95d6d4c211cd8f1ca1bc4daec770b64b22b3d1
Introduces the gr-syntax-layer element. This element works as an
annotation layer that is configured with the diff and asynchronously
computes/applies syntax for the diff.
Introduces a custom build of Highlight.js which gr-syntax-layer makes
use of. Building the script is documented in
scripts/vendor/highlight/building.md.
The layer is connected to the annotation pipeline in gr-diff-builder as
the lowest layer and syntax processing is triggered only after a diff
has been completely rendered.
A number of styles are added to the gr-diff element for syntax markers.
Tests added for gr-syntax-layer.
Bug: Issue 3916
Change-Id: Ic33e40f4fe39dfce1a62de133cfaf32be5e3f25a