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

Warn, don’t crash, when running Next.js inside an IFrame #5523

Closed
wants to merge 1 commit into from

Conversation

tomsoderlund
Copy link

@tomsoderlund tomsoderlund commented Oct 25, 2018

Checks if Next.js is running inside an IFrame, in which case it doesn’t use window.history and throws a warning once.

Previously, this would generate this error:

Failed to execute 'replaceState' on 'History':
A history state object with URL 'https://NEXTJS-CHILD-SERVER/path' cannot be created in a document with origin 'https://IFRAME-SERVER.com' and URL 'https://IFRAME-SERVER.com/path'.

This is an update to #3437 (which is a solution for #3118).

@@ -224,6 +224,9 @@ export default class Router {
}

if (method !== 'pushState' || getURL() !== as) {
if (window.frameElement) {
Copy link
Member

Choose a reason for hiding this comment

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

We don't do this check right 🤔

Copy link
Member

Choose a reason for hiding this comment

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

So it probably should check for the method not being available

Copy link
Author

Choose a reason for hiding this comment

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

@timneutkens The method IS available (I think), just restricted by the browser’s security model.

Choose a reason for hiding this comment

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

@timneutkens Actually we don't need history to be rewritten if we run Next inside the iframe.

@timneutkens
Copy link
Member

@tomsoderlund
Copy link
Author

I see now that the problem only applyies to Friendly IFrame's without src. Running Next.js inside a normal IFrame (with src) seems to work fine. So maybe our use case is more exotic than I first thought.

@tomsoderlund
Copy link
Author

Oh, it looks like @hankmander's old PR #3437 is on the merge queue for 7.0.3:
b8f189f

@timneutkens
Copy link
Member

It is not, it was replaced by the window.history check.

@timneutkens
Copy link
Member

Could you fix the merge conflicts and add an integration test? I guess this is the only way to solve the specific issue with iframes.

@timneutkens
Copy link
Member

I'll close this for now since it's conflicting with the current codebase.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants