-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Allow transitions to work within iFrames #3624
Comments
Svelte works great in iframes except for transitions and animations. This fixes that issue. See #3624.
@jacwright , do you have a simple REPL to demo how to render content in an iFrame ? I wanted to do this but I couldn't figure it out :) |
Unfortunately because the REPL sandboxes it's iframe, any iframes within it are sandboxed and it doesn't work. In the test I added as part of the pull request I include a Frame.svelte component which you can use. You'll need to add the styles to the body in the onload event, but it should work. I did try to get it working with the REPL. |
ok, I'll look , thanks... Just in case you were unaware; www.codesandbox.io also has a Svelte template, and you can "pop out" the preview pane in to a separate (non-framed) window, maybe that'll help your PR 🙂 |
Unless I can load a branch of Svelte into www.codesandbox.io I don't know if that will help determine the PR correctly fixes any issues. |
I'm also in a similar situation. @jacwright I'm also interested on how to add content to an iFrame. I managed to do this by manually creating a component, but I don't think this is the best solution.
|
I also need this feature implemented. |
@2beers I use a Svelte component to simplify the iframe. See https://gist.github.com/jacwright/7003916d7ae402b528dbaaca3061ca92#file-app-svelte-L6 as an untested example. |
@Tzelon you could clone my branch locally, then:
That's how I'm using it right now. |
Oh yeah, that gist is from the REPL. It just didn't work in the REPL because of sandboxing issues. https://svelte.dev/repl/7003916d7ae402b528dbaaca3061ca92?version=3.12.1 |
Works perfectly |
Is this specific to transitions and animations, or is this an issue for all styles? I'm trying to render a component with an It looks like Svelte briefly had support for styles in an |
@jtormey This PR is specific to transitions and animations. It would be great to get another PR for component styles. |
Thanks! I'll take a look at that. In the meantime, were you able to find a workaround that allowed you to inject component styles generated by Svelte into the iframe for your navigation component? |
My iframe component does this little number on load: Array.from(document.querySelectorAll('style, link[rel="stylesheet"]')).forEach(node => head.appendChild(node.cloneNode(true))); Here it is in context: import { onMount, onDestroy } from 'svelte';
export let component;
let frame; // bound in HTML with <iframe bind:this={frame}>
let content;
function onLoad() {
const head = frame.contentDocument.head;
const body = frame.contentDocument.body;
Array.from(document.querySelectorAll('style, link[rel="stylesheet"]'))
.forEach(node => head.appendChild(node.cloneNode(true)));
if (component) {
const { component, ...props } = $$props;
content = new component({
target: body,
props,
});
}
}
onMount(async () => {
if (frame.contentDocument.readyState === 'complete' && frame.contentDocument.defaultView) {
onLoad();
} else {
frame.addEventListener('load', onLoad);
}
});
onDestroy(() => {
if (frame) frame.removeEventListener('load', onLoad);
if (content) content.$destroy();
}); |
This is great! Thanks for sharing. |
I can see that the PR for this issue is still opened. Are there any updates on this? (my app really needs this feature). Thanks in advance. |
I haven't had the time to update the PR to the latest version of Svelte and resubmit. I should be able to soon (in the next month). Sorry for the delay! It helps knowing others need this too. |
This has been released in 3.20.0, thank you! |
@jacwright |
I’m not sure. I know you can export your app’s css separately in the build
step, so maybe do that and put a data-attribute on the link element loading
the style sheet or something like that.
…On Tue, Apr 21, 2020 at 3:16 PM naorye ***@***.***> wrote:
@jacwright <https://github.com/jacwright> Is there away to take only the
app styles instead of taking all the styles of the parent?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3624 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA5LZV7OMA5S4ZQM2V7LDTRNYEKZANCNFSM4I26L7RQ>
.
|
@jacwright You right. Thats what I've done. |
Sometimes your app needs to run within an iframe. For example, Intercom's chat widget which needs to be style-sandboxed from the rest of the page is run in an iFrame. My app wraps a navigation component inside an iFrame for better performance in the rest of the page.
The only thing that can't be worked around in this situation is Svelte's CSS transitions. They add the animation styles to the global (top-level) document and not the component's document.
For Svelte's transitions to work, Svelte will need to support adding styles to the document a component lives in.
I've created a solution which works well and avoids memory leaks. I reference this ticket in the PR.
The text was updated successfully, but these errors were encountered: