Invoke-UDRedirect Doesn't Reload Query Parameters in URL

I’m using Invoke-UDRedirect to refresh the page and query parameters (the automatic $Query variable). I’m doing this because I’m trying to garbage-collect the memory from a New-UDDynamic component. Since that component contains many objects, including hundreds of map polygons, the page will error with “out of memory” after being on the page and refreshing the dynamic component a few dozen times.

The trouble I’m hitting is that after an Invoke-UDRedirect reloads the page, the $Query variable still contains the values originally passed to the page, not the new query parameters in the new, redirected URL.

Here is a test page to demonstrate:

New-UDPage -Name 'TestPage' -Title 'TestPage' -Url 'TestPage' -Role @('Administrator') -Content {
    $ValuePassed = $Query.ValuePassed
    New-UDTypography -Text "Value passed: $ValuePassed" -Variant 'h6'
    New-UDTextbox -Id 'NewValue' -Label 'New Value' -Value $ValuePassed
    New-UDButton -Text 'Submit' -OnClick {
        Invoke-UDRedirect -Url "/TestPage?ValuePassed=$((Get-UDElement -Id 'NewValue').Value)"

If I fully specify the new URL and using the “Native” parameter than this problem is avoided. However, with development environments in the mix, I prefer never to specify the base URI of the server where PU is running.

Maybe I’m doing this all wrong? Is there a way to garbage collect the objects in a New-UDDynamic without redirecting/refreshing the page? Is it wrong to assume that a New-UDRedirect should be refreshing the $Query variable?

1 Like

Hello, I had the same problem. You can use the $Headers[“host”] variable to avoid hardcoding your URLs.

I think the issue comes from React. With the relative link, it should only update the DOM and not the actual page itself.

1 Like