This book was written primarily to the Jews who had been dispersed amidst the Roman Empire during a time of intense persecution.
That’s pure religion to James (and to God) but there’s more to it than that.
One has to keep oneself unstained from the world and the “world” surely means the sins of the world and living in a sinful lifestyle.
Blessed is that one “who remains steadfast under trial, for when he has stood the test he will receive the crown of life, which God has promised to those who love him” (James )..” Visiting the orphans and widows would be considered the sort of works that James wrote about that would be produced as a result of having genuine, saving faith.
These kinds of works would be evident and if not, there there’s evidently no saving faith in the first place.
God uses this pain to produce the future glory he will reveal to you and in you.