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

Support dimension bindings in cross-origin mode #2989

Merged
merged 5 commits into from
Apr 20, 2020

Conversation

mrkishi
Copy link
Member

@mrkishi mrkishi commented Jun 9, 2019

bind:clientWidth and friends currently don't work when you're under cross-origin restrictions. This manifests itself in the REPL or any time a component with those bindings is used in a cross-origin iframe.

This PR just relies on message passing in these cases. The only browser that doesn't support this is IE11, but that's because it doesn't support srcdoc or src="data:", so I don't know what our options are. It didn't work before either, so it's not a regression.

As a small bonus, I made the helper follow the regular listener/bindings format, so it now reuses the dispose array with them.

Closes #2147 and sveltejs/svelte-repl#12.

if (crossorigin === undefined) {
try {
if (typeof window === 'undefined' || !window.parent || window.parent.document) {
crossorigin = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that none of these conditions will be true, and yet an exception is not thrown? If yes, crossorigin wouldn't get set in those cases. If not, could this be made a little clearer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either the last one throws, or one of them is true, but I'm not sure how to make it clearer. I suppose crossorigin = false could come before the tests, would that help? Perhaps adding a void to signify it's done on purpose instead of a forgotten statement?

if (crossorigin === undefined) {
    crossorigin = false;

    try {
        if (typeof window !== 'undefined' && window.parent) {
            void window.parent.document;
        }
    } catch (error) {
        crossorigin = true;
    }
}

return crossorigin;

@Conduitry
Copy link
Member

Would this mean that the workaround in #2279 would no longer be necessary?

@Conduitry
Copy link
Member

Actually, there are probably still some other things that people might want to do that require more relaxed sandboxing. Having a UI toggle for this is probably still a good TODO.

@Conduitry
Copy link
Member

I:

and the size binding did not seem to be working. Did I do something wrong to test this?

@mrkishi
Copy link
Member Author

mrkishi commented Jun 26, 2019

Ah, interesting. I didn't notice it wasn't working for static elements after moving to event listeners. Will revert it so it still happens on mount.

@Conduitry
Copy link
Member

@mrkishi Do you think you might have time to take another look at this?

@mrkishi
Copy link
Member Author

mrkishi commented Oct 20, 2019

Took me a while (...just a little bit), but finally moved it back to mounting phase - now working on static elements.


if (/Trident/.test(navigator.userAgent)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what browser difference this UA sniffing was originally meant to work around, but can you confirm that it's no longer necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm honestly not sure. We're using iframe now and I tested it on Chrome/Firefox/Edge/Internet Explorer, but this might still make a difference on older IEs?

@thojanssens
Copy link

Hello. I was on version 3.20.1 and binding on clientWidth didn't work for me. After many hours of research I updated Svelte from 3.20.1 to 3.23.2 and now it works.

But I can't relate to the cross-origin thing... I don't use iframes, I'm simply using my dev environment, from a URL such as http://myapp.localhost:5000/

Why would it now work? Didn't you do more than supporting something related to cross origin?

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

Successfully merging this pull request may close these issues.

bind:clientWidth doesn't work in sandbox
3 participants