FIX: Wait for the page to load before warning that no preference platform was found - #32
Merged
Merged
Conversation
…form was found A preference platform's bundle loads asynchronously, so on a first visit it has not registered when this script constructs. The script warned right then, which read as an integration error on a page that was correctly integrated, and the answer arrived moments later on the window event and everything worked. The warning now waits the way a platform waits for this script's object, ending at the page's load event or after 5000 milliseconds, whichever comes first, and skipping the wait where the page has already loaded. An answer from any source during the wait, or a platform that registers during it, means nothing is printed. Where no platform ever appears the warning is printed exactly as before, because that case matters. Rendered output with the user prompt block off is byte for byte what it was, and with the block on the only change is this function. Checks in tests/template-tests.js went from 157 to 176, all passing.
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.
The problem
On a page that is correctly integrated, the client script logs this on a
first visit:
A preference management platform's bundle loads asynchronously, so
__tcfapiis not registered at the moment this script constructs. Thescript then picks the answer up from the
51d-pmp-preferencewindow eventand everything works, so the line is noise, and anyone with the console
open reads it as an integration error.
The two sides had different rules for the same question. A preference
management platform waits for the client script's object before deciding
the script is absent, and that wait ends at the page's load event or after
5000 milliseconds, whichever comes first, with no wait at all where the
page has already loaded. The client script decided at construction, which
is the one moment an asynchronous tag has reliably not run yet.
The change
JavaScriptResource.mustache, inside the user prompt block. The warningnow waits in the same shape:
loadevent, or after 5000 milliseconds,whichever comes first, so a page whose load event is very late or never
comes is still told.
that is not there then is not coming from a tag the markup carries.
during it, means nothing is printed, because a 51Did will be created.
with the same text, because that case matters and the line is the only
signal the page gets.
The wait only logs. It changes nothing about processing, no request waits
for it, and no value is ever printed. The existing failure handling style
in the block is followed, so every read that a stub could make throw is
wrapped and nothing here can stop
process().Environments with no window, no
addEventListeneror nosetTimeout,which is where the cloud's server side evaluation runs this script, warn
at once as before rather than waiting for a page that does not exist.
Evidence
The template is shared by every language's builder, so the rendered output
had to stay the same in every other respect. Rendering the template before
and after with the same model and comparing:
identical;
node tests/template-tests.js:157 checks, 0 failures176 checks, 0 failuresOne existing check changed meaning, from "a page with no platform at
construction is warned once" to "a page still loading is not warned about
a missing platform", which is the behaviour under test here. Nineteen
checks were added in a new section, "The wait before the missing platform
warning", covering:
the page's load event;
always got, and the load listener is removed afterwards;
comes is warned at that limit, and a load event after the limit does not
repeat it;
still reaches the request;
about;
rendered without the user prompt block.
The 5000 millisecond limit is reached in the tests through a
setTimeoutthe test drives, so the suite does not sit waiting five seconds for it.
Found while working on the 51Degrees website against cloud release
4.4.38.
Without the change
The counts above show the suite is green before and after, which on its own does not show the new checks would have caught the fault. Running this branch's
tests/template-tests.jsagainst theJavaScriptResource.mustachefrommain, with nothing else altered, gives:Six of the nineteen new checks fail there, together with the one existing check whose meaning changed. The other thirteen describe behaviour the block already had, such as the warning text itself and a platform found at construction being neither waited for nor warned about, so they pass either way and are there to hold that behaviour still.
Related, and what has to follow
This and #31, which stores a snippet's result only under a name the snippet writes, both change
JavaScriptResource.mustache, in different parts of the file. Merging the two branches together locally in both orders needed no conflict resolution, andnode tests/template-tests.json the result reports207 checks, 0 failureseither way, so the merge order does not matter.The Rust SDK keeps its own copy of the template at
javascript-builder/assets/JavaScriptResource.mustacheand checks it against this repository. Its pull request and push builds compare against a pinned commit, but the Monday 04:00 schedule and a manual run compare againstmain, so that weekly check goes red once this is merged and stays red until 51Degrees/rust#52 moves the bundled copy and the pinned reference together in one pull request. The .NET, Java, Node and Python pipelines take this repository as a submodule and the PHP pipeline readsJavaScriptResource.mustachefrom ajavascript-templatesdirectory beside its source, so each of them picks the change up only when it next moves that pointer and publishes a package.Left for the reviewer to judge
Where the page has already loaded the warning is printed at once with no wait. A page that injects both this script and its preference management platform after the load event, which a tag manager can do, therefore still gets the line on a first visit even though the platform is on its way. The alternative is to wait 5000 milliseconds on every late injection, which delays the one signal a genuinely unintegrated page gets.
Merge order
The three ready pull requests in this repository take this order:
29, 32, 31
Merges before this one: 29.
This and 31 both change
JavaScriptResource.mustacheandtests/template-tests.js, in different parts of each file, andgit merge-treefinds no conflict between them in either direction.No branch had to be changed for this order. Every pair was measured with
git merge-tree, the three were then merged intomainin that order as real merges with no conflict, andnpm testintestson the result reports207 checks, 0 failures. Smallest and most self-contained first. Checked on 17 September 2026.