-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: unwanted duplication when going forward/backward in browser history * refactor: trigger perceptor.run() after tab url changes * fix: fluent UI will not lost its style sheets after page navigation * refactor: perfect way to trigger mainInject() * docs: add some comments * chore: remove "tabs" permission since it is not needed in the new strategy
- Loading branch information
Showing
9 changed files
with
156 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// This is an injected script, which shares same js context with the host page. | ||
|
||
// I infer that GitHub uses hotwired/turbo to speedup its SPA. | ||
// Fortunately there are some events to hook our code in GitHub | ||
// life cycle. See: https://turbo.hotwired.dev/reference/events | ||
|
||
// FluentUI is a css-in-js UI library, all styles are dynamicly | ||
// computed and injected to several style tags, like: | ||
// | ||
// <head> | ||
// <style data-merge-styles="true"></style> | ||
// <style data-merge-styles="true"></style> | ||
// <style data-merge-styles="true"></style> | ||
// </head> | ||
// | ||
// Thease tags are only computed once for each component. But the | ||
// style tags are regarded as "provisional elements" by turbo and | ||
// most of them will be removed after each trubo:visit, leading to | ||
// style crash. | ||
// | ||
// After reading the source code of turbo, I figure out a workaround. | ||
// By adding an id to all <style data-merge-styles="true"></style> | ||
// to make their outerHtml not be same, turbo will not regard them | ||
// as provisional elements and will keep them in headers. | ||
|
||
document.addEventListener('turbo:before-visit', () => { | ||
[...document.getElementsByTagName('style')].forEach((element, index) => { | ||
if (element.hasAttribute('data-merge-styles')) { | ||
element.setAttribute('data-id', index + ''); | ||
} | ||
}); | ||
}); | ||
|
||
document.addEventListener('turbo:load', () => { | ||
window.postMessage('turbo:load', '*'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters