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.

Nested pages not loading static files using HOC

See original GitHub issue

Bug report

Describe the bug

The static images in my layout file (Navbar & Footer) will not get loaded when exporting html and navigating into a nested page (pages/products/test.js). But they are loaded when navigating into files directly (pages/*.js).

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Install freshly NextJS
  2. Create Layout HOC
  3. next build && next export && serve -p 8080
  4. localhost:8080 //Images loaded
  5. localhost:8080/products/test // HOC images missing

components/Layout.js

const withLayout = Content => {
  return () => (
    <Container>
      <Navbar active={Content.displayName} />
      <Content />
      <Footer />
    </Container>
  );
};

export default withLayout;

pages/index.js

  // IMAGES WILL LOAD HERE (i.e. Logo in Navbar)

  render() {
    return (
      <p>Test</p>
    );
  }
}

Home.displayName = "Home";
export default withLayout(Home);

pages/products/test.js

  // IMAGES SET IN Layout.js WILL NOT BE LOADED
  // test.jpg WILL BE LOADED

  render() {
    return (
      <img src={"../../static/test.jpg"} />
    );
  }
}

Home.displayName = "Home";
export default withLayout(Home);

Expected behavior

Images set in Layout file for Navbar & Footer should be loaded when navigating into a nested page.

Screenshots

grafik

grafik

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
Lokgiccommented, Mar 18, 2020

Ran into the same issue, but nothing here worked for me. At the end, it turned out a div with

height: 100vh;

was causing the issue. Pages are now rendered scrolled to the top after that line is removed.

7reactions
doantu-mirabocommented, Oct 20, 2020

I’ve stuck for two days. My solution is to remove overflow-x: hidden in body, HTML. Check your css such as min-height, overflow …

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested pages not loading static files using HOC - Stack Overflow
I solved this by creating & overwriting the file ./pages/_app.js . The Layout it now living there and will not be rerendered on...
Read more >
Nested pages not loading static files using HOC-Reactjs
[Solved]-Nested pages not loading static files using HOC-Reactjs. Search. score:1. Accepted answer. import React from "react"; import App, ...
Read more >
Basic Features: Layouts - Next.js
Learn how to share components and state between Next.js pages with Layouts. ... Because this file is not a Page, you cannot use...
Read more >
Higher-Order Components - React
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per...
Read more >
Lazy loading React components - LogRocket Blog
When you visit a website or use an app, it's very likely you're not seeing all the available content. Depending on how you...
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