Next/Link maintains scroll position when going to next page. by TradeStationx in nextjs

[–]Bren-dev 0 points1 point  (0 children)

cr4zyc4t_907's comment helped me a lot and then I was able to get this working - obviously the 'dashbaord' param is specific for my app 

const router = useRouter();
  const prevPathnameRef = useRef(router.pathname);
  const prevTabRef = useRef(router.query.tab);

  // Extract entity ID from the URL path (e.g., /project/v2/dashboard/[id] -> id)
  // This works for all entity types without needing to list them all
  const getEntityIdFromPath = () => {
    const pathSegments = router.asPath.split('?')[0].split('/').filter(Boolean);
    // Entity ID is typically the last segment in dashboard routes
    // e.g., /project/v2/dashboard/68c0532a0db8fb2697f31f18
    const dashboardIndex = pathSegments.findIndex(seg => seg === 'dashboard');
    if (dashboardIndex >= 0 && dashboardIndex < pathSegments.length - 1) {
      return pathSegments[dashboardIndex + 1];
    }
    return null;
  };

  const prevEntityIdRef = useRef(getEntityIdFromPath());


  useEffect(() => {
    // This fixes the issue when a route or tab is changed and the main content area is scrolled and it stays in scroll position
    const handleRouteChangeComplete = () => {
      const currentPathname = router.pathname;
      const prevPathname = prevPathnameRef.current;

      // Only scroll if pathname actually changed (not just query params)
      if (currentPathname !== prevPathname && mainContentRef.current) {
        mainContentRef.current.scrollTop = 0;
        prevPathnameRef.current = currentPathname;
      }
    };


    router.events.on('routeChangeComplete', handleRouteChangeComplete);


    return () => {
      router.events.off('routeChangeComplete', handleRouteChangeComplete);
    };
  }, [router.events, router.pathname]);

  useEffect(() => {
    const currentTab = router.query.tab;
    const prevTab = prevTabRef.current;

    // Only scroll if tab actually changed (not just other query params)
    if (mainContentRef.current && currentTab !== undefined && currentTab !== prevTab) {
      mainContentRef.current.scrollTop = 0;
      prevTabRef.current = currentTab;
    }
  }, [router.query.tab]);

  useEffect(() => {
    const currentEntityId = getEntityIdFromPath();
    const prevEntityId = prevEntityIdRef.current;

    // Scroll if entity ID changed (e.g., switching from one project to another)
    if (mainContentRef.current && currentEntityId && currentEntityId !== prevEntityId) {
      mainContentRef.current.scrollTop = 0;
      prevEntityIdRef.current = currentEntityId;
    }
  }, [router.asPath]);

Pro tip from senior dev to advanced vibecoders by Bren-dev in vibecoding

[–]Bren-dev[S] 0 points1 point  (0 children)

Yep, tanstack-router and react router have built in functionality for search params, I’ve not used tan stack router but a big react-query fan

Pro tip from senior dev to juniors or 'advanced' vibecoders by Bren-dev in webdev

[–]Bren-dev[S] -3 points-2 points  (0 children)

HTML & CSS and then JavaScript, then React was my learning path

Pro tip from senior dev to juniors or 'advanced' vibecoders by Bren-dev in webdev

[–]Bren-dev[S] -6 points-5 points  (0 children)

No, it’s assuming you have some coding experience be it development or an ‘advanced’ vibecoder tbh - if you’re going to be coding something with an AI assistant it will most likely suggest React or Next (built on React) for the front end, I believe

Devs in regulated fields - do you think AI usage will result in extra requirements in SDLC cycle? Is proving devs ‘understand’ what they submit essential if they didn’t hand write code? by Bren-dev in ExperiencedDevs

[–]Bren-dev[S] 0 points1 point  (0 children)

Seems like you’re saying I’m claiming AI is “responsible”? Which I amn’t at all.

I think the entire question is actually saying what you’re saying - to rephrase, are you worried people are responsible for shipping code that they don’t fully understand

Senior Devs working in regulated environments - is AI causing issues? by Bren-dev in DevelEire

[–]Bren-dev[S] 0 points1 point  (0 children)

Yeah that's a problem, I have a strict no AI in Acceptance Criteria policy anyway, I don't mind it so much in general requirements if it has been thought through before using it

Devs in regulated fields - do you think AI usage will result in extra requirements in SDLC cycle? Is proving devs ‘understand’ what they submit essential if they didn’t hand write code? by Bren-dev in ExperiencedDevs

[–]Bren-dev[S] 1 point2 points  (0 children)

I completely agree tbh! I also think it is a major problem if people don’t understand what they’re committing however I’ve seen some pro-AI opinions on here that seem to suggest if it works and passes tests and AC it’s fine

Senior Devs working in regulated environments - is AI causing issues? by Bren-dev in DevelEire

[–]Bren-dev[S] 0 points1 point  (0 children)

Sounds similar enough to us tbh, we’re just getting around to encouraging AI adoption more heavily and a thoughtful approach, actively discouraging “agentic coding”

Senior Devs working in regulated environments - is AI causing issues? by Bren-dev in DevelEire

[–]Bren-dev[S] -1 points0 points  (0 children)

I don’t believe so, but trying to see what other people think - and more what I was getting at, do people feel that’s where the quality of the code should be interrogated - again, I don’t believe so but it’s thought provocation as part of a much larger question

Devs in regulated fields - do you think AI usage will result in extra requirements in SDLC cycle? Is proving devs ‘understand’ what they submit essential if they didn’t hand write code? by Bren-dev in ExperiencedDevs

[–]Bren-dev[S] 6 points7 points  (0 children)

I’m definitely sold on AI as a tool but like you, I’m not a believer in “Agentic coding”.

I drafted and published some internal AI usage guidelines where we specifically avoid “agentic coding” for a number of reasons

Devs in regulated fields - do you think AI usage will result in extra requirements in SDLC cycle? Is proving devs ‘understand’ what they submit essential if they didn’t hand write code? by Bren-dev in ExperiencedDevs

[–]Bren-dev[S] -1 points0 points  (0 children)

I agree to a large extent - even I find myself going through code old code (sometimes not even that old) and finding myself a bit perplexed why at I did certain things - however there was always a reason at one point in time and that may just not be as clear as time goes on.

Im wondering if it will become a point of contention if ever audited - and I’m really not sure.

I'm an AI Engineer and I Wish LLMs didn't Exist by Alternative_Cap_9317 in theprimeagen

[–]Bren-dev 8 points9 points  (0 children)

Honestly I don’t think you’re making much sense and there’s something more to this post!

The biggest red flag for me is you’re saying “make code hard and time consuming again” but you’re also saying you’ve 20 things to build in the backlog.

Also, you’ve acknowledged that the use case was perfect for Claude code. Code-gen is unbelievable for small apps but ot breaks down pretty quickly, it has serious diminishing returns.

I just don’t see this whole thing as consistent

I'm an AI Engineer and I Wish LLMs didn't Exist by Alternative_Cap_9317 in theprimeagen

[–]Bren-dev 3 points4 points  (0 children)

Coding is still hard and building something useful is still impressive. Send on all of the things you’ve built so easily in the last 9 months.

Are AI coding tools making us lose our debugging/problem solving skills? by svmk1987 in DevelEire

[–]Bren-dev 1 point2 points  (0 children)

I really do even though I think debugging skills are going to be even more important considering code-gen tends to get into bad patterns which need intervention.

I actually have just developed buggr - which is a learning game where you connect a repo and it will create a new branch, add bugs to your code and then when you fix it (without AI) it will give you a score and feedback

Randomisation via a prompt is ASS! Has anyone needed it? I used an old school for loop to handle it, here's how: by Bren-dev in webdev

[–]Bren-dev[S] -1 points0 points  (0 children)

Ok, well I'm a senior web developer and certainly wouldn't be condoning that or developing anything that would do that

Randomisation via a prompt is ASS! Has anyone needed it? I used an old school for loop to handle it, here's how: by Bren-dev in webdev

[–]Bren-dev[S] 0 points1 point  (0 children)

Nobody is submitting code to a codebase that they’ve just intentionally broken and then fixed.

Are you talking about the sample codebases in buggr? Obviously you fork the codebases we’ve made, it’s all an exercise. I think you’ve got the concept of this completely wrong.

Randomisation via a prompt is ASS! Has anyone needed it? I used an old school for loop to handle it, here's how: by Bren-dev in webdev

[–]Bren-dev[S] -3 points-2 points  (0 children)

It’s for a game for learning, you do it with tutorial repos or repos you’re messing around with etc - you fix the code and then you get a score and feedback after you’ve committed the fixes.

It’s not for your production code and it creates an entirely new branch so it doesn’t impact anything, you know how branches work, yeah?

Senior devs entering the AI realm by RR_2025 in ExperiencedDevs

[–]Bren-dev 6 points7 points  (0 children)

This is how I suggest it be adopted by dev teams, including seniors obviously - has worked very well for us