I don't know if this question has already been asked here, I searched and couldn't find it.
Does the story of Judah and Tamar develop during Joseph's age to Egypt? If so, in that case the children of Judah had to be 9 years old to give Judah time ahead with his brothers to go to Egypt to look for food because the 7 years were of abundance according to the prophecy and the 7 years of famine and I mention 9 because it took two years with Joseph in Egypt for Pharaoh to have the dream in which the prophecy would begin. What I see is that chapter 38, which is where this story of Judah and Tamar is found, seems to break the line of reasoning that chapter 37 of Genesis was giving, the sale of Joseph, in chapter 39 it will deal with Joseph's stay in the Egypt proper. The end of chapter 37 seems to be consistent with the beginning of chapter 39.
Is it inconceivable that the stories in Genesis are not necessarily in chronological order? Or do we have to maintain that Judah's children were 9 years old or a little older and committed that whole event of wasting seed if at that age that would be biologically possible, apart from the fact that Judah deceived Tamar by making her wait for the third son to grow up to If he marries her, that is, it seems like a story displaced from the chapters that surround it, couldn't this story be located well before they sold Joseph? What does tradition, sages and Judaism have to say about, or has not even addressed this apparent problem?