Skip to content
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

Rendering components in other documents #331

Closed
cristinecula opened this issue Mar 3, 2017 · 4 comments
Closed

Rendering components in other documents #331

cristinecula opened this issue Mar 3, 2017 · 4 comments
Labels

Comments

@cristinecula
Copy link
Contributor

Hello!

First of all, thank you for releasing this project and the time that's been invested in it! I am amazed by it's pure awesomeness and I am sure it will spark a revolution in the frontend frameworks landscape!

I have started to use Svelte in a production app and I am very satisfied with it's capabilities and performance.

One of my app's requirements is to render bits of UI in dynamically created iframes, so they can be overlayed over a customer's website and not be affected by the existing css and scripts (I can't wait for native custom elements browser support!). The problem is that Svelte components use the global document for adding the css and this leads to missing styles in the iframe. Here is a repl demonstrating the behaviour:

https://svelte.technology/repl/?version=1.9.1&gist=55752a08defcbd1423e2a2029eb02ef7

I have already made a branch with some code partially fixing the problem: master...widgetic:feature/ownerDocument

There are actually two issues here:

  1. adding the css to the correct document (based on the target's ownerDocument) [fixed]
  2. adding the css to both documents if needed (the global addedCss flag is not fitting anymore) [not sure of best way to fix]

I would love to hear your thoughts about this.

@cristinecula
Copy link
Contributor Author

I updated the branch with a solution for 2.

@PaulBGD
Copy link
Member

PaulBGD commented Mar 3, 2017

In firefox the h1 doesn't even get appended to the iframe. Is this supported in all browsers?

@cristinecula
Copy link
Contributor Author

cristinecula commented Mar 4, 2017

This is supported by all browsers, but there are a few quirks (we're using this in production with no issues).

Here is an updated repl that's cross-browser compatible: https://svelte.technology/repl/?version=1.9.1&gist=1ca1dd1182b4b30372bf741c898a6815

@Rich-Harris Rich-Harris added the bug label Mar 7, 2017
Rich-Harris added a commit that referenced this issue Mar 10, 2017
Rich-Harris added a commit that referenced this issue Mar 10, 2017
Add CSS to each document a component is rendered to
@Rich-Harris
Copy link
Member

Thanks! Took your fix and turned it into #362 — released as 1.11.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants