Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log overflow/tagged node every time it is used to calculate size #1336

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions packages/child/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,8 @@ export function getElementName(el) {
}
}

// function elementSnippet(el, maxChars = 30) {
// const outer = el?.outerHTML?.toString()

// if (!outer) return el

// return outer.length < maxChars
// ? outer
// : `${outer.slice(0, maxChars).replaceAll('\n', ' ')}...`
// }
const BOLD = 'font-weight: bold;'
const NORMAL = 'font-weight: normal;'

// TODO: remove .join(' '), requires major test updates
const formatLogMsg = (...msg) =>
Expand All @@ -53,7 +46,7 @@ export const log = (...msg) =>
// eslint-disable-next-line no-unused-vars
export const info = (...msg) =>
// eslint-disable-next-line no-console
logging && console?.info(`[iframe-resizer][${id}]`, ...msg)
logging && console?.info(`%c[iframe-resizer][${id}]%c`, BOLD, NORMAL, ...msg)
Dismissed Show dismissed Hide dismissed

export const warn = (...msg) =>
// eslint-disable-next-line no-console
Expand Down
14 changes: 8 additions & 6 deletions packages/child/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const usedTags = new WeakSet()

const addUsedTag = (el) => typeof el === 'object' && usedTags.add(el)

let lastPerfEl = null
// let lastPerfEl = null
let perfEl = null
let details = {}

Expand All @@ -28,18 +28,20 @@ function usedEl(detail, duration) {

details = detail

if (usedTags.has(perfEl) || lastPerfEl === perfEl || (hasTags && len <= 1)) {
if (
usedTags.has(perfEl) /* || lastPerfEl === perfEl */ ||
(hasTags && len <= 1)
)
return
}

if (!logging) addUsedTag(perfEl)

lastPerfEl = perfEl
// lastPerfEl = perfEl

info(
`\n${Side} position calculated from:`,
`\n ${Side} position calculated from:`,
perfEl,
`\nParsed ${len} ${hasTags ? 'tagged' : 'potentially overflowing'} elements in ${round(duration)}ms`,
`\n Parsed ${len} ${hasTags ? 'tagged' : 'potentially overflowing'} elements in ${round(duration)}ms`,
)
}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
import { addEventListener, removeEventListener } from '../common/listeners'
import {
advise,
info,
log,
setLogEnabled,
setLogSettings,
vInfo,
warn,
} from '../common/log'
} from './log'
// import modal from '../common/modal'
import setMode, { getModeData, getModeLabel } from '../common/mode'
import { once } from '../common/utils'
Expand Down Expand Up @@ -1035,7 +1035,7 @@ The <b>sizeWidth</>, <b>sizeHeight</> and <b>autoResize</> options have been rep
if (vAdvised || mode < 0) return

vAdvised = true
info(`v${VERSION} (${getModeLabel(mode)})`)
vInfo(`v${VERSION} (${getModeLabel(mode)})`)

if (mode < 1) advise('Parent', getModeData(3))
}
Expand Down
9 changes: 8 additions & 1 deletion packages/common/log.js → packages/core/log.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import formatAdvise from './format-advise'
import formatAdvise from '../common/format-advise'

const msgId = '[iframe-resizer]'

const BOLD = 'font-weight: bold;'
// const NORMAL = 'font-weight: normal;'

let settings = {}
let logEnabled = false

Expand Down Expand Up @@ -42,6 +45,10 @@

export const info = (iframeId, ...msg) => output('info', iframeId, ...msg)

export const vInfo = (msg) =>
// eslint-disable-next-line no-console
console.info(`%c[iframe-resizer] ${msg}`, BOLD)
Dismissed Show dismissed Hide dismissed

export const warn = (iframeId, ...msg) => output('warn', iframeId, ...msg)

export const advise = (iframeId, msg) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/values/defaults.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { advise } from '../../common/log'
import { advise } from '../log'
import settings from './settings'

const onReadyDeprecated = (messageData) => {
Expand Down
Loading