question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues when using together with Next.js

See original GitHub issue

After trying several ways of using asscroll v2, I still haven’t found a way to successfully use it in Next.js. In versions prior to v2, this worked:

// _app.js

useEffect(() => {
  const ASScroll = require("@ashthornton/asscroll").default;
  const sc = new ASScroll();
  sc.enable();

  const handleRouteChange = () => {
    setTimeout(() => {
      sc.onResize(window.innerWidth, window.innerHeight);
    }, 500);
  };

  router.events.on("routeChangeComplete", handleRouteChange);
}, []);

(The onResize was needed to calculate the new page height)

After upgrading to v2, though, I keep getting the TypeError: ASScroll is not a constructor error. I also tried to import it at the top (native and via next/dynamic), but then Webpack throws a ReferenceError: self is not defined error.

Any help is appreciated!

Thanks in advance 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ashthorntoncommented, Jul 3, 2021

Hi @tienuur , this must be a quirk with Nextjs and custom attributes. Glad you found a solution!

1reaction
tingyuzengcommented, Jul 3, 2021

@ashthornton it works now! I was still using the old parameter names, that’s why it couldn’t find the container element. Thanks!

Hi LotharVM, would you mind sharing a demo? I tried to work with asscroll in Nextjs as well. I cannot make it work… I tried your method, and made sure I require the package without default. There is a [asscroll-container] attribute in the JSX as well. But it keeps giving me TypeError: Cannot read property 'setAttribute' of null.

//_app.js

function MyApp({ Component, pageProps }) {

  useEffect(() => {
    const ASScroll = require("@ashthornton/asscroll");
    const asc = new ASScroll();
    asc.enable();
  }, []);

  return (
    <>
      <div asscroll-container>
        <div>
          <Component {...pageProps} />
        </div>
      </div>
    </>
  );
}

export default MyApp;

Thank you in advance!

I found a solution: I have to explicitly state asscroll-container="true" to make it work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js: The Good, Bad and Ugly - An Idiosyncratic Blog
When to use Next.js? Issues with Next.js; CSS Modules; Automatic Static Optimization, but only if you do this; Share data between getStaticPaths ...
Read more >
Basic Features: ESLint - Next.js
Next.js provides an integrated ESLint experience by default. These conformance rules help you use Next.js in the optimal way.
Read more >
Advanced Features: Next.js Compiler
js Compiler, written in Rust using SWC, allows Next.js to transform and minify your JavaScript code for production. This replaces Babel for individual...
Read more >
Blog - Next.js 13
Next.js 13 introduces layouts, React Server Components, and streaming in the app directory, as well as Turbopack, an improved image ...
Read more >
Migrating from Create React App - Next.js
Updating package.json and dependencies · Remove react-scripts (but keep react and react-dom ). If you're using React Router, you can also remove react-router-dom ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found