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

bug: isNode judge is inaccurate in server side rendering #4787

Closed
6 tasks done
zhangyuang opened this issue Jul 22, 2021 · 2 comments
Closed
6 tasks done

bug: isNode judge is inaccurate in server side rendering #4787

zhangyuang opened this issue Jul 22, 2021 · 2 comments

Comments

@zhangyuang
Copy link
Contributor

zhangyuang commented Jul 22, 2021

Check that this is really a bug

  • I confirm

Reproduction link

https://github.com/zhangyuang/swiper-bug-isnode

Bug description

// src/utils/utils.js
function isNode(node) {
  // eslint-disable-next-line
  if (typeof window !== 'undefined') {
    return node instanceof HTMLElement;
  }
  return node && (node.nodeType === 1 || node.nodeType === 11);
}

The judge is very inaccurate, in server side render, framework self or users maybe mock a window object in server side is frequent

Maybe there should judge at a deeper level。for example, window.document,window.document.documentElement or window.screen

Expected Behavior

No response

Actual Behavior

No response

Swiper version

6.8.0

Platform/Target and Browser Versions

macos

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
  • Make sure this is a Swiper issue and not a framework-specific issue

Would you like to open a PR for this bug?

  • I'm willing to open a PR
@zhangyuang
Copy link
Contributor Author

zhangyuang commented Jul 22, 2021

For the issue, the corresponding pr is #4788

if (typeof window !== 'undefined' && typeof window.screen !== 'undefined') {
    return node instanceof HTMLElement;
  }

@lhtdesignde
Copy link

lhtdesignde commented Aug 10, 2021

@zhangyuang I updated to 6.8.1 and still seeing this, I guess, related error: ReferenceError: HTMLElement is not defined.
This comes up in a mocha/enzyme test.

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

No branches or pull requests

2 participants