Skip to content

Allow option update#1686

Open
davidjbradshaw wants to merge 6 commits into
devfrom
dev-update
Open

Allow option update#1686
davidjbradshaw wants to merge 6 commits into
devfrom
dev-update

Conversation

@davidjbradshaw
Copy link
Copy Markdown
Owner

No description provided.

Comment thread packages/react/index.tsx Fixed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an “options update” flow to iframe-resizer: re-calling connectResizer() on an already-bound iframe now updates stored settings and sends an update message to the child, with wrapper integrations across major frameworks to trigger rebinds on option changes.

Changes:

  • Add a core update path (connectResizerupdateIframe) that merges options, validates child version, and dispatches an update message.
  • Add child-side handling for update messages to apply changed settings without unnecessarily re-touching page styles/listeners.
  • Add framework wrapper rebind logic (React/Vue/Svelte/Solid/Angular/Web Component) plus unit/e2e coverage for the new behavior.

Reviewed changes

Copilot reviewed 27 out of 28 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vite.config/solid.post-build.js Copy Solid source dependencies needed for “solid” export consumers.
tsconfig.json Adjust TS root config (noEmit) and include Svelte component sources.
packages/web-component/index.ts Support option/attribute updates by rebuilding options and rebinding.
packages/vue/iframe-resizer.vue Rebind on prop changes via watch() using a shared options builder.
packages/svelte/IframeResizer.svelte Rebind on reactive prop changes while skipping the initial mount bind.
packages/solid/wire-options.ts New helper to pick “wire payload” options with Solid reactivity tracking.
packages/solid/IframeResizer.tsx Rebind on relevant prop changes using createEffect() and picked wire options.
packages/react/options-key.ts New stable dependency key builder for React option-change detection.
packages/react/index.tsx Rebind connectResizer when wire-relevant props change (update path).
packages/react/index.test.tsx Add test validating React rebind behavior on option change.
packages/core/setup/update.ts New parent-side update flow: merge options and send UPDATE to child.
packages/core/setup/update.test.ts Unit tests for update flow and dispatch gating.
packages/core/index.ts Route “already setup” connectResizer calls into the update flow.
packages/core/index.test.ts Update test expectations for “already setup” to call update flow.
packages/core/checks/min-child-version.ts New guard requiring child v6+ for option updates.
packages/core/checks/min-child-version.test.ts Unit tests for child version parsing/requirements.
packages/common/consts.ts Add UPDATE message constant.
packages/child/received/update.ts New child handler applying updated settings and selectively applying side-effects.
packages/child/received/update.test.ts Unit tests for child update handler behavior and side-effect gating.
packages/child/received/process-request.ts Register update handler in child request router.
packages/child/page/links.units.test.ts Update mocks to reflect in-page-links gating by settings.
packages/child/page/links.ts Make in-page linking idempotent and respect runtime enable/disable.
packages/child/page/links.test.ts Add coverage for findTarget no-op when inPageLinks disabled.
packages/child/page/links.branches.test.ts Adjust branch test setup for inPageLinks gating.
packages/child/events/mouse.ts Gate mouse event forwarding on runtime settings.mouseEvents.
packages/child/events/mouse.test.ts Add coverage for mouse forwarding disabled after settings update.
packages/angular/directive.ts Add ngOnChanges rebind path when options input changes.
e2e/tests/shared/parent-methods.js Add e2e test ensuring rebind sends update without breaking iframe attachment.

Comment thread packages/core/setup/update.ts Outdated
Comment on lines +16 to +27
function mergeOptions(id: string, options: Record<string, any>): void {
settings[id] = {
...settings[id],
...checkOptions(id, options),
}

if (hasMouseEvents(options)) settings[id].mouseEvents = true
if (hasOwn(options, 'mode')) settings[id].mode = setMode(options)

setOffsetSize(id, options)
setTargetOrigin(id)
}
Comment thread packages/core/setup/update.ts Outdated
Comment on lines +13 to +24
const hasMouseEvents = (options: Record<string, any>): boolean =>
hasOwn(options, 'onMouseEnter') || hasOwn(options, 'onMouseLeave')

function mergeOptions(id: string, options: Record<string, any>): void {
settings[id] = {
...settings[id],
...checkOptions(id, options),
}

if (hasMouseEvents(options)) settings[id].mouseEvents = true
if (hasOwn(options, 'mode')) settings[id].mode = setMode(options)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 44 out of 45 changed files in this pull request and generated 4 comments.

Comment on lines +73 to +74
const target = e.target as Element | null
const link = target?.closest?.('a[href^="#"]')
Comment on lines +163 to +171
attributeChangedCallback(
name: string,
oldValue: string | null,
newValue: string | null,
): void {
if (oldValue === newValue) return
if (!RESIZER_ATTR_MAP[name]) return
this.rebind()
}
Comment thread packages/react/index.tsx
Comment on lines +67 to +74
// Re-bind when iframe-resizer-relevant props change. The first mount above
// already created the binding, so subsequent calls take the update path in
// core, which sends an UPDATE message to the child.
//
// optionsKey is the only meaningful dep — it's a stable serialization of the
// props the resizer cares about. We read latest `props` and `onBeforeClose`
// through refs so the effect doesn't re-fire on unrelated re-renders.
const optionsKey = buildOptionsKey(props)
Comment on lines +5 to +15
import settings from '../values/settings'

export default function moveToAnchor(id: string, anchor: string): void {
typeAssert(anchor, STRING, 'moveToAnchor(anchor) anchor')

if (settings[id]?.inPageLinks !== true) {
throw new Error(
'moveToAnchor() requires the "inPageLinks" option to be set to true',
)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants