Merge pull request #5936 from vishnukothakapu/fix/use-local-storage-state-stale-closure-v2