Commit 998f8f87 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'ek-remove-inline-script-issues-show' into 'master'

Use dataset instead of inline javascript to embed initial issuable data

See merge request gitlab-org/gitlab!42667
parents 69855e88 8de0c0b6
import * as Sentry from '@sentry/browser';
import { sanitize } from '~/lib/dompurify'; import { sanitize } from '~/lib/dompurify';
// We currently load + parse the data from the issue app and related merge request // We currently load + parse the data from the issue app and related merge request
...@@ -7,10 +8,9 @@ export const parseIssuableData = () => { ...@@ -7,10 +8,9 @@ export const parseIssuableData = () => {
try { try {
if (cachedParsedData) return cachedParsedData; if (cachedParsedData) return cachedParsedData;
const initialDataEl = document.getElementById('js-issuable-app-initial-data'); const initialDataEl = document.getElementById('js-issuable-app');
const parsedData = JSON.parse(initialDataEl.textContent.replace(/"/g, '"'));
const parsedData = JSON.parse(initialDataEl.dataset.initial);
parsedData.initialTitleHtml = sanitize(parsedData.initialTitleHtml); parsedData.initialTitleHtml = sanitize(parsedData.initialTitleHtml);
parsedData.initialDescriptionHtml = sanitize(parsedData.initialDescriptionHtml); parsedData.initialDescriptionHtml = sanitize(parsedData.initialDescriptionHtml);
...@@ -18,7 +18,7 @@ export const parseIssuableData = () => { ...@@ -18,7 +18,7 @@ export const parseIssuableData = () => {
return parsedData; return parsedData;
} catch (e) { } catch (e) {
console.error(e); // eslint-disable-line no-console Sentry.captureException(e);
return {}; return {};
} }
......
...@@ -62,9 +62,7 @@ ...@@ -62,9 +62,7 @@
.issue-details.issuable-details .issue-details.issuable-details
.detail-page-description.content-block .detail-page-description.content-block
-# haml-lint:disable InlineJavaScript #js-issuable-app{ data: { initial: issuable_initial_data(@issue).to_json} }
%script#js-issuable-app-initial-data{ type: "application/json" }= issuable_initial_data(@issue).to_json
#js-issuable-app
.title-container .title-container
%h2.title= markdown_field(@issue, :title) %h2.title= markdown_field(@issue, :title)
- if @issue.description.present? - if @issue.description.present?
......
...@@ -14,12 +14,8 @@ useMockIntersectionObserver(); ...@@ -14,12 +14,8 @@ useMockIntersectionObserver();
jest.mock('~/lib/utils/poll'); jest.mock('~/lib/utils/poll');
const setupHTML = initialData => { const setupHTML = initialData => {
document.body.innerHTML = ` document.body.innerHTML = `<div id="js-issuable-app"></div>`;
<div id="js-issuable-app"></div> document.getElementById('js-issuable-app').dataset.initial = JSON.stringify(initialData);
<script id="js-issuable-app-initial-data" type="application/json">
${JSON.stringify(initialData)}
</script>
`;
}; };
describe('Issue show index', () => { describe('Issue show index', () => {
......
...@@ -19,9 +19,8 @@ describe('RelatedMergeRequests', () => { ...@@ -19,9 +19,8 @@ describe('RelatedMergeRequests', () => {
mockData = getJSONFixture(FIXTURE_PATH); mockData = getJSONFixture(FIXTURE_PATH);
// put the fixture in DOM as the component expects // put the fixture in DOM as the component expects
document.body.innerHTML = `<div id="js-issuable-app-initial-data">${JSON.stringify( document.body.innerHTML = `<div id="js-issuable-app"></div>`;
mockData, document.getElementById('js-issuable-app').dataset.initial = JSON.stringify(mockData);
)}</div>`;
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
mock.onGet(`${API_ENDPOINT}?per_page=100`).reply(200, mockData, { 'x-total': 2 }); mock.onGet(`${API_ENDPOINT}?per_page=100`).reply(200, mockData, { 'x-total': 2 });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment