fix: handle serialized Buffer in state.key for View/Window sessions#100
Open
blahah wants to merge 1 commit intoholepunchto:mainfrom
Open
fix: handle serialized Buffer in state.key for View/Window sessions#100blahah wants to merge 1 commit intoholepunchto:mainfrom
blahah wants to merge 1 commit intoholepunchto:mainfrom
Conversation
When creating a ui.View or ui.Window from within an app, the state
object is passed through Electron IPC serialization. This converts
Buffer objects to plain objects like { type: 'Buffer', data: [...] }.
The session partition code was using hypercoreid.encode(this.state.key)
which requires a Buffer, causing "Key must be a Buffer" errors.
This fix checks if state.key is a serialized Buffer object and converts
it back to a real Buffer before encoding:
let stateKey = this.state.key
if (stateKey && stateKey.type === 'Buffer' && Array.isArray(stateKey.data)) {
stateKey = Buffer.from(stateKey.data)
}
Fixes holepunchto#99
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
70d3960 to
1074829
Compare
Author
Updated FixThe previous The correct fix explicitly checks for and converts serialized Buffer objects back to real Buffers: // Handle serialized Buffer from IPC (becomes { type: 'Buffer', data: [...] })
let stateKey = this.state.key
if (stateKey && stateKey.type === 'Buffer' && Array.isArray(stateKey.data)) {
stateKey = Buffer.from(stateKey.data)
}
const session = electron.session.fromPartition(`persist:${this.sessname || (stateKey ? hypercoreid.encode(stateKey) : this.state.dir)}`)This handles both:
Tested and confirmed working with a staged Pear app using |
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.
Summary
ui.Viewandui.Windowfailing with "Key must be a Buffer" error whenstate.keyis serialized through IPChypercoreid.encode()withhypercoreid.normalize()which handles both Buffer and serialized Buffer formatsProblem
When creating a
ui.Viewfrom within a Pear app, thestateobject is passed through Electron IPC serialization. This convertsBufferobjects to plain objects like{ type: 'Buffer', data: [...] }.The session partition code was using
hypercoreid.encode(this.state.key)which requires a Buffer, causing the error:Solution
Use
hypercoreid.normalize()instead, which internally callsdecode()thenencode(). Thedecode()function handles:Test plan
ui.ViewinstancesFixes #99
🤖 Generated with Claude Code