Skip to content

Async table updates with pagination does not work #709

@mkht

Description

@mkht

Describe the Bug

The sample code for async table updates in the example does not work.

I wanted to try out Pode.Web's asynchronous update feature,
so I ran examples/async-update.ps1 without any changes, but it did not work.

Update-PodeWebTable, which includes pagination, outputs the following error message:

Level: Error
ThreadId: 0
Server: MY-SRV-01
Category: InvalidOperation: (:) [Update-PodeWebTable], RuntimeException
Message: Cannot index into a null array.
StackTrace: at Update-PodeWebTable<End>, F:\test\modules\Pode.Web\1.0.0\Public\Actions.ps1: line 71
at <ScriptBlock>, <No file>: line 15
at Invoke-PodeScriptBlock, F:\test\modules\Pode\2.13.2\Public\Utilities.ps1: line 617
at <ScriptBlock>, <No file>: line 58

Steps To Reproduce

This code is an excerpt of the relevant code from examples/async-update.ps1

Start-PodeServer -Threads 2 {
    # add a simple endpoint
    Add-PodeEndpoint -Address localhost -Port 8090 -Protocol Http
    New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging

    # set the use of templates, and set a login page
    Initialize-PodeWebTemplates -Title 'Async Updates' -Theme Dark -RootRedirect

    # add a third page - table
    Add-PodeWebPage -Name 'Processes' -ScriptBlock {
        New-PodeWebCard -Name 'Processes' -NoTitle -Content @(
            New-PodeWebTable -Name 'Processes' -Paginate -ScriptBlock {
                Set-PodeWebAsyncHeader
                $null = Invoke-PodeTask -Name 'GetProcesses' -ArgumentList @{
                    AsyncEvent = Export-PodeWebAsyncEvent
                    PageIndex  = $WebEvent.Data.PageIndex
                    PageSize   = $WebEvent.Data.PageSize
                }
            }
        )
    }

    # async task to load the processes and populate the table
    Add-PodeTask -Name 'GetProcesses' -ScriptBlock {
        param([hashtable]$AsyncEvent, [int]$PageIndex, [int]$PageSize)

        $AsyncEvent | Set-PodeWebAsyncEvent
        Start-Sleep -Seconds 2

        $processes = Get-Process | Select-Object -Property Name, ID, WorkingSet, CPU
        $totalCount = $processes.Length
        $processes = $processes[(($PageIndex - 1) * $PageSize) .. (($PageIndex * $PageSize) - 1)]
        $processes | Update-PodeWebTable -Name 'Processes' -PageIndex $PageIndex -TotalItemCount $totalCount
    }
}

The Processes table will continue loading indefinitely.
An error will be displayed in the console.

Platform

  • OS: Windows
  • Browser: Chrome
  • Versions:
    • Pode: 2.13.2
    • Pode.Web: 1.0.0-preview3
    • PowerShell: 7.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something isn't working

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions