Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Gildiss
Aug 24, 2010

Grimey Drawer

smackfu posted:

Anyone have tips on working with static assets (like images) and CDNs and file naming? We recently had a designer say “oh that SVG we gave you that you deployed into production had a small layering bug, here is the new one.” We could just add a “b” or “v2” to the filename but maybe we should version them from the start? It’s our first time dealing with the CDN for this stuff so we are kind of winging it.

From my own experience, we kept the files named the same, overwrote them on the storage, and then ran an invalidation on AWS Cloudfront for that specific file path.
But that was also winging it.

Adbot
ADBOT LOVES YOU

gbut
Mar 28, 2008

😤I put the UN🇺🇳 in 🎊FUN🎉


Either strategy is valid. I like versioning filename just because it avoids the complexity, and is ok for long-lived assets. I suggest a proper versioning instead of "..._new" ;) For short-lived, iterated-over assets, cache invalidation is probably a better option.

Honest Thief
Jan 11, 2009
I get that you might no want to put a library like d3 on your project, but why output an entirely new svg instead of leveraging CSS, especially for the use case given?

bartkusa
Sep 25, 2005

Air, Fire, Earth, Hope

smackfu posted:

Anyone have tips on working with static assets (like images) and CDNs and files

Webpack renames our images with hashes of their content.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

gbut posted:

Either strategy is valid. I like versioning filename just because it avoids the complexity, and is ok for long-lived assets. I suggest a proper versioning instead of "..._new" ;) For short-lived, iterated-over assets, cache invalidation is probably a better option.

This is correct. The right way to version an asset is with "_FINAL". The next version becomes "_FINAL2". The version after that is "_FINAL2_corrected", etc.

Doh004
Apr 22, 2007

Mmmmm Donuts...

bartkusa posted:

Webpack renames our images with hashes of their content.

This is correct and a major advantage to using modern build tooling like Webpack. It also lets you start to use aggressive cache-control headers on your static assets.

minato
Jun 7, 2004

cutty cain't hang, say 7-up.
Taco Defender
Yeah the serious answer is to use Webpack. If you're not currently using it, be aware that since version 4 it (apparently) became a lot easier to use and integrate into your build/deploy process.

gbut
Mar 28, 2008

😤I put the UN🇺🇳 in 🎊FUN🎉


Third-ing this. ^

Ape Fist
Feb 23, 2007

Nowadays, you can do anything that you want; anal, oral, fisting, but you need to be wearing gloves, condoms, protection.
Can't wait for Angular 8.0 to drop so I can re-learn the RXJS syntax again like we have to do every loving version.

The Merkinman
Apr 22, 2007

I sell only quality merkins. What is a merkin you ask? Why, it's a wig for your genitals!
So we started using Vue for the employee-facing parts, as opposed to Angular for the customer-facing parts. In Angular we've used this to structure the "pages" of the site to different projects, which each can have sharable code and can be built independently of each other as well as, ultimately, built as one big app.

Is there an equivalent for Vue? I keep looking around and since I'm not getting any results I feel I'm either overthinking it, or it's a dumb idea.
Basically I'd like it where the different 'pages' of our employee-facing parts can be built independently, and optionally as one large one if we ever want to do a big SPA.
code:
/page-1
--/a-page1-component
--/another-page1-component
/page-2
--/a-page2-component
--/another-page2-component
/shared
--/shareable-component
--/another-shareable-component
So we could just build page-1.js and page-2.js separately....with maybe the option for a larger app.js down the road if we so choose, but I doubt we will.

EDIT: Also, using the Vue CLI

gbut
Mar 28, 2008

😤I put the UN🇺🇳 in 🎊FUN🎉


Those look just like different entry points that use the same shared components.

You could have an entry point for page1, page1,... and one that incorporates those elements in the main app.js. similar with router and state: split into modules, and instantiate in a very simple way, attach modules, and you can do that for individual pages as well as the main app.

Not sure if I'm missing something.

my bony fealty
Oct 1, 2008

Volguus posted:

On the other hand, you have this simple page application, with a form with 5 fields on it that submits some information to the backend to be saved into the database, and there are people out there who use angular or react or god knows what other 3mb minified abomination only because they do not know that document.getElementById is a thing.

These libraries (Vue, react, angular, etc.) have their place. A To Do list app is not one of them.

react + react-dom is like 100 kb these days, it's fine to use a front end library for simple interactions or widgets if you want to. yeah you shouldn't run a fancy library for a simple form but blanket statements and strawmen are meaningless.

if you wanna get real spooked try loading a webapp that was created in Wix Code or some other wysiwig nightmare and watch as it somehow transfers like 30mb of javascript (something I encountered recently for real), it's like the Dreamweaver of yore but for applications!

Sistergodiva
Jan 3, 2006

I'm like you,
I have no shame.

Is there any way to serve a non 200 status in a react app without using a server?
A library we use looks for json files of translations and fallbacks to English if it doesn't get a 200. Problem is that react juat gives it a 200 you must enable javascript response thus crashing the lib later.

This is looking for the files in the public folder.

prom candy
Dec 16, 2005

Only I may dance
What's your actual web server here? A client-side React app isn't really "serving" anything and can't return HTTP statuses. Are you referring to webpack-dev-server with create react app?

my bony fealty
Oct 1, 2008

useReducer and useContext are becoming my favorite thing in React. the only problem is trying to control components rerendering all the time when you don't want them to, which has not proved to be a big problem yet but certainly will at scale. anyone have suggested resources for learning about this kind of thing? should I be looking at memoizing components?

prom candy
Dec 16, 2005

Only I may dance
I think the official party line is "Concurrent React is coming, which will solve all problems forever." I think the other thing to keep in mind is that re-renders are pretty cheap if they don't do any calculation. What's causing all your extra rendering now anyway? Just more reliance on the Context API and components re-rendering because part of the context that you don't actually care about gets updated?

RobertKerans
Aug 25, 2006

There is a heppy lend
Fur, fur aw-a-a-ay.

my bony fealty posted:

useReducer and useContext are becoming my favorite thing in React. the only problem is trying to control components rerendering all the time when you don't want them to, which has not proved to be a big problem yet but certainly will at scale. anyone have suggested resources for learning about this kind of thing? should I be looking at memoizing components?

YMMV, your usecase/setup might be completely different and it might work fine, so go ahead and just try stuff, but:

I'm gonna guess at somewhere you have a collection of stuff: that's going to be your issue. Memo ain't any use (directly) for that (isn't really much use for context stuff), and you're going to have to do some very funky stuff to get it working optimally. I rebuilt one of the smaller apps at my work, replacing redux with context. Pretty simple, normalised model, was very careful about what parts I wanted to update, split across multiple providers, still getting unwanted re-renders all over the place. Rerenders are pretty cheap, so not a massive issue, but couldn't optimise them away, went back to redux.

Context is really good for stuff where you have a few states known in advance (eg theme switching, auth). Context is really not so good for stuff like collections, and isn't currently designed to be. There is a second argument you can give to createContext (unstable_observedBits) that allows you to do optimisations via bit flags, so they're clearly thinking about how to fix stuff. react-redux hit this issue (among others) when they switched to using context, and they're ripping context out ATM and reverting back to how it worked before

Sistergodiva
Jan 3, 2006

I'm like you,
I have no shame.

prom candy posted:

What's your actual web server here? A client-side React app isn't really "serving" anything and can't return HTTP statuses. Are you referring to webpack-dev-server with create react app?

We are working with a bank which has a like 3 week onboarding to get to their jira through citrix so I am assuming we can't change their server environments.

My project manager thinks we can solve thid by ejecting and removing webpack but am I assuming right when I think we would need to conf their server to fix it?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Sistergodiva posted:

We are working with a bank which has a like 3 week onboarding to get to their jira through citrix so I am assuming we can't change their server environments.

My project manager thinks we can solve thid by ejecting and removing webpack but am I assuming right when I think we would need to conf their server to fix it?

It's still kinda unclear what you're wanting.

React doesn't have anything to do with HTTP status codes. It doesn't even know networking of any type exists.

Aaronicon
Oct 2, 2010

A BLOO BLOO ANYONE I DISAGREE WITH IS A "BAD PERSON" WHO DESERVES TO DIE PLEEEASE DONT FALL ALL OVER YOURSELF WHITEWASHING THEM A BLOO BLOO
Your boss may be confused over whatever local dev server your React install of choice is using to serve the pages locally (hence their mention of webpack? Version 3 of that had a server which Angular still uses iirc). Once you build the app, it's just static content with no self-serving capability. You won't be able to do anything with HTTP statuses beyond responding to them without the server to barf them out.

Doh004
Apr 22, 2007

Mmmmm Donuts...

Sistergodiva posted:

We are working with a bank which has a like 3 week onboarding to get to their jira through citrix so I am assuming we can't change their server environments.

My project manager thinks we can solve thid by ejecting and removing webpack but am I assuming right when I think we would need to conf their server to fix it?

It sounds like you're confusing React with something like Node & Express. Like others have said, React is not a web server that handles requests and provides responses. It's literally just HTML and Javascript that runs in the browser.

SimonChris
Apr 24, 2008

The Baron's daughter is missing, and you are the man to find her. No problem. With your inexhaustible arsenal of hard-boiled similes, there is nothing you can't handle.
Grimey Drawer

RobertKerans posted:

Context is really good for stuff where you have a few states known in advance (eg theme switching, auth). Context is really not so good for stuff like collections, and isn't currently designed to be. There is a second argument you can give to createContext (unstable_observedBits) that allows you to do optimisations via bit flags, so they're clearly thinking about how to fix stuff. react-redux hit this issue (among others) when they switched to using context, and they're ripping context out ATM and reverting back to how it worked before

What's the problem, specifically? I am using Context to pass down my shared state, including a bunch of lists, and I haven't noticed any issues. Is it just a performance thing?

RobertKerans
Aug 25, 2006

There is a heppy lend
Fur, fur aw-a-a-ay.

SimonChris posted:

What's the problem, specifically? I am using Context to pass down my shared state, including a bunch of lists, and I haven't noticed any issues. Is it just a performance thing?

Yeah; just for context (heh) I am making a direct comparison with redux, as in replacing that with Context, and I ran into perf problems pretty quickly. The issue was the diffing of the state object, and the fact that Context is completely dumb. Any change to that object triggers rerenders to all subscribed consumers in the state tree. Memo doesn't help at all because it uses shallow comparison. I found I was basically trying to duplicate what react-redux already does better (use a fairly complex battery of methods to decide which parts of the state have to update) and having to write sometimes quite complex logic in components to prevent them rerendering unecessarily.

It's all contextual, and I hope over this year they work on improving it because I would love to be able to strip out redux. The DX is great; in the app I rebuilt, I got it down to 4 dependencies (react, react-dom, then the app-specific aws-amplify, and history for basic routing), hacked out a few thousand lines of code, and the code I rewrote was much simpler (until the diffing logic started to get gnarly). I'd really like to be back in that position, if only from a maintenance pov, and if the performance thing isn't an issue I'd totally recommend it.

RobertKerans fucked around with this message at 14:44 on Mar 15, 2019

SimonChris
Apr 24, 2008

The Baron's daughter is missing, and you are the man to find her. No problem. With your inexhaustible arsenal of hard-boiled similes, there is nothing you can't handle.
Grimey Drawer

RobertKerans posted:

Yeah; just for context (heh) I am making a direct comparison with redux, as in replacing that with Context, and I ran into perf problems pretty quickly. The issue was the diffing of the state object, and the fact that Context is completely dumb. Any change to that object triggers rerenders to all subscribed consumers in the state tree. Memo doesn't help at all because it uses shallow comparison. I found I was basically trying to duplicate what react-redux already does better (use a fairly complex battery of methods to decide which parts of the state have to update) and having to write sometimes quite complex logic in components to prevent them rerendering unecessarily.

It's all contextual, and I hope over this year they work on improving it because I would love to be able to strip out redux. The DX is great; in the app I rebuilt, I got it down to 4 dependencies (react, react-dom, then the app-specific aws-amplify, and history for basic routing), hacked out a few thousand lines of code, and the code I rewrote was much simpler (until the diffing logic started to get gnarly). I'd really like to be back in that position, if only from a maintenance pov, and if the performance thing isn't an issue I'd totally recommend it.

I understand. I get around such performance issues by having Container components, which extract the needed state from the context and feeds it to view components, which only rerender when their props change. The only diffing logic needed is to make the views PureComponents.

my bony fealty
Oct 1, 2008

SimonChris posted:

I understand. I get around such performance issues by having Container components, which extract the needed state from the context and feeds it to view components, which only rerender when their props change. The only diffing logic needed is to make the views PureComponents.

can you post an example of how you do it, is it just copying the context into new state to pass down? any issues with objects and having to make deep copies to avoid accidentally mutating the original context state? or are you saying the container grabs from context and prop drills it directly down to view, no copying?

do y'all use anything you like for route transition animations in React? I'm using Popmotion Pose right now (with Reach Router) and while it works pretty well for simple routing I am running into issues with nested routes, there doesn't seem to be a good way to tell it not the call the top-level router animation when a nested route (which is currently not animated) change happens. the route change will happen right away (in the nested router) and then the top-level animation will play, to the appearance of the component animating into itself. for now I've sorta fixed it by telling it to render a non-animated router when activating a nested transition, but this does not seem like a good solution.

I'm looking for something that can do left/right slide route transitions, nothing fancy, that ideally can handle animations for nested routers that are inside of another animated router. I wanna have lil widgets that are controlled by a nested router sliding around.

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.
I've got typescript code which uses the 'name' property on an array of types at runtime. This has worked fine in development mode (vue-cli), but in build mode it seems like some optimization is clobbering the class names in transpilation, and each type has name 't'.

Any webpack folks have a suggestion for a config flag that will avoid this optimization?

e: Here I go.

code:
optimization: {
    minification: false
}
A start. This works for my means (the classnames aren't squashed), but it'd be better if the code were still minified without touching any 'names'. Further suggestions?

Newf fucked around with this message at 07:36 on Mar 16, 2019

SimonChris
Apr 24, 2008

The Baron's daughter is missing, and you are the man to find her. No problem. With your inexhaustible arsenal of hard-boiled similes, there is nothing you can't handle.
Grimey Drawer

my bony fealty posted:

can you post an example of how you do it, is it just copying the context into new state to pass down? any issues with objects and having to make deep copies to avoid accidentally mutating the original context state? or are you saying the container grabs from context and prop drills it directly down to view, no copying?

code:
<MyContext.Consumer>
  {store => ( 
    <View
      someProp={store.someProp}
      updateSomeProp={store.updateSomeProp}
   />
  )}
</MyContext.Consumer>
View only rerenders when someProp changes.

prom candy
Dec 16, 2005

Only I may dance
That's a good solution but it's basically also just react-redux. I guess if you want to avoid dealing with the rest of Redux it makes sense. You could probably write your own HoC or render prop component that takes a mapStateToProps function and save yourself writing all those container components actually!

dupersaurus
Aug 1, 2012

Futurism was an art movement where dudes were all 'CARS ARE COOL AND THE PAST IS FOR CHUMPS. LET'S DRAW SOME CARS.'
First time using redux and react-redux and I'm confused. A story in three reducers...

code:
function updateName(state, action) {
    return Object.assign(state, {name: action.name});
}
code:
function updateName(state, action) {
    return _.extend(state, {name: action.name});
}
code:
function updateName(state, action) {
    return {
        name: action.name,
        start: state.start,
        end: state.end
    }
}
According to everything I've read, these three should all be equivalent, and all three correctly change the state. But react-redux only renders on the third one. What am I missing?

RC Cola
Aug 1, 2011

Dovie'andi se tovya sagain
I'm pretty new at all of this and am still learning. I have 8 hours at work everyday to listen to podcasts and was wondering if there are any that one of you can recommend to me for a beginner. Just to help supplement what I'm learning on my own/through this bootcamp. Maybe ways of thinking, or algorithms, or ways to code cleanly. I'm not sure exactly what I'm even looking for is part of the problem.

justizor
Dec 21, 2007

dupersaurus posted:

First time using redux and react-redux and I'm confused. A story in three reducers...

code:
function updateName(state, action) {
    return Object.assign(state, {name: action.name});
}
code:
function updateName(state, action) {
    return _.extend(state, {name: action.name});
}
code:
function updateName(state, action) {
    return {
        name: action.name,
        start: state.start,
        end: state.end
    }
}
According to everything I've read, these three should all be equivalent, and all three correctly change the state. But react-redux only renders on the third one. What am I missing?

In the first two you’re updating the state object directly. React-redux expects a new state object if the state has changed, which is what happens in the third example.

The first example can be rewritten as:
code:
function updateName(state, action) {
    return Object.assign({}, state, {name: action.name});
}
and it should work. Probably the same for the second example.

SimonChris
Apr 24, 2008

The Baron's daughter is missing, and you are the man to find her. No problem. With your inexhaustible arsenal of hard-boiled similes, there is nothing you can't handle.
Grimey Drawer

justizor posted:

In the first two you’re updating the state object directly. React-redux expects a new state object if the state has changed, which is what happens in the third example.

The first example can be rewritten as:
code:
function updateName(state, action) {
    return Object.assign({}, state, {name: action.name});
}
and it should work. Probably the same for the second example.
Using spread syntax makes this a lot neater
code:
function updateName(state, action) {
    return {
      ...state,
      name: action.name
    }
}

dupersaurus
Aug 1, 2012

Futurism was an art movement where dudes were all 'CARS ARE COOL AND THE PAST IS FOR CHUMPS. LET'S DRAW SOME CARS.'

justizor posted:

In the first two you’re updating the state object directly. React-redux expects a new state object if the state has changed, which is what happens in the third example.

The first example can be rewritten as:
code:
function updateName(state, action) {
    return Object.assign({}, state, {name: action.name});
}
and it should work. Probably the same for the second example.

Ahhhh that's it, doc reading fail. I thought Object.assign (and probably _.extend as well) was returning a new object, not mutating the first param. Thanks!

Doom Mathematic
Sep 2, 2008

dupersaurus posted:

Ahhhh that's it, doc reading fail. I thought Object.assign (and probably _.extend as well) was returning a new object, not mutating the first param. Thanks!

It returns the first param and mutates it! I don't like this, myself, I consider it hazardous for exactly the reason you've just experienced. I have a similar issue with Array.prototype.sort, which sorts the input array in place but also returns the input array, behaviour which is shockingly easily mistaken for "returns a brand new, sorted array, leaving the original untouched".

When I write a function which mutates one of its parameters I generally make it so that the function returns undefined. And then I put a honking great comment warning about which parameter gets mutated in place...

Tanners
Dec 13, 2011

woof

RC Cola posted:

I'm pretty new at all of this and am still learning. I have 8 hours at work everyday to listen to podcasts and was wondering if there are any that one of you can recommend to me for a beginner. Just to help supplement what I'm learning on my own/through this bootcamp. Maybe ways of thinking, or algorithms, or ways to code cleanly. I'm not sure exactly what I'm even looking for is part of the problem.

Hey I was in this exact situation a couple years ago. I've never really found anything good for learning algorithms, but as far as software in general goes:

https://completedeveloperpodcast.com/ Haven't listened to this in a while but earlier episodes track one of the hosts through from knowing barely anything about code to landing a job within a couple years, lots of good content.

https://frontendhappyhour.com/ Show with a changing panel of guests talking about modern front-end development

http://bikeshed.fm/ weekly show usually about software development in general episodes focusing on a specific practice or technology with guests

https://nodogmapodcast.bryanhogan.net/ Interview show, Favors technology around Windows development, but some general stuff as well

https://www.thisagilelife.com/ was very helpful around learning all of the bullshit agile terminology and practices.

-Anders
Feb 1, 2007

Denmark. Wait, what?
For webdev and frontend stuff, I really like Syntax.fm
It's a couple of independent developers, that run their business on making training courses for people. They talk about all kinds of stuff, from the small things to entire frameworks.
https://www.google.com/podcasts?feed=aHR0cHM6Ly9mZWVkLnN5bnRheC5mbS9yc3M_X19zPW9jZXh5Ym40M3NhY3dvbWMybzho

huhu
Feb 24, 2006
I believe there was a website mentioned several times here that gives you structured learning in front end from 0 to hero. Anyone know what I'm talking about?

The Fool
Oct 16, 2003


https://www.freecodecamp.com ?

There are a few, but that is the one I recommend whenever someone asks.

lunar detritus
May 6, 2009


Is anyone here developing on Windows? If yes, what's the best way to have a modern web development environment?

Adbot
ADBOT LOVES YOU

prom candy
Dec 16, 2005

Only I may dance
Just working on switching over from MacOS right now actually. WSL (Windows Subsystem for Linux) is working pretty well. Still getting used to a lot of things and not 100% sold on a terminal emulator yet, but I have my whole stack running. For my back-end services I'm using Docker, and I did have to upgrade to Windows 10 Pro in order to use Docker for Windows, otherwise you have to gently caress around with docker-machine and setting up your own VMs which I was willing to pay $100 not to do. Windows definitely isn't the poo poo show it used to be now that there's WSL, although you still have to do some finagling to get things working the way you want.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply