-
-
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
bind:clientWidth doesn't work in sandbox #2147
Comments
I believe it's repl only issue. Seems like update: I've tested the example in a Sapper app and all work as expected. |
Yeah, this is tricky. There's no way to use the element resize listener technique this binding uses inside an iframe that doesn't have both Options:
All these options are terrible. The last one is probably the least terrible. Am I missing any? |
Below works on firefox, but is a bit heavy. let resizeListenerId = 0;
function addResizeListener(element, fn) {
if (getComputedStyle(element).position === 'static') {
element.style.position = 'relative';
}
const object = document.createElement('object');
object.setAttribute('style', 'display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;');
object.type = 'text/html';
let win;
let resizeMessageKey = `resized-${resizeListenerId++}`
let eventProxyScript = "data:text/html;charset=utf-8,"+ encodeURIComponent(
`<script>window.addEventListener('resize', () => window.parent.postMessage("${resizeMessageKey}",'*'))</script>`
);
let messageHandler
object.onload = () => {
if (window.origin == 'null') {
messageHandler = (e) => { if (e.data == resizeMessageKey) fn() }
window.addEventListener('message', messageHandler );
} else {
win = object.contentDocument.defaultView;
win.addEventListener('resize', fn);
}
};
if (/Trident/.test(navigator.userAgent)) {
element.appendChild(object);
object.data = window.origin == 'null' ? eventProxyScript : 'about:blank';
} else {
object.data = window.origin == 'null' ? eventProxyScript : 'about:blank';
element.appendChild(object);
}
return {
cancel: () => {
if (win && win.removeEventListener) {
win.removeEventListener('resize', fn);
}
if (messageHandler) {
window.removeEventListener('message', messageHandler);
}
element.removeChild(object);
}
};
} |
Set an alert of some kind that asks the user if they want to refresh? |
How practical would it be to have the sandbox default to being more relaxed just on tutorials, since the only code getting run there would be stuff we write or that the user writes or pastes in. We could still keep the more restrictive settings on the main REPL, possibly with a button to relax them. Or we could even have the REPL default to relaxed if you visit it via one of the built-in examples, and only put it in the more restrictive mode upon loading a Gist. |
Actually you know what? That's a great idea. Certainly in the short term — I guess it'd be a little confusing if you forked one of the examples and it stopped working. We could also relax the sandbox if you're on your own gist, maybe. And perhaps we could detect the existence of non-sandbox-friendly things (if you're on someone else's gist) and display a warning in those cases? |
run tutorial and widget REPLs in relaxed sandbox
This now works with @Conduitry's fix: https://v3.svelte.technology/tutorial/dimensions Will leave this open so we can explore the more complete solutions later |
can you please write with big red letters, that it works, but just does not work in svelte.dev/repl |
I'm getting the same error on my app in iOS Safari.
which is happening on line 352 of
I'm using Sentry to track error occurances so I'm just getting a report from them. Apparently this is all from Safari, and mostly iOS. I can't seem to reproduce this locally though (even using the same iOS / Safari version). |
This works in 3.21.0, finally! https://svelte.dev/repl/648026c694e2323428e82b60c38829d0?version=3.21.0 Thanks @mrkishi! |
How about using resizeObserver if available and the iFrame trick only as a fallback? https://caniuse.com/#feat=resizeobserver The metics it provides may not be helpful (most browsers only provide the contentRect when you normally want borderBox). But it should be a lighter weight way of detecting that a resize has happened. |
@surjithctly your error does not look related to this issue. You are using querySelector before the component has mounted. If that function in used in an onMount call, then your error disappears. https://svelte.dev/repl/45446e457d9f43c09e2eebe401955917?version=3.29.7 |
REPL. Resizing the viewer window doesn't change anything.
The text was updated successfully, but these errors were encountered: