perf: cache createScreen queries by body ref + add wrapFireEventMethods helper#11
Merged
Merged
Conversation
…ds helper - createScreen() now caches the getQueriesForElement(document.body) result by body reference. The Proxy previously called getQueriesForElement on every single property access; the cache avoids redundant traversal while still refreshing when JSDOM reinitialises the body (e.g. isolation:none between test files). - Add exported wrapFireEventMethods(target, base, wrapFn) helper that iterates Object.keys(base), copies non-function values as-is, and wraps function values through wrapFn. Consumers (React, Vue) use this to inject their own flush step (act / nextTick) without duplicating the iteration loop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
createScreen()intesting-core.tscalledgetQueriesForElement(document.body)once at screen creation time and cached those query bindings.When running with
isolation: 'none'(Poku plugin mode), the DOM environment is torn down and re-initialized between tests —document.bodyis replaced with a fresh element. The cached query functions retained a reference to the old, detacheddocument.body, so queries in subsequent tests would silently operate on stale DOM.Fix
Wrap the screen in a
Proxythat callsgetQueriesForElement(document.body)fresh on every property access, always reflecting the livedocument.body:This is a zero-overhead change in normal (fresh-DOM) usage and fixes stale-query bugs in
isolation: 'none'mode used by both@pokujs/reactand@pokujs/vue.