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

Code splitting with one SPA page #1379

Closed
thisbejim opened this issue Mar 10, 2017 · 12 comments
Closed

Code splitting with one SPA page #1379

thisbejim opened this issue Mar 10, 2017 · 12 comments

Comments

@thisbejim
Copy link

thisbejim commented Mar 10, 2017

Because an application re-renders when changing a page it seems like it is not possible to have a persistent navbar that doesn't flicker across multiple pages (frame rate doesn't catch first flicker):

mar-10-2017 10-52-39

The solution in this comment here is to have only one page (index.js) and just change the route query and use that to render whatever sub components/pages you'd like, as demonstrated in nextgram and react-overdrive. This means you can just mount the navbar once, which is great!

My only concern is that by going the one index page route you lose the automatic code splitting that comes with next - how might you address that in next's current state? I can see there are some conversations about supporting import in the future but what can we do today?

@thisbejim
Copy link
Author

thisbejim commented Mar 11, 2017

I thought this was a relevant snippet from the new react-router 4.0 docs on Code-splitting + server rendering:

We’ve tried and failed a couple of times. What we learned:

  1. You need synchronous module resolution on the server so you can get those bundles in the initial render.
  2. You need to load all the bundles in the client that were involved in the server render before rendering so that the client render is the same as the server render. (The trickiest part, I think its possible but this is where I gave up.)
  3. You need asynchronous resolution for the rest of the client app’s life.
    We determined that google was indexing our sites well enough for our needs without server rendering, so we dropped it in favor of code-splitting + service worker caching. Godspeed those who attempt the server-rendered, code-split apps.

@arunoda
Copy link
Contributor

arunoda commented Mar 11, 2017

@thisbejim the flick is due to the page fetching. Try doing some prefetching.
So, currently there's no more information than you linked in the issue description.

We'll land import support soon and we are experimenting it here.

@arunoda
Copy link
Contributor

arunoda commented Mar 11, 2017

I'm gonna close this since we've a separate issue where we discussed about this.
Thanks for mentioning that in the description.

@arunoda arunoda closed this as completed Mar 11, 2017
@rauchg
Copy link
Member

rauchg commented Mar 11, 2017

@thisbejim it's absolutely possible. Go to http://zeit.co and navigate around. I also have recently come up with a very simple solution to do lazy loading + route transitions which I'll share soon!

@thisbejim
Copy link
Author

Thanks @rauchg and yes I can confirm this is definitely possible, this was down to user error on my part. Looking forward to hearing about your new lazy loading solution!

@MarcMagnin
Copy link

@rauchg @thisbejim @arunoda any news about that? I'm quite interested too!

@MarcMagnin
Copy link

Awesome, so I've tried import and it seems to work fine but how do you refresh a dynamic component? (https://github.com/zeit/next.js/tree/import-then/examples/with-dynamic-import)

@arunoda
Copy link
Contributor

arunoda commented May 16, 2017

@MarcMagnin what do you mean by refreshing?

@MarcMagnin
Copy link

Sorry I was meaning that I want to change that Component on the fly by clicking on a button ie:
Something like:

@arunoda
Copy link
Contributor

arunoda commented May 16, 2017

@MarcMagnin please open a new issue for that. I know what you are referring to.
But it's not related here.

@MarcMagnin
Copy link

ok will do.

@EmperiorEric
Copy link

@thisbejim @rauchg are there any tutorials/walk-throughs for how this working? We have an application thats re rendering the navigation, background, etc and we're trying to get that to stop but its very unclear how to make that happen.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 13, 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

No branches or pull requests

5 participants