youtube / spfjs

A lightweight JS framework for fast navigation and page updates from YouTube
https://youtube.github.io/spfjs/
MIT License
2.23k stars 147 forks source link

Strange error when loading new page #420

Closed jhonsore closed 8 years ago

jhonsore commented 8 years ago

Hy guys,

fist of all, thanks youtube on providing this incredible source.

That's my problem:

I navigate normally through pages but for some reason sometimes everything breaks down showing just the json in my page. Maybe i'm making something wrong, but all requests are the same and there is just a static json through all pages.

I recorded what is happening for evaluation:

https://youtu.be/uWKHw8voIlg

https://youtu.be/46i5nIV5m9w

Best regards.

DavidCPhillips commented 8 years ago

It's a bit hard to confirm through the video, but it looks like you're running into the navigation limits.

For some background, the spf is really meant as an opportunistic framework. It tries to do an spf navigation where possible, but if something goes wrong (a bug in the JS, a bad request, etc.), it expects to be able to fall back to a traditional page load. To distinguish these cases, it sends the spf cgi param ('spf=navigate') when it wants a JSON response, and sends no param when it loads traditionally.

With this in mind, the framework has a default limit of 20 navigations before it falls back to a traditional page load. This is in place as a safeguard against memory leaks or similar bugs.

https://github.com/youtube/spfjs/blob/29965379cc77bd546c8829611028e03309a36bf3/src/client/config.js#L40

Now, we do support a null navigation limit which will skip any limit checks, but keep in mind that there are other code paths which trigger a traditional reload. So the recommended approach is for the server to only provide a JSON response when the spf=navigate cgi param is sent, and traditional HTML otherwise.

On Wed, Aug 3, 2016 at 10:49 AM, Jhonnatan Rebuli notifications@github.com wrote:

Hy guys,

fist of all, thanks youtube on providing this incredible source.

That's my problem:

I navigate normally through pages but for some reason sometimes everything breaks down showing just the json in my page. Maybe i'm making something wrong, but all requests are the same and there is just a static json through all pages.

I recorded what is happening for evaluation:

https://youtu.be/uWKHw8voIlg

https://youtu.be/46i5nIV5m9w

Best regards.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/youtube/spfjs/issues/420, or mute the thread https://github.com/notifications/unsubscribe-auth/AGfoRTfNtBAKp_OfyCis0INxLVm31gAtks5qcNSygaJpZM4Jb5h6 .

jhonsore commented 8 years ago

Wow,

I clicked 21 times in links and page breaks. Everything is clear now!

Thanks for all!