From 0748b8f931ec1477d36fc4814d695867d10360f6 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Tue, 8 Jan 2019 12:26:57 -0800 Subject: [PATCH] Add ability to add a suffix to the style tag name to prevent multiple instances colliding. --- src/exports.js | 2 ++ src/index.js | 2 ++ src/inject.js | 11 +++++++++-- src/no-important.js | 2 ++ tests/index_test.js | 33 ++++++++++++++++++++++++++++++++- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/exports.js b/src/exports.js index b86f3d3..fb88fbb 100644 --- a/src/exports.js +++ b/src/exports.js @@ -9,6 +9,7 @@ import { addRenderedClassNames, getRenderedClassNames, getBufferedStyles, + setStyleTagSuffix, } from './inject'; import {defaultSelectorHandlers} from './generate'; @@ -188,5 +189,6 @@ export default function makeExports( flushToStyleTag, injectAndGetClassName, defaultSelectorHandlers, + setStyleTagSuffix, }; } diff --git a/src/index.js b/src/index.js index 78c35bf..6bcdf67 100644 --- a/src/index.js +++ b/src/index.js @@ -13,6 +13,7 @@ const { flushToStyleTag, injectAndGetClassName, defaultSelectorHandlers, + setStyleTagSuffix, } = Aphrodite; export { @@ -24,4 +25,5 @@ export { flushToStyleTag, injectAndGetClassName, defaultSelectorHandlers, + setStyleTagSuffix, }; diff --git a/src/inject.js b/src/inject.js index c5c85d9..4dff2a5 100644 --- a/src/inject.js +++ b/src/inject.js @@ -16,6 +16,12 @@ import type { SelectorHandler } from './generate.js'; // `document.querySelector("style[data-aphrodite"])`, but holding onto it is // faster. let styleTag /* : ?HTMLStyleElement */ = null; +let styleTagSuffix = ''; +const styleTagAttribute = () => `data-aphrodite${styleTagSuffix ? '-' + styleTagSuffix : ''}`; + +export const setStyleTagSuffix = suffix => { + styleTagSuffix = suffix; +}; // Inject a set of rules into a