-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
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
[docs] Fix iframe demos with emotion #24232
Merged
oliviertassinari
merged 3 commits into
mui:next
from
oliviertassinari:docs-fix-portal-demos
Jan 3, 2021
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that we can share the same cache between two iframe demos. The documentation only mentions that unique keys are required when using the same window/frame https://emotion.sh/docs/@emotion/cache#key.
@Andarist is it accurate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe that you can share the same cache between iframes because each one has to get their separate styles in their separate documents. Cache only checks the inserted keys and assumes that inserted keys are in sync with the inserted style elements - but if you share cache between "realms" then styles will really be only inserted into a single document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate note -
useMemo
doesn't give any semantic guarantees about caching (it's just like a perf hint). This probably doesn't matter for you here but to avoiduseMemo
refiring (even ifdocument
doesn't change!) you should put cache into a ref or into a state.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current configuration, each iframe has a different emotion cache instance in the React context with the same key. Is there a global side effect between different cache instances? (the
document
global side effect is not happening as we use different document, one per iframe). So far, the demos are rendered correctly.Would the style be broken if the emotion cache changes between two renders? I ask because I'm happy with a perf hint only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is:
https://github.com/emotion-js/emotion/blob/6e157aa198ac32d326d1aa1a921f459d880a8428/packages/cache/src/index.js#L84-L99
But it operates on the main script's document so it should simply not find any iframe styles in it and this should act like a noop - like you have mentioned.
No - styles should not be affected. You would only end up with multiple copies of the same styles being injected and some perf hit caused by somewhat full subtree rerended (all context consumers would have to rerender)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok great, awesome, thanks for the details