Since I convinced my new job to let me use Frontity for building one of our next projects, Iām going to be spending a lot of time here.
I figured it might be useful for me to make a bucket to kind of live blog all my thoughts about the framework etc as I go through it.
Disclaimer:
Iām hardly a āreal devā. Iām really more of a designer who knows enough to get themselves in trouble. But maybe that means my perspective will be of interest! IDK. Iām coming at this with the fresh eyes of someone who doesnāt know what theyāre doing.
Iāve greatly appreciated the responsiveness of the frontity main devs, and Iām offering this thread purely because I hope it can be useful. What isnāt useful please just ignore and take with a grain of salt
I also just find it helpful to journal stuff as Iām working through the problems, so itās practically just a form of documentation for my own purposes if nothing else
Thoughts in no paricular order:
I find it a little weird that the default theme mars names the archive component ālistā. I understand that the purpose is that list is perhaps more general in nature but I think itās a little confusing and considering the majority of people using this framework are probably coming from a wordpress background it seems to me that keeping the naming consistent would be better.
Iām going to have to break out the featured image into a separate component or something I think. Not sure. I want to eventually create a transition for it between the Archive page and the actual Post page similar to the modal effect you find here: https://tympanus.net/Development/CardExpansion/
other examples https://tympanus.net/Development/ExpandingGridItemAnimation/
That example is all built in one page so itās cool looking but not actually that practical for building a website and Iām not totally sure how to get a similar effect in Frontity or React. Iāve played with vanilla JS things like BarbaJs that allows for page transition effects but they basically work by fading out the current page and then fading in the new page, and Iād prefer to do some thing which thereās an actual sense of continuitity between the pages. Still trying to grok how to do that though.
Well thatās it for today. Iāll see yaāll tomorrow hopefully!
My recommendation is that you learn react-spring. It is the most powerful react animation library:
Itās hard to understand at first, but once you get the concept you can do amazing things with a few lines of code. And without stepping out of the āReact worldā.
The most important thing to understand is its transitions.map. In order to do transitions between two or more objects, the transitions.map maintains those objects on the screen until the transition ends.
If you do normal React like this:
{open ? <Open /> : <Close />}
React unmounts the non-used component instantly and you cannot do a transition.
In react-spring, you delegate the open value to useTransition and it controls when the components should appear and disappear with the transitions.map:
I donāt recommend you to use old vanilla JS animation libraries. They may seem to work at first but then youāll get into trouble when the animation and the React virtual-dom get out of sync. Stay in the React world.
I wish there was a clear difference between page and posts in the mars theme. I know that it should be possible for me to make my own āpageā component but Iām not quite sure how to do that yet. Iāll get there though.
I changed list to Archive but Iām getting a warning saying that I double named the modules. I shouldnāt be too surprised because I accidentally ran a search and replace when I only mean to do a search. The search and replace ended up breaking the theme for a little bit but I fixed it finally. I need to dig more into the stuff tomorrow and see if I can fix the double module issue that I created for myself.
The lazyloading image settings are really slow. Most lazy image stuff will preload the images a couple of seconds before the image comes into frame which helps to keep the appearance of āpopā in from happening. Is this being done with a js or browser native settings? I know that that lazyloading is coming to browsers soon but wasnāt sure how this was being handled.
Chrome 76+ includes native lazy loading. Once Chrome controls the lazy loading, thereās no way to change the offset. Itās something built-in and decided by Chrome based on device, connection and so on.
For other browsers, the Intersection Observer is used. Default rootMargin is 0px 0px 0px 0px but you can pass the rootMargin value to the <Image> component. For example:
rootMargin: '300px'
Looks like this!
The guys from Framer have also released another animation library for React:
Hey this is dope! But also if Iām not mistaken thatās not using webGL canvas right? It looks like itās an svg with svg Gaussian blur filters applied, but itās still in the DOM, and not in a separate canvas element, unless Iām misunderstanding something.
WARNING in ./packages/labs-website/src/components/Archive/archive-item.js
There are multiple modules with names that only differ in casing.
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
Use equal casing. Compare these module identifiers:
* /Users/aslan.french/work/labs-website/node_modules/babel-loader/lib/index.js??ref--4!/Users/aslan.french/work/labs-website/packages/labs-website/src/components/Archive/archive-item.js
Used by 2 module(s), i. e.
/Users/aslan.french/work/labs-website/node_modules/babel-loader/lib/index.js??ref--4!/Users/aslan.french/work/labs-website/packages/labs-website/src/components/Archive/archive.js
* /Users/aslan.french/work/labs-website/node_modules/babel-loader/lib/index.js??ref--4!/Users/aslan.french/work/labs-website/packages/labs-website/src/components/archive/archive-item.js
Used by 2 module(s), i. e.
/Users/aslan.french/work/labs-website/node_modules/babel-loader/lib/index.js??ref--4!/Users/aslan.french/work/labs-website/packages/labs-website/src/components/archive/archive.js
[...]
'EDIT: rest of the error message has been abridged as its basically a repetition of the first error message and because I fixed it just now
I have a decent sense of what I did I to screw it up. I just need to sit down and parse through it.
Cool, I have done this and I am currently troubleshooting some presentational issues but otherwise it seems to be working!
Quick question though. how does isPage getting passed? Where is it first defined? I know where to make a new āPageā component, but isPage is a function, so that has to be declared somewhere right? Is that a part of the frontity framework itself?
Letās say I wanted to make a new component like: Calendar
If I added data.addCalendar && <Calendar/> it wouldnāt know what to do right?
Also I respond with these questions, but I am also looking up stuff in the documentation so Iām trying to find the answers on my own too. Just donāt want you guys thinking Iām just asking questions without reading stuff first. Iām in the process of doing that stuff too.
in nav.js I found a css property applied to const Container called āarchive-style:noneā. As far as I can tell this isnāt a standard css property? It gets flagged by vscode and I also canāt find any mention on it through google.
I donāt know if this is even possible with server side rendered apps but it would be nice to have some kind of css.maps to more easily track down where a particular piece of css is coming from.
BTW I fixed the issue with the modules having inconsistent casing. The error message was pretty clear it was just a matter of tracking it down.
Also I tracked down that isPage, isArchive method. Itās from wp-source right? I will look at the documentation for that and see what I can learn from the recently addition of custom post types to frontity.
Youāre probably right! I donāt know much about animations/CSS/canvas to be honest.
Itās part of the wp-source package. You can take a look at frontity.state.source in your Chrome console. Youāll find a state.source.data object with all the known URLs and information about them.
Each time you move to another URL or manually fetch a URL using actions.source.fetch, wp-source tries to find information about that URL using the REST API and populates state.source.data with the info.
When you use state.source.get() you are actually taking a look at state.source.data. Thatās probably the point where itās not straightforward. Maybe state.source.getData() would have been a better name.
Not, because a calendar is not part of WordPress data.
You could create a calendar custom post type in your WordPress, add it to your wp-source settings and then, yes, you would have calendar URLs in /calendar/my-calendar-slug with data populated like this:
Donāt worry. We know our documentation needs to be improved a lot and we are currently looking for a person to work full-time on that. Your questions help us understand what things are not yet clear in the documentation so please continue to do so
I took another good look this morning and I tried many things but I couldnāt make it work. I guess the next step would be to debug the babel emotion plugin code itself.
So a lot of stuff in the mars theme is styled like this: const Content = styled.div
Thatās pretty straightforward but itās also makes it a little heard to read. Iām looking at the emotion js documentation and I canāt find a simple way to target an element by itās class name. Itās really simple to add a class name to a custom React component. And one advantage of this is that itās easier to then trouble shoot stuff because instead of just being <div class="css74289478></div> I can instead look for <div class="css236473 page-title></div>. Thatās doable within the context of lower level elements because of scss nesting but for wrapper elements itās a bit harder.
Is there some way of targetting stuff by css class name that Iām missing?
Also as a side note: I changed the names of the components and named in the following way to reflect the CSS classes which are normally output by Wordpress content html:
What is the purpose of ādangerslySetInnerHTMLā?
Is there a specific reason why the nav bar is divided into āheaderā which then contains ānavā? Seems it would be easier to just have a single component called āNavā but maybe this is done for some logic based reason that I am unable to see?
Okay so Iām kinda going through all the components and trying to simplify and reorder things according to the needs of the theme Iām working on, and also as a way of better understanding and learning the specifics of how things work in Frontity.
In the nav the menu links look like this in the mars theme:
When I print {state.router.link} the result I get is ā/about-us/ā and when I print {link} I get ā/about-usā.
Iāve tried to add an extra slash on the end of the {link} in the comparison but that also does not work even though I get identical prints from link and state.router.link when I do that.
-------EDIT:
Okay Iāve tried to simplify it even more. Still isnāt working consistently. When the menu item for the frontpage is selected then it is blue but when the about-us page is selected it remains purple.
and neither of those things ended up fixing the issue.
EDIT1:
Okay so I created a brand new frontity server using the cli create frontity command and I moved over my theme to that new location and got it working there.
Iām not totally clear on what the problem was but I think it was caused by incompatible versions or double installs of react and/or perhaps compatiblity issues between the version of frontity I was using on my work computer versus my home computer (work computer is a mac, home computer is a Windows Subystem Layer install of Ubuntu)
I am still getting the following error results despite the successful build.
Error: post type from endpoints "posts,pages,media" with slug "e3ae9ef6b9b0c063645f.hot-update.json" not found
at Object.eval (webpack-internal:///./node_modules/@frontity/wp-source/src/libraries/handlers/postType.ts:8:21)
at process._tickCallback (internal/process/next_tick.js:68:7)
Error: post type from endpoints "posts,pages,media" with slug "e3ae9ef6b9b0c063645f.hot-update.json" not found
at Object.eval (webpack-internal:///./node_modules/@frontity/wp-source/src/libraries/handlers/postType.ts:8:21)
at process._tickCallback (internal/process/next_tick.js:68:7)
EDIT2:
Iām going to continue my work diary below but the follow doesnāt have a whole lot to do with the above problems.
The isSelected issue has cleared up! IDK why exactly, maybe it was an update to Frontity?
I realize that thereās been some additions to mars-theme since I started building my own theme from it. I think I might try to refork mars-theme and migrate my changes over so that I can take advantage of those new features while still maintaining the changes Iāve made structurally.
You are right, itās a problem with a double install of @frontity/connect.
I think it happens when you have two different versions of the main frontity package in the root and inside a package.
Iām going to move all the frontity dependencies in packages to peerDependencies and I think that should solve this problem for good. Iām sorry about it.
That error is different. It appears when
You run Frontity in dev mode
Localhost is connected to the server for HMR (hot module replacement)
You stop the server.
Localhost tries to reconnect.
You start the server again.
Somehow, the HMR request of the old localhost goes thru webpack-dev-server and ends up in Frontity and it thinks it is trying to fetch a new page.
Iām testing the theme now on mobile emulation with chrome dev tools and Iām getting really inconsistent behavior.
I got things working okay with the default frontity test server API but when I try to test stuff with my own website blog at jackalope.tech/blog I get weird stuff like this.
EDIT:
Actually I fixed this. Was a problem with my code blocks not properly wrapping!
I encountered some inconsistencies when I was testing compatibility with my website json api source but the problems have been magnified when Iām trying the chrome device emulation stuff and I canāt actually determine what is causing these problems.
One issue that is relevant to bring up is that it seems the frontity test server posts have all been written in 2016. This is a problem since Gutenberg is now the standard editor and it outputs different HTML than the classic editor did. (some of these issues have popped in my own normal WP development.)
In line with that I would suggest you guys consider creating a new test blog that will have more full compatibility with the Gutenberg editor.
That of course isnāt going to fix this problem for me. I have no clue whatās causing it. Iām going to investigate this the best I can but thought I should drop a note by you guys since I can only see the disjunction between the test wp json and the evolution of the modern default editor growing.
Also I keep having this happen and I have no clue why. The only way to fix it is to go to put a ā/ā in the url and then it will load the front page correctly. But clicking stuff wonāt work.
Also a suggestion/request. Would it be possible to not have the babel output generate all the various browser variations when in dev mode? It makes it a lot more tedious to actually look through chrome dev tools when thereās like 4 different variations of the same css property.