Skip to content

Commit

Permalink
fix: invalidate styles cache on styles update
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Feb 18, 2021
1 parent c0778a6 commit 12b1b07
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
17 changes: 11 additions & 6 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,21 @@ function initSubscriptions() {
minimapElement.attach(textEditor.getElement())
}),
// empty color cache if the theme changes
atom.themes.onDidChangeActiveThemes(() => {
domStylesReader.invalidateDOMStylesCache()
editorsMinimaps.forEach((minimap) => {
atom.views.getView(minimap).requestForcedUpdate()
})
}),
atom.themes.onDidChangeActiveThemes(updateStyles),
atom.styles.onDidUpdateStyleElement(updateStyles),
atom.styles.onDidAddStyleElement(updateStyles),
atom.styles.onDidRemoveStyleElement(updateStyles),
treeSitterWarning()
)
}

function updateStyles() {
domStylesReader.invalidateDOMStylesCache()
editorsMinimaps.forEach((minimap) => {
atom.views.getView(minimap).requestForcedUpdate()
})
}

// The public exports included in the service:
const MinimapServiceV1 = {
minimapViewProvider,
Expand Down
57 changes: 53 additions & 4 deletions spec/minimap-element-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1380,26 +1380,75 @@ describe("MinimapElement", () => {
// ###### ####### ## ## ## #### ######

describe("when the atom styles are changed", () => {
let styleElement;
beforeEach(() => {
styleElement = document.createElement("style");
atom.styles.addStyleElement(styleElement);

waitsFor("a new animation frame request", () => {
return nextAnimationFrame !== noAnimationFrame
})

runs(() => {
nextAnimationFrame()
spyOn(minimapElement, "requestForcedUpdate").andCallThrough()
spyOn(minimapElement.DOMStylesReader, "invalidateDOMStylesCache").andCallThrough()
})
})

it("forces a refresh with theme change", () => {

atom.themes.emitter.emit("did-change-active-themes")

waitsFor("minimap frame requested", () => {
return minimapElement.frameRequested
})

atom.themes.emitter.emit("did-change-active-themes")
runs(() => {
expect(minimapElement.requestForcedUpdate).toHaveBeenCalled()
expect(minimapElement.DOMStylesReader.invalidateDOMStylesCache).toHaveBeenCalled()
})
})

it("forces a refresh with style update", () => {
atom.styles.emitter.emit("did-update-style-element", styleElement)

waitsFor("minimap frame requested", () => {
return minimapElement.frameRequested
})

runs(() => {
expect(minimapElement.requestForcedUpdate).toHaveBeenCalled()
expect(minimapElement.DOMStylesReader.invalidateDOMStylesCache).toHaveBeenCalled()
})
})

it("forces a refresh with cache invalidation", () => {
expect(minimapElement.requestForcedUpdate).toHaveBeenCalled()
expect(minimapElement.DOMStylesReader.invalidateDOMStylesCache).toHaveBeenCalled()
it("forces a refresh with style add", () => {

atom.styles.emitter.emit("did-add-style-element", styleElement)

waitsFor("minimap frame requested", () => {
return minimapElement.frameRequested
})

runs(() => {
expect(minimapElement.requestForcedUpdate).toHaveBeenCalled()
expect(minimapElement.DOMStylesReader.invalidateDOMStylesCache).toHaveBeenCalled()
})
})

it("forces a refresh with style remove", () => {

atom.styles.emitter.emit("did-remove-style-element", styleElement)

waitsFor("minimap frame requested", () => {
return minimapElement.frameRequested
})

runs(() => {
expect(minimapElement.requestForcedUpdate).toHaveBeenCalled()
expect(minimapElement.DOMStylesReader.invalidateDOMStylesCache).toHaveBeenCalled()
})
})
})

Expand Down

0 comments on commit 12b1b07

Please sign in to comment.