-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom root
& shadow DOM support (#832)
#1004
base: canary
Are you sure you want to change the base?
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 889c04c:
|
An alternate solution might be removing the stringify in export const createMemo = () => {
const cache = new Map()
return (value, apply, ...args) => {
if (cache.has(value)) {
return cache.get(value)
}
const result = apply(value, ...args)
cache.set(value, result)
return result
}
} @jonathantneal could you give some feedback on this? |
root
to config
(#832)root
& shadow DOM support (#832)
If it is of interest I wrote a different solution last year (it was for use in a personal project as it uses the constructed stylesheets polyfill). aMediocreDad@14660d4 |
@jlalmes Any chance you could add core lib usage instructions for web components to the docs in this PR? |
Happy to update the Stitches website docs once this PR is merged 👍 |
Hey @hadihallak 👋 |
@jlalmes Thanks for your hard work.. this is something that's under consideration for the next release. @LexSwed Thanks for the ping |
No, I haven't tried this solution specifically, but this one: #628 (comment) worked in my case |
Hi @hadihallak - I suggest using a better memoizing function like the one I have mentioned above if bundle size is a concern (#1004 (comment)). Let me know what you think and I will update the PR. |
@jlalmes @LexSwed I think we're gonna delay merging this until after the 1.3 release as even with root support via the config, this doesn't solve providing root at runtime like in other libraries so I'm gonna think about this after the 1.3 release and come up with a plan to include runtime root support or work on merging this with the same old root API that exists here. Just to be extra clear, we want to support this as it's a much needed feature even for things not mentioned in this PR but we don't want to be hasty with API decisions (I know this used to exist prior to v1 but it wasn't the ideal solution). Thank you so much for your hard work 🙏 |
Need shadow DOM feature support. When creating chrome extension and injecting ui into content script, this "css in js" library will be the best practice if shadow dom feature was supported. |
Any updates on the status of PR? |
Don't we also have to add the From: Henrik Laxhuber <[email protected]>
Date: Wed, 22 Mar 2023 20:09:29 +0100
Subject: [PATCH] Shadow DOM Support
---
packages/core/types/stitches.d.ts | 4 +++-
packages/react/types/stitches.d.ts | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/packages/core/types/stitches.d.ts b/packages/core/types/stitches.d.ts
index 42a7200..3ed6636 100644
--- a/packages/core/types/stitches.d.ts
+++ b/packages/core/types/stitches.d.ts
@@ -12,7 +12,8 @@ export default interface Stitches<
Media extends {} = {},
Theme extends {} = {},
ThemeMap extends {} = {},
- Utils extends {} = {}
+ Utils extends {} = {},
+ Root extends DocumentOrShadowRoot = Document
> {
config: {
prefix: Prefix
@@ -20,6 +21,7 @@ export default interface Stitches<
theme: Theme
themeMap: ThemeMap
utils: Utils
+ root?: Root
},
prefix: Prefix
/** The **prefix** property defined.
diff --git a/packages/react/types/stitches.d.ts b/packages/react/types/stitches.d.ts
index 846f281..9d7b986 100644
--- a/packages/react/types/stitches.d.ts
+++ b/packages/react/types/stitches.d.ts
@@ -12,7 +12,8 @@ export default interface Stitches<
Media extends {} = {},
Theme extends {} = {},
ThemeMap extends {} = {},
- Utils extends {} = {}
+ Utils extends {} = {},
+ Root extends DocumentOrShadowRoot = Document
> {
config: {
prefix: Prefix
@@ -20,6 +21,7 @@ export default interface Stitches<
theme: Theme
themeMap: ThemeMap
utils: Utils
+ root?: Root
},
prefix: Prefix
/** The **prefix** property defined.
--
2.38.3 |
While at it, might be useful to also support multiple roots + changing roots dynamically? If you have a need for Shadow DOM, then chances are you'll have more than one Shadow DOM. |
Hii!! Running into this issue, this would be an awesome addition! Any updates? 🙏 |
If this PR is looking good for a single one, we could maybe do that as a follow up PR to unblock some use cases? :) |
Closes #832.
Custom
root
& shadow DOM supportThe
root
config property is causing aTypeError - Converting circular structure to JSON
error. The root cause of this is thecreateMemo
function (introduced here) attempting toJSON.stringify
circular objects such asdocument
.Changes made by this PR
stringify
function used bycreateMemo.js
(heavily inspired bysafe-json-stringify
)root
toCreateStitches
&ConfigType
TS definitions (forcore
&react
).👇 Web Components & shadow DOM demo
https://codesandbox.io/s/circular-json-reproduction-forked-gy01cx?file=/src/index.tsx