|
1 | 1 | import Vue from 'vue' |
2 | 2 |
|
3 | 3 | <% if (options.lazy.injectMock) { %> |
| 4 | +/* eslint-disable-next-line quotes, comma-spacing */ |
| 5 | +const API_METHODS = <%= JSON.stringify(options.lazy.mockApiMethods)%> |
4 | 6 | let delayedCalls = [] |
5 | 7 | let SentryMock = {} |
6 | 8 | <% } %> |
@@ -41,9 +43,7 @@ Vue.config.errorHandler = (error, vm, info) => { |
41 | 43 |
|
42 | 44 | export default function SentryPlugin (ctx, inject) { |
43 | 45 | <% if (options.lazy.injectMock) { %> |
44 | | - /* eslint-disable-next-line quotes, comma-spacing */ |
45 | | - const apiMethods = <%= JSON.stringify(options.lazy.mockApiMethods)%> |
46 | | - apiMethods.forEach((key) => { |
| 46 | + API_METHODS.forEach((key) => { |
47 | 47 | SentryMock[key] = (...args) => delayedCalls.push([key, args]) |
48 | 48 | }) |
49 | 49 |
|
@@ -141,8 +141,12 @@ async function loadSentry (ctx, inject) { |
141 | 141 |
|
142 | 142 | // help gc |
143 | 143 | <% if (options.lazy.injectMock) { %> |
144 | | - // Dont unset delayedCalls & SentryMock during |
145 | | - // development, this will cause HMR issues |
| 144 | + // Avoid crashes in case the reference to the mocked object is being used after the actual Sentry instance has loaded. |
| 145 | + API_METHODS.forEach((key) => { |
| 146 | + SentryMock[key] = (...args) => SentrySdk[key].apply(SentrySdk, args) |
| 147 | + }) |
| 148 | + |
| 149 | + // Dont unset delayedCalls & SentryMock during development - this will cause HMR issues. |
146 | 150 | <% if (!options.dev) { %> |
147 | 151 | delayedCalls = undefined |
148 | 152 | SentryMock = undefined |
|
0 commit comments